Skip to Content
Menu
This question has been flagged
1 Reply
13174 Views

I want to make price_unit field in sale order line like readonly in own documents only group in sales


<field name="groups_id" eval="[(6, 0, [ref('sales_stock.group_sale_salesman') ])]"/>

i add this line in before             <field name="arch" type="xml">

finally i change the price_unit field like this

            <xpath expr="//notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="attributes">
                <attribute name="readonly">1</attribute>
            </xpath>


The price_unit field readonly in all groups.
How can i set the field in only 1 group.??



Avatar
Discard
Best Answer

Hi,
Add a new compute field(ie, boolean field, you can hide the field)  in the form , then  in the compute function, check whether the current user belongs to particular group or not. If user belong to that group write true to the field else write false,

Then for the original field, give an attribute like this, based on the new compute field.

In the python,

compute_field = fields.Boolean(string="check field", compute='get_user')

@api.depends('compute_field')
def get_user(self):
res_user = self.env['res.users'].search([('id', '=', self._uid)])
if res_user.has_group('sale.group_sale_salesman') and not res_user.has_group('sale.group_sale_salesman_all_leads'):
self.compute_field = True
else:
self.compute_field = False

In the XML,

<field name="compute_field" invisible="1"/>
<field name="actual_field" attrs="{'readonly': [('compute_field', '=', True)]}" />

Try this, make changes accordingly

Thanks

Avatar
Discard
Author

Thanks Niyas

res_user can get without a DB query. User self.env.user instead of DB query.

Related Posts Replies Views Activity
5
Jun 19
11025
1
Nov 19
3891
1
Feb 16
4175
1
May 22
14218
3
Feb 20
17213