Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
14461 Widoki

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.??



Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

Thanks Niyas

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

Powiązane posty Odpowiedzi Widoki Czynność
5
cze 19
12445
1
lis 19
4884
1
lut 16
4925
1
maj 22
15463
3
lut 20
18386