Odoo:字段上的条件不可见属性只能在一个方向上起作用吗?

Rob*_*beM 7 xml inheritance odoo odoo-view

我试图在一个Odoo表单视图中使一个字段不可见.检查"可以出售"时==>"产品经理"应该是不可见的:

在此输入图像描述

在此输入图像描述

我尝试在产品表单的继承视图中使用属性"invisible"与域:

<record model="ir.ui.view" id="product_template_form_inherit">
    <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">
        <field name="product_manager"  position="attributes">
                    <attribute name="invisible">[('sale_ok', '=', True)]</attribute>
        </field>    
</field>
</record>
Run Code Online (Sandbox Code Playgroud)

当字段sale_ok为true时,product_manager字段实际上是隐藏的.但是当字段sale_ok再次变为false时,字段product_manager保持隐藏状态.

我也试过这个:

<field name="product_manager" attrs="{'invisible': [('sale_ok', '=', True)]}"/>
Run Code Online (Sandbox Code Playgroud)

这也不起作用.

我也尝试过其他域名:

[('sale_ok', '==', True)]
[('sale_ok', '!=', False)]
[('sale_ok', '=', 'True')]
Run Code Online (Sandbox Code Playgroud)

不确定这里有什么问题......当(未)检查时如何使它(in)可见?

我最终得到的是以下内容:选中复选框后,表单应立即更改而不保存.必须添加和删除字段.那可能吗?

编辑:

我现在可以用ChesuCR的答案隐藏/取消隐藏产品经理.但是,当我使用"loc_rack"(存储位置==>机架)尝试相同的操作时,它会给出错误:

Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Element '<field name="loc_rack">' cannot be located in parent view
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码:

<field name="loc_rack"  position="replace">
    <field name="loc_rack" attrs="{'invisible': [('sale_ok', '=', True)]}"/>
</field>
Run Code Online (Sandbox Code Playgroud)

为什么我不能对这个领域做同样的事情呢?

Che*_*uCR 6

这对我很有用

<record id="custom_product_template_form_view" model="ir.ui.view">
    <field name="name">custom.product.template.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view" />
    <field name="arch" type="xml">
        <field name="product_manager"  position="replace">
            <field name="product_manager" attrs="{'invisible': [('sale_ok', '=', True)]}"/>
        </field>
    </field>  
</record>
Run Code Online (Sandbox Code Playgroud)


小智 5

使用position="replace"可能会带来问题,最好的选择是使用position="attributes"

想象另一个已安装的模块(名为模块 X)正在继承您要替换的标签。当您更新您的 Odoo 系统时,它会崩溃,因为模块 X 找不到您替换的标签。

这段代码非常适合我:

<field name="product_manager"  position="attributes">
    <attribute name="attrs">{'invisible': [('sale_ok', '=', True)]}</attribute>
</field>
Run Code Online (Sandbox Code Playgroud)