From 89cf5b15daef7009d12252d04372ad584995a368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 16 Jun 2009 22:48:05 +0200 Subject: [PATCH] Round tax amounts in the same way than for invoice --- purchase.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/purchase.py b/purchase.py index 8e79520d86..93dfe2fd08 100644 --- a/purchase.py +++ b/purchase.py @@ -251,6 +251,8 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): 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 = {} res = { @@ -266,6 +268,7 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): 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 @@ -274,7 +277,16 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): 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, + 'in_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']) @@ -391,6 +403,8 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): ''' 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 = {} @@ -399,6 +413,7 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): ctx.update(self.get_tax_context(cursor, user, purchase, context=context)) res.setdefault(purchase.id, Decimal('0.0')) + taxes = {} for line in purchase.lines: if line.type != 'line': continue @@ -406,7 +421,15 @@ class Purchase(ModelWorkflow, ModelSQL, ModelView): for tax in tax_obj.compute( cursor, user, [t.id for t in line.taxes], line.unit_price, line.quantity, context=ctx): - res[purchase.id] += tax['amount'] + key, val = invoice_obj._compute_tax(cursor, user, tax, + 'in_invoice', context=context) + if not key in taxes: + taxes[key] = val['amount'] + else: + taxes[key] += val['amount'] + for key in taxes: + res[purchase.id] += currency_obj.round(cursor, user, + purchase.currency, taxes[key]) res[purchase.id] = currency_obj.round(cursor, user, purchase.currency, res[purchase.id]) return res