From bb72dea98de4dae8f59e397f232a0636411d37ce Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 9 Aug 2016 14:01:42 +0200 Subject: [PATCH] [FIX] account: return of product with unit price = 0 and fixed tax Use copysign to take into account the sign of the base amount which includes the sign of the quantity and the sign of the price_unit Amount is the fixed price for the tax, it can be negative Base amount included the sign of the quantity and the sign of the unit price and when a product is returned, it can be done either by changing the sign of quantity or by changing the sign of the price unit. When the price unit is equal to 0, the sign of the quantity is absorbed in base_amount then a "else" case is needed. opw:684459 --- addons/account/models/account.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 91a95ba359d..1d1d50cfc01 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -615,7 +615,16 @@ class AccountTax(models.Model): if self.amount_type == 'fixed': # Use copysign to take into account the sign of the base amount which includes the sign # of the quantity and the sign of the price_unit - return math.copysign(quantity, base_amount) * self.amount + # Amount is the fixed price for the tax, it can be negative + # Base amount included the sign of the quantity and the sign of the unit price and when + # a product is returned, it can be done either by changing the sign of quantity or by changing the + # sign of the price unit. + # When the price unit is equal to 0, the sign of the quantity is absorbed in base_amount then + # a "else" case is needed. + if base_amount: + return math.copysign(quantity, base_amount) * self.amount + else: + return quantity * self.amount if (self.amount_type == 'percent' and not self.price_include) or (self.amount_type == 'division' and self.price_include): return base_amount * self.amount / 100 if self.amount_type == 'percent' and self.price_include: