Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[SOLVED] How to add an on_change attribute to 'purchase_price' in a sales order form

By
E.M.
on 7/25/15, 5:43 PM 648 views

 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)

1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 7/26/15, 2:23 AM

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

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?

E.M.
on 7/26/15, 3:31 AM

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

zbik
on 7/27/15, 2:28 AM
0
E.M.
On 7/26/15, 2:16 AM

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

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

zbik
on 7/26/15, 2:47 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/25/15, 5:43 PM
Seen: 648 times
Last updated: 7/26/15, 3:25 AM