Hi Fadil,
To achieve the requirement of making the recommended_price
field editable only for administrators of Company 1, you can use the attrs
attribute in the XML view definition to control the read-only state of the field based on the user's group membership and the company. Here's how you can implement this:
Create a new group (e.g., company_1_admin
) in your custom module for administrators of Company 1.
In your custom module's XML file (e.g., views/your_model_view.xml
), locate the <field>
element for the recommended_price
field in the form view.
Add the attrs
attribute to the <field>
element with the following value:
<field name="recommended_price" attrs="{'readonly': ['|', ('user_has_groups', 'not in', ['your_module.company_1_admin']), ('company_id', '!=', 1)]}" />
Replace 'your_module.company_1_admin'
with the actual XML ID of the company_1_admin
group you created, and 1
with the ID of Company 1.
This expression will make the recommended_price
field read-only if:
- The current user does not belong to the
company_1_admin
group (user_has_groups
, 'not in'
, ['your_module.company_1_admin']
), OR
- The current record's
company_id
is not equal to 1
(company_id
, '!='
, 1
)
Hope it helps
Hope it helps