From 37e4bd85a31220931358b6b3b5abbacd7838c230 Mon Sep 17 00:00:00 2001 From: resteve Date: Thu, 3 Oct 2013 11:55:55 +0200 Subject: [PATCH] sale line: get margin depends amount and operation if self.amount --- sale.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sale.py b/sale.py index 0464a5d..1416e86 100755 --- a/sale.py +++ b/sale.py @@ -62,9 +62,9 @@ class SaleLine: states={ 'invisible': ~Eval('type').in_(['line', 'subtotal']), 'readonly': ~Eval('_parent_sale'), - }, on_change_with=['type', 'quantity', 'cost_price', + }, on_change_with=['type', 'quantity', 'cost_price', 'amount', 'unit_price', 'unit', '_parent_sale.currency'], - depends=['type']), 'get_margin') + depends=['type', 'amount']), 'get_margin') def on_change_product(self): if not self.product: @@ -76,8 +76,9 @@ class SaleLine: def on_change_with_margin(self): cost = Decimal(str(self.quantity or '0.0')) * \ (self.cost_price or Decimal('0.0')) - res = Decimal(self.amount-cost) - return res + if self.amount: + return Decimal(self.amount-cost) + return Decimal('0.0') def get_margin(self, name): '''