I will show one example to how this functionality works in sale group.
I make the unit price field in the sale order line makes readonly we select the user group user:own documents only
The field is editable for other 2 groups user:All documets
and manager
Firstly I create a boolean field for checking the user belongs to which group
is_own_user = fields.Boolean(string="Own user", compute='compute_own_user')
Then assigns the boolean field is True
when the user belongs the group user:own documents only otherwise assigns to False
@api.depends('product_id')
def compute_own_user(self):
res_user_id = self.env['res.users'].search([('id', '=', self._uid)])
for rec in self:
if res_user_id.has_group('sales_team.group_sale_salesman') and not res_user_id.has_group('sales_team.group_sale_salesman_all_leads'):
rec.is_own_user = True
else:
rec.is_own_user = False
in xml make is_own_user invisible and replaces the unit price field
<xpath expr="//notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="replace">
<field name="price_unit" attrs="{'readonly': [('isown_user', '=', True)]}" />
</xpath>