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 2b5e2b6 commit 781e761cc523f3e9a34183403cd1135be2d3d572
Showing with 4 additions and 1 deletion.
  1. +4 −1 addons/sale_margin/models/
@@ -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))
line.margin = line.price_subtotal - (price * line.product_uom_qty)

class SaleOrder(models.Model):

0 comments on commit 781e761

Please sign in to comment.