From fb1dc57e4e9b90180a0d658ec4d2a4477442d6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 22 Jul 2013 14:27:21 +0200 Subject: [PATCH] Fix COGS computation with negative quantity issue3287 review976002 (transplanted from b041a5be1444d626bd9105f28f6861c7695ffaa9) --- invoice.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/invoice.py b/invoice.py index 347e9902a9..742dbfbf15 100644 --- a/invoice.py +++ b/invoice.py @@ -81,10 +81,17 @@ class InvoiceLine: type_ = 'out_supplier' elif self.invoice.type == 'out_credit_note': type_ = 'in_customer' + if self.quantity < 0: + direction, target = type_.split('_') + if direction == 'in': + direction = 'out' + else: + direction = 'in' + type_ = '%s_%s' % (direction, target) moves.sort(key=operator.attrgetter('effective_date')) cost = Move.update_anglo_saxon_quantity_product_cost( - self.product, moves, self.quantity, self.unit, type_) + self.product, moves, abs(self.quantity), self.unit, type_) cost = self.invoice.currency.round(cost) anglo_saxon_move_lines = self._get_anglo_saxon_move_lines(cost, type_)