From 0b8eb71d7143af6fd3bfee19dcf6cb668329d250 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 14 Nov 2019 09:49:26 +0000 Subject: [PATCH] [FIX] sale_margin: recompute purchase_price on product_id_change. When creating sale order lines from the matrix (sale_product_matrix), the purchase_price weren't computed No cleaner change has been found to ensure the cost is computed. Triggering all onchanges from the server side is quite tricky and dirty to do... closes odoo/odoo#40986 X-original-commit: 5c15b1310729129e390b455b0d1e0ac367f8dd69 Signed-off-by: Victor Feyens (vfe) --- addons/sale_margin/models/sale_order.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/sale_margin/models/sale_order.py b/addons/sale_margin/models/sale_order.py index 6c7f9d10dc7..7a813e1b210 100644 --- a/addons/sale_margin/models/sale_order.py +++ b/addons/sale_margin/models/sale_order.py @@ -40,6 +40,13 @@ class SaleOrderLine(models.Model): return self.purchase_price = self._compute_margin(self.order_id, self.product_id, self.product_uom) + @api.onchange('product_id') + def product_id_change(self): + # VFE FIXME : bugfix for matrix, the purchase_price will be changed to a computed field in master. + res = super(SaleOrderLine, self).product_id_change() + self.product_id_change_margin() + return res + @api.model def create(self, vals): vals.update(self._prepare_add_missing_fields(vals))