Skip to Content
Menu
This question has been flagged

 I am trying to add an on_change attribute to 'purchase_price' field in a sales_order form. (It might require sales_margin module so purchase_price appears).

I add:

    <record model="ir.ui.view" id="sale_margin_percent_5">
        <field name="name">change.purchase_price</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='order_line']/tree//field[@name='purchase_price']" position="attributes">
                <attribute name="on_change">update_sale_price(sale_margin_percent, purchase_price, discount)</attribute>
            </xpath>
        </field>
    </record> 


But I get the following error:

Error details:
Element '<xpath expr="//field[@name='order_line']/tree//field[@name='purchase_price']">' can not be located in parent view

Context error: View `change.purchase_price` [view_id: 621, xml_id: n/a, model: sale.order, parent_id: 577]" while parsing /usr/lib/python2.7/dist-packages/openerp/addons/custom/sale_margin_percent/sale_margin_percent.xml:27, near <record model="ir.ui.view" id="sale_margin_percent_5"> <field name="name">change.purchase_price</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <xpath expr="//field[@name='order_line']/tree//field[@name='purchase_price']" position="attributes"> <attribute name="on_change">update_sale_price(sale_margin_percent, purchase_price, discount)</attribute> </xpath> </field> </record>


Why "purchase_price" is not found? (I have added a similar on_change attribute for "price_unit" which works fine)

Avatar
Discard
Best Answer

You had a similar problem recently, field purchase_price not exist in view sale.view_order_form, it exist in view sale_margin.sale_margin_sale_order_line_form. Try

...
 <field name="inherit_id" ref="sale_margin.sale_margin_sale_order_line_form"/>
...
Avatar
Discard
Author

Actually, there are two inherited views for this field: sale_margin.sale_margin_sale_order_line_form and sale_margin.sale_margin_sale_order_line Which are their differences?

Difference in .../form//field... and .../tree//field..., see sale_margin_view.xml

Author Best Answer

I finally understood/find how to fix that.

In developer mode,if you check form you will discover that the view which adds 'purchase_price' field is 'sale.order.line.margin.view.form'.

Therefore you have to inherit that view using its external ID:

<field name="inherit_id" ref="sale_margin.sale_margin_sale_order_line"/>

Avatar
Discard

/tree//field .... is added in sale_margin_sale_order_line_form, not in sale_margin_sale_order_line

Related Posts Replies Views Activity
0
Feb 16
3587
1
Jul 15
5622
2
Jun 15
3086
1
Jul 16
5188
2
Aug 16
9552