تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
13941 أدوات العرض

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.

المنشورات ذات الصلة الردود أدوات العرض النشاط
5
يونيو 19
11819
1
نوفمبر 19
4537
1
فبراير 16
4609
1
مايو 22
15027
3
فبراير 20
17918