我目前正在使用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>

推荐答案

try 以下操作:对于www.example.com_user,字段将变为只读,对于base.group_system,字段将变为可编辑.

<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="groups_id" eval="[(6, 0, [ref('base.group_system') ])]" />
    <field name="arch" type="xml">
        <field name="name" position="attributes">
            <attribute name="readonly">0</attribute>
        </field>
    </field>
</record>

<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="groups_id" eval="[(6, 0, [ref('base.group_user') ])]" />
    <field name="arch" type="xml">
        <field name="name" position="attributes">
            <attribute name="readonly">1</attribute>
        </field>
    </field>
</record>

Python相关问答推荐

Python:在类对象内的字典中更改所有键的索引,而不是仅更改一个键

线性模型PanelOLS和statmodels OLS之间的区别

TARete错误:类型对象任务没有属性模型'

Python daskValue错误:无法识别的区块管理器dask -必须是以下之一:[]

聚合具有重复元素的Python字典列表,并添加具有重复元素数量的新键

Pandas计数符合某些条件的特定列的数量

无法在Docker内部运行Python的Matlab SDK模块,但本地没有问题

isinstance()在使用dill.dump和dill.load后,对列表中包含的对象失败

如何杀死一个进程,我的Python可执行文件以sudo启动?

以逻辑方式获取自己的pyproject.toml依赖项

导入错误:无法导入名称';操作';

在Google Drive中获取特定文件夹内的FolderID和文件夹名称

BeautifulSoup-Screper有时运行得很好,很健壮--但有时它失败了::可能这里需要一些更多的异常处理?

Python Mercury离线安装

我可以不带视频系统的pygame,只用于游戏手柄输入吗?''

Python:从目录内的文件导入目录

在不中断格式的情况下在文件的特定部分插入XML标签

如何在Polars中将列表中的新列添加到现有的数据帧中?

Pandas:使列中的列表大小与另一列中的列表大小相同

如何将django url参数传递给模板&S url方法?