İçereği Atla
Menü
Bu soru işaretlendi
6 Cevaplar
9669 Görünümler

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])]}"">


Avatar
Vazgeç
Üretici

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?

En İyi Yanıt

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

Avatar
Vazgeç
En İyi Yanıt

Hi,

Use the attribute <t groups />

Try this example

<t groups="crm.customer_group">

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

</t>

Hope it helps

Avatar
Vazgeç
En İyi Yanıt

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


        

Avatar
Vazgeç
En İyi Yanıt
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,
)


Avatar
Vazgeç
En İyi Yanıt

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)]}"

 

Avatar
Vazgeç
En İyi Yanıt

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




Avatar
Vazgeç

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Eyl 23
1883
1
Mar 15
7223
1
Tem 23
2267
2
May 23
5910
1
May 23
218