From 211abaad9849cefbf93326742a4b295a94d3b4a2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 1 Feb 2023 11:25:16 +0700 Subject: add condition while compute margin --- indoteknik_custom/models/sale_order.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index b88d9ad0..75981275 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -355,8 +355,11 @@ class SaleOrderLine(models.Model): purchase_price = purchase_price * line.product_uom_qty margin_per_item = sales_price - purchase_price line.item_margin = margin_per_item - # if sales_price > 0: - line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 + + if sales_price > 0: + line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 + else: + line.item_percent_margin = 0 @api.onchange('vendor_id') def onchange_vendor_id(self): -- cgit v1.2.3