Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
14441 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

Thanks Niyas

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

Related Posts Odpovědi Zobrazení Aktivita
5
čvn 19
12427
1
lis 19
4874
1
úno 16
4918
1
kvě 22
15433
3
úno 20
18366