[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) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2019-11-14 09:55:14 +00:00
parent 7581097779
commit 0b8eb71d71
+7
View File
@@ -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))