Round tax amounts in the same way than for invoice
This commit is contained in:
1 parent
33b2489e8a
commit
89cf5b15da
1 file changed
+25
-2
+25
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user