Odoo 16 : how to add attributes with conditions

Jeevachaithanyan Sivanandan - Oct 11 '23 - - Dev Community

If you want to add a custom condition to show/hide a field, you would need to use XPath. For instance, to show a field 'cost' in the product template only if the user is a member of a custom group called 'Allow Cost and Price' you need to know the XML ID of this group, which is 'group_edit_costprice_purchaseorders.'

Now, you can inherit the product template and add the XPath as shown below

            <xpath expr="//field[@name='standard_price']" position="attributes">
                <attribute name="groups">
                    custom_extension.group_edit_costprice_purchaseorders
                </attribute>                
            </xpath>
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player