跳至内容
菜单
此问题已终结
1 回复
886 查看

I'm trying to add some restriction to procurement department, so i tried to add this code:

  <xpath expr="//form[1]/sheet[1]/notebook[1]/page[@name='order_lines']/field[@name='order_line']/tree[1]/field[@name='price_unit']" position="attributes">
    <attribute name="groups">Departments.PurchasingMarketing, Departments.PurchasingCoordinator</attribute>
  </xpath>

  <xpath expr="//form[1]/sheet[1]/notebook[1]/page[@name='order_lines']/field[@name='order_line']/tree[1]/field[@name='price_unit']" position="after">
    <field name="price_unit" readonly="1" groups="Departments.SystemAdministrators,!Departments.Purchasing, !Departments.PurchasingCoordinator"/>
  </xpath>


But THIS error code is preventing me to do it:

  <form string="Sales Order" class="o_sale_order" __validate__="1"> <header> <field name="locked" invisible="1"/> Field 'price_unit' used in context ({ 'partner_id': parent.partner_id, 'quantity': product_uom_qty, 'pricelist': parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id, 'default_list_price': price_unit, 'default_description_sale': name }) is restricted to the group(s) Departments.PurchasingMarketing, Departments.PurchasingCoordinator,Departments.SystemAdministrators,!Departments.Purchasing,!Departments.PurchasingCoordinator.


What did i miss?

形象
丢弃

Check context inside product_id and product_template_id fields if it is prevent to inherit this field or not.

What is the error you get?

编写者

<form string="Sales Order" class="o_sale_order" __validate__="1"> <header> <field name="locked" invisible="1"/> Field 'price_unit' used in context ({ 'partner_id': parent.partner_id, 'quantity': product_uom_qty, 'pricelist': parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id, 'default_list_price': price_unit, 'default_description_sale': name }) is restricted to the group(s) Departments.PurchasingMarketing, Departments.PurchasingCoordinator,Departments.SystemAdministrators,!Departments.Purchasing,!Departments.PurchasingCoordinator.

This one.

最佳答案

Hi,

Define a computed Boolean field and add it in the view.


is_boolean_field = fields.Boolean(compute="_compute_is_boolean_field")

def _compute_is_boolean_field(self):

        for record in self:

            if record.env.user.has_group("Provide the group that you want the restriction"):

                record.is_boolean_field = True

            else:

                record.is_boolean_field = False

<record id="view_order_form" model="ir.ui.view" >

        <field name="name">view.order.form.inherit</field>

        <field name="model">sale.order</field>

        <field name="inherit_id" ref="sale.view_order_form"/>

        <field name="arch" type="xml">

         <xpath expr="//field[@name='order_line']//tree//field[@name='price_unit']"

                       position="replace">

                    <field name="price_unit"

                           readonly="parent.is_boolean_field == False"/>

                </xpath>

<xpath expr="//field[@name='order_line']//tree//field[@name='price_unit']"

                       position="replace">

                    <field name="price_unit"

                           readonly="parent.is_boolean_field == False"/>

                </xpath>

    </record>


Hope it helps

形象
丢弃
编写者

We are using Odoo Online SaaS. So, i only have Studio to modify this.

相关帖文 回复 查看 活动
2
6月 25
402
3
7月 25
1413
1
6月 25
1351
2
5月 25
1390
1
5月 25
729