1
votes

Using Odoo 10 (fetched from GitHub commit 7413b26, branch 10.0), installing a module which I'm porting over from Odoo 8.

This module forces the purchase.order.line form to show up upon clicking a line in purchase.order by removing the editable attribute from the tree, but when saving changes done in that form Odoo raises:

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>

The __manifest__.py is:

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

and __init__.py is just the usual from . import purchase_order_error.

Here are some more observations:

  • The field state can have the following Selection values: [draft], [sent], [to approve], [purchase], [done], [cancel]; [draft] and [sent] do not appear in the error.
  • An Odoo user reported same problem on the Odoo GitHub bug tracker, without any solution as the time of writing.

Is there a workaround ?

2
Not sure about the msg error but try change the editable to: <attribute name="editable">bottom</attribute>dccdany

2 Answers

1
votes

The problem is when saving the record from the form view the state field is not defined. you don't get this error in the tree view because the field is there:

                <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"/>
                                .....
                                ....
                                ..

so you need to add it to the embedded form too:

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

You should add

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

So in form view of purchase order line there might be no field defined "state". According to rule if fields are used anywhere in attrs, domains then it must be defined on view, it doesn't matter you can define it invisible.

So just add this field in Purchase order line form view or follow the first solution for editable="top"

<field name="state" invisible="1" />