Hello, I try add a on_change on two fields (fields A and fields B). I wand that:
- if user change the fields A that aumaticaly change the fileds B.
- if user change the fields B that aumaticaly change the fileds A.
I take the 2 events and they work. But when I launch theim together, infinite loop.
It is possible to take what I want to do?
edit:
sale_perso.py:
def price_unit_change(self, cr, uid, ids, price_unit, product):
result = {}
if product:
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product)
result['coeff'] = price_unit / product_obj.standard_price
return {'value': result}
def coeff_change(self, cr, uid, ids, coeff, standard_price):
result = {}
result['price_unit'] = coeff * standard_price
return {'value': result}
sale_perso_view.xml: <openerp> <data>
<record model="ir.ui.view" id="sale_order_line_type_price">
<field name="name">sale.order.line.type.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='price_unit']" position="replace">
<field name="price_unit" on_change="price_unit_change(price_unit, product_id)"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="before">
<field name="standard_price"/>
<field name="coeff" on_change="coeff_change(coeff, standard_price)"/>
</xpath>
</field>
</record>
</data>
</openerp>
fields A and B will always have the same value.
on_change event is triggered when focused loses, pressing TAB or ENTER.
Please post your on_change method and XML on_change field. thanks
When you change A then on_change(A) is triggered to change B = A. Now B is changed, then on_changed(B) is triggered to change A. At this point there is no change for A, so on_change(A) is not triggered. So there is no infinite loop.