Permalink
Browse files

[FIX] sale_margin: product margin round error

In a SO without customer:

Before this commit, the _product_margin wasn't working. This because,
as the customer is not defined, the pricelist isn't defined either,
and therefore currency of the pricelist is also undefined.
When you call the round function, in an undefined currency
an error is raised.

Now we take into account if customer is defined.
  • Loading branch information...
jpp-odoo committed Feb 11, 2019
1 parent 4e26fa3 commit 6f4d5c62da966f3d6a083b74ccf37b5dd6d7d93b
Showing with 4 additions and 1 deletion.
  1. +4 −1 addons/sale_margin/models/sale_order.py
@@ -60,7 +60,10 @@ def _product_margin(self):
for line in self:
currency = line.order_id.pricelist_id.currency_id
price = line.purchase_price
line.margin = currency.round(line.price_subtotal - (price * line.product_uom_qty))
if currency:
line.margin = currency.round(line.price_subtotal - (price * line.product_uom_qty))
else:
line.margin = line.price_subtotal - (price * line.product_uom_qty)


class SaleOrder(models.Model):

0 comments on commit 6f4d5c6

Please sign in to comment.