Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1447 Vizualizări

Hello,

I want to make the price unit read only by default except for can edit sale price group 

I did the following but not worked 

<odoo>
<data>
<record id="view_order_form_inherit_discount_price_unit" model="ir.ui.view">
<field name="name">sale.order.form.inherit.discount.price_unit</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='price_unit']" position="attributes">
<attribute name="attrs">{'readonly': [('user_id', '!=', user.id), ('id', 'not in', user.groups_id.ids)]}</attribute>
</xpath>
<xpath expr="//field[@name='discount']" position="attributes">
<attribute name="attrs">{'readonly': [('user_id', '!=', user.id), ('id', 'not in', user.groups_id.ids)]}</attribute>
</xpath>
</field>
</record>
</data>
</odoo>



<record id ="module_category_edit_price" model ="ir.module.category" >
<field name ="name" > Order Price </field>
<field name ="sequence" > 21 </field>
<field name ="parent_id " ref ="base.module_category_services" />
</record>


<record id ="group_can_edit_sale_price" model ="res.groups" >
<field name ="name" > Can edit sale price </field>
<field name =" category_id" ref ="module_category_edit_price" />
</record>


Imagine profil
Abandonează
Autor Cel mai bun răspuns

yes , it worked however the field after creating the invoice is not readonly

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

In odoo 17 there are technical changes on usage of attrs.

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("group_can_edit_sale_price"):

                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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
nov. 24
868
1
iul. 25
568
3
iun. 25
2359
4
iul. 25
1121
0
nov. 24
1262