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

I want to make the field A readonly for the customer group which is a new group i have created. 

I tried this but it didnt work. Is there another way to do this or a way to keep track of the logged in user in the xml view?

attrs="{'readonly': [('groups', 'in', [crm.customer_group])]}"">


الصورة الرمزية
إهمال
الكاتب

I have tried creating a boolean field and using it to make fields read only but there is no way for my python file to tell the boolean field in xml to become true based on user login.

I tried @Cybrosys Tech method but that doesn't render the field for any other group just the one mentioned in the groups tag. Anyway to dynamically change the readonly for field A based on loggedIn user's group?

أفضل إجابة

define boolean compute filed on model and user attrs on view to make field readonly

ref: https://github.com/odoo/odoo/blob/16.0/addons/hr_holidays/models/hr_leave_allocation.py#L134

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

Use the attribute <t groups />

Try this example

<t groups="crm.customer_group">

<field name="field_name" readonly="1"/>

</t>

Hope it helps

الصورة الرمزية
إهمال
أفضل إجابة

The solution I found is duplicating the field and set specifics groups for each case.

This is a example:




field name="can_edit" invisible="1"/>

field name="resolucion" attrs="{'readonly':[('can_edit', '!=', True)]}"/>


@api.depends('resolucion')

    def _compute_can_edit(self):

        for record in self:

            if self.env.user.has_group('interturnos.group_interturnos_resolucion_modifier'):

                record.can_edit = True

            else:

                record.can_edit = False


        

الصورة الرمزية
إهمال
أفضل إجابة
def _compute_my_field_readonly(self):
return not (
self.user.has_group("my_module.group_1")
or self.user.has_group("my_module.group_2")
)

my_field = fields.Float(
readonly=_compute_my_field_readonly,
)


الصورة الرمزية
إهمال
أفضل إجابة

Hi Walaga Qapas,

Also, you can  do this by using a boolean field...

for example --- step1 - suppose we create a boolean field called "boolean_check"

​step2 - write a compute method and set "boolean_check" field True/False base on the login user.

​step3 - write attrs attribute in the field that you want to make readonly.

  ​condition like- attrs="{'readonly': [('boolean_check', '=' ,True)]}"

 

الصورة الرمزية
إهمال
أفضل إجابة

Hi  Walaga Qapas,

Try,

id="employee_normal_user_uneditable" model="ir.ui.view">
name="name">hr.employee.ta
name="model">hr.employee
name="inherit_id" ref="hr.view_employee_form"/>
name="groups_id" eval="[(6, 0, [ref('module_name.group_name')])]"/>
name="arch" type="xml">
name="field_name1" position="attributes">
name="readonly">1

name="field_name2" position="attributes">
name="readonly">1




الصورة الرمزية
إهمال

<record id="employee_normal_user_uneditable" model="ir.ui.view">
<field name="name">hr.employee.ta</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="groups_id" eval="[(6, 0, [ref('module_name.group_name')])]"/>
<field name="arch" type="xml">
<field name="field_name1" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="field_name2" position="attributes">
<attribute name="readonly">1</attribute>
</field>
</field>
</record>

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
1885
1
مارس 15
7224
1
يوليو 23
2272
2
مايو 23
5913
1
مايو 23
218