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

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

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?

Nejlepší odpověď

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

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

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

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

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

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

Related Posts Odpovědi Zobrazení Aktivita
1
zář 23
1883
1
bře 15
7223
1
čvc 23
2267
2
kvě 23
5910
1
kvě 23
218