From 7a24df4889de386faa69e9f763214427a3eed46f Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 17 Apr 2018 12:46:26 +0200 Subject: [PATCH] [FIX] sale_margin: Fall back on the user company if not set on the SO line As the company is not required on a sales order, this could lead to errors when trying to compute the margin as _convert is expecting a valid company. --- addons/sale_margin/models/sale_order.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/sale_margin/models/sale_order.py b/addons/sale_margin/models/sale_order.py index bd1687a8e2a..cf5902d6b2b 100644 --- a/addons/sale_margin/models/sale_order.py +++ b/addons/sale_margin/models/sale_order.py @@ -29,7 +29,9 @@ class SaleOrderLine(models.Model): if product_uom != product.uom_id: purchase_price = product.uom_id._compute_price(purchase_price, product_uom) price = frm_cur._convert( - purchase_price, to_cur, self.order_id.company_id, date or fields.Date.today(), round=False) + purchase_price, to_cur, + self.order_id.company_id or self.env.user.company_id, + date or fields.Date.today(), round=False) return {'purchase_price': price} @api.onchange('product_id', 'product_uom') @@ -63,7 +65,7 @@ class SaleOrderLine(models.Model): price = from_cur._convert( line.product_id.standard_price, currency, - line.order_id.company_id, + line.order_id.company_id or self.env.user.company_id, line.order_id.date_order or fields.Date.today(), round=False) line.margin = currency.round(line.price_subtotal - (price * line.product_uom_qty))