我目前正在使用 odoo 16,我在其中创建了一个自定义字段并尝试将该字段设为只读。仅当非管理员用户登录时才应显示只读字段
这是我的初始代码:-
<odoo>
<data>
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='group_general']" position="inside">
<field name="recommanded_price" string="Recommended Price" readonly="1" groups="base.group_system"/>
</xpath>
</field>
</record>
</data>
</odoo>
我尝试了什么?
<odoo>
<data>
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='group_general']" position="inside">
<field name="recommanded_price" string="Recommended Price"
attrs="{'readonly': [('groups', 'not in', ['base.group_system'])]}"
/>
</xpath>
</field>
</record>
</data>
</odoo>
尝试此解决方案:禁用默认只读后应用新条件。
<field name="arch" type="xml">
<field name="recommanded_price" position="attributes">
<attribute name="readonly">0</attribute>
<attribute name="attrs">{'readonly': [('groups', 'not in', ['base.group_system'])]}</attribute>
</field>
</field>
“属性”位置:
通过“属性”,您可以调整 XML 的各种特征 Odoo 视图中的元素。这包括添加 CSS 类之类的事情 (用于样式),更改小部件类型(用于用户交互),以及 调整控制界面显示方式的其他属性以及 行为。
您可以修改的具体属性将取决于上下文 以及您正在自定义的特定视图。你有灵活性 根据您的喜好微调这些细节。