Odoo:字段上的条件不可见属性仅在一个方向上有效?

Odoo: Conditional invisible attribute on fields only works in one direction?

我正在尝试在 Odoo 表单视图中根据条件使字段不可见。 当 "Can be sold" 被选中时 ==> "Product Manager" 应该是不可见的:

我尝试在产品表单的继承视图中将属性 "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>

当字段sale_ok为真时,product_manager字段实际上是隐藏的。但是 当字段 sale_ok 再次变为假时字段 product_manager 保持隐藏状态

我也试过这个:

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

这也不行。

我也尝试过其他域,例如:

[('sale_ok', '==', True)]
[('sale_ok', '!=', False)]
[('sale_ok', '=', 'True')]

不太确定这里出了什么问题...如何使其在(未)选中时(不)可见?

我最终追求的是以下内容: 选中复选框时,表单应立即更改而不保存。必须添加和删除字段。这可能吗?

编辑:

我现在可以 hide/unhide 产品经理使用 ChesuCR 的回答。 然而,当我用 "loc_rack" (Storage Location==>Rack) 尝试同样的事情时,它给出了错误:

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

Error details:
Element '<field name="loc_rack">' cannot be located in parent view

这是我使用的代码:

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

为什么我不能对这个字段做同样的事情?

这很适合我

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

如果您发现任何问题,您可以尝试 "federico" 答案只是为了修改 attrs 属性。如果其他属性已经以原始形式存在,我的解决方案可能会修改或删除它们。

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

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

这段代码非常适合我:

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