From cef142b69b6c81ff67a92dffe010e95e4489f3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 16 Jun 2009 22:48:23 +0200 Subject: [PATCH] Round tax amounts in the same way than for invoice --- sale.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/sale.py b/sale.py index 990f84a64e..6216da19fe 100644 --- a/sale.py +++ b/sale.py @@ -300,6 +300,7 @@ class Sale(OSV): def on_change_lines(self, cursor, user, ids, vals, context=None): currency_obj = self.pool.get('currency.currency') tax_obj = self.pool.get('account.tax') + invoice_obj = self.pool.get('account.invoice') if context is None: context = {} @@ -319,6 +320,7 @@ class Sale(OSV): ctx = context.copy() ctx.update(self.get_tax_context(cursor, user, vals, context=context)) + taxes = {} for line in vals['lines']: if line.get('type', 'line') != 'line': continue @@ -327,7 +329,16 @@ class Sale(OSV): for tax in tax_obj.compute(cursor, user, line.get('taxes', []), line.get('unit_price', Decimal('0.0')), line.get('quantity', 0.0), context=context): - res['tax_amount'] += tax['amount'] + key, val = invoice_obj._compute_tax(cursor, user, tax, + 'out_invoice', context=context) + if not key in taxes: + taxes[key] = val['amount'] + else: + taxes[key] += val['amount'] + if currency: + for key in taxes: + res['tax_amount'] += currency_obj.round(cursor, user, + currency, taxes[key]) if currency: res['untaxed_amount'] = currency_obj.round(cursor, user, currency, res['untaxed_amount']) @@ -424,6 +435,8 @@ class Sale(OSV): ''' currency_obj = self.pool.get('currency.currency') tax_obj = self.pool.get('account.tax') + invoice_obj = self.pool.get('account.invoice') + if context is None: context = {} res = {} @@ -432,6 +445,7 @@ class Sale(OSV): ctx.update(self.get_tax_context(cursor, user, sale, context=context)) res.setdefault(sale.id, Decimal('0.0')) + taxes = {} for line in sale.lines: if line.type != 'line': continue @@ -439,7 +453,15 @@ class Sale(OSV): for tax in tax_obj.compute(cursor, user, [t.id for t in line.taxes], line.unit_price, line.quantity, context=ctx): - res[sale.id] += tax['amount'] + key, val = invoice_obj._compute_tax(cursor, user, tax, + 'out_invoice', context=context) + if not key in taxes: + taxes[key] = val['amount'] + else: + taxes[key] += val['amount'] + for key in taxes: + res[sale.id] += currency_obj.round(cursor, user, + sale.currency, taxes[key]) res[sale.id] = currency_obj.round(cursor, user, sale.currency, res[sale.id]) return res