跳至内容
菜单
此问题已终结

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
9月 23
1767
1
3月 15
7117
1
7月 23
2125
2
5月 23
5695
1
5月 23
218