Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
14438 Переглядів

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



Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Автор

Thanks Niyas

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

Related Posts Відповіді Переглядів Дія
5
черв. 19
12423
1
лист. 19
4874
1
лют. 16
4918
1
трав. 22
15431
3
лют. 20
18361