I'm inherit purchase.order.line and try change value in field. For product_qty I can change value but for price_unit I can't change value.
My custom .py file:
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
@api.onchange('product_id')
def my_fucn(self):
for rec in self:
rec.product_qty = 10 #WORKING
rec.price_unit = 1 #NOT WORKING
Maybe is problem because in original purcahase.py odoo file also have @api.onchange('product_id').
Any solution?
You can't predict which onchange method will be triggered first or last, but the original onchange method for
product_id
changes inpurchase.order.line
is setting theprice_unit
field, but not theproduct_qty
field.So it seems your method is called before the other one, because
price_unit
is overwritten. You can check that by debugging both methods.What to do now? I would prefer the extension of the original method:
In your case a
product_qty
change will trigger another onchange event. Always have in mind, that field changes can trigger onchange events and field recomputations.Try to extend both methods: