编辑属性时域中的未知字段 'state'

Unknown field 'state' in domain when editing attribute

使用 Odoo 10(从 GitHub 提交 7413b26、分支 10.0 获取),安装我从 Odoo 8 移植过来的模块。

此模块通过从 tree 中删除 editable 属性,在单击 purchase.order 中的一行时强制显示 purchase.order.line 表单,但是在保存更改时完成以这种形式,Odoo 提出:

Error: Unknown field state in domain [["state","in",["purchase","to approve","done","cancel"]]]

purchase_order_error.xml:

<record id="purchase_order_line_tree" model="ir.ui.view">
    <field name="name">purchase.order.form</field>
    <field name="model">purchase.order</field>
    <field name="priority" eval="33"/>
    <field name="type">form</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page/field[@name='order_line']/tree" position="attributes">
            <attribute name="editable"/>
        </xpath>
    </field>
</record>

__manifest__.py是:

{'name': "purchase_order_error",'depends': ['base', 'product', 'purchase'],'data': ['purchase_order_error.xml',],'installable':True}

__init__.py只是通常的from . import purchase_order_error

这里还有一些观察结果:

有解决办法吗?

您应该添加

<record id="purchase_order_line_tree" model="ir.ui.view">
    <field name="name">purchase.order.form</field>
    <field name="model">purchase.order</field>
    <field name="priority" eval="33"/>
    <field name="type">form</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page/field[@name='order_line']/tree" position="attributes">
            <attribute name="editable">top</attribute>
        </xpath>
    </field>
</record>

In your case it's going to open form view to allow you to create records, because you have not given the value of editable attribute.

因此在采购订单行的表单视图中可能没有定义字段 "state"。根据规则,如果在 attrs、domains 中的任何地方使用字段,则必须在视图中定义它,没关系,您可以将其定义为不可见。

因此只需在采购订单行表单视图中添加此字段或按照 editable="top"

的第一个解决方案
<field name="state" invisible="1" />

问题出在从表单视图保存记录时 状态字段未定义。你没有得到这个错误 在树视图中,因为字段在那里:

                <page string="Products">
                        <field name="order_line" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}">
                             <tree string="Purchase Order Lines" editable="bottom">
                                <field name="currency_id" invisible="1"/>
                                <field name="state" invisible="1"/>
                                .....
                                ....
                                ..

因此您也需要将其添加到嵌入表单中:

    <record id="xxx_purchase_order_form_list_details" model="ir.ui.view">
        <field name="name">xxx_purchase_order_form_list_details</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='order_line']/tree" position="attributes">
                <attribute name="editable"/>
            </xpath>

             <xpath expr="//field[@name='order_line']//form//field[@name='product_id']" position="before">
                <field name="state" invisible="1"/>
            </xpath>
        </field>
    </record>