Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
1452 Tampilan

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>


Avatar
Buang
Penulis Jawaban Terbai

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

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Nov 24
870
1
Jul 25
568
3
Jun 25
2365
4
Jul 25
1123
0
Nov 24
1262