[FIX] account: fix price included taxes in reconciliation widget

Suppose a bank statement of 11$ and a tax 10% price_included.
The result shown by the reconciliation widget is

 D | C
11 |
   | 10
   | 1

that is correct. However, after clicking on validate, the result is

 D | C
10 |
   | 9.09
   | 0.91

because the taxes are recomputed python-side and the values of the account.move.line are
amount = 10, tax_id = 10% incl. Then, the tax is recomputed on 10 instead of 11$.

-opw: 776644
This commit is contained in:
Laurent Smet
2017-10-24 09:14:48 +02:00
parent 58ed404a32
commit 9bf4b70287
3 changed files with 8 additions and 4 deletions
+5 -2
View File
@@ -817,7 +817,7 @@ class AccountTax(models.Model):
if tax.include_base_amount:
base = recompute_base(base, incl_fixed_amount, incl_percent_amount)
incl_fixed_amount = incl_percent_amount = 0
if tax.price_include:
if self._context.get('force_price_include', tax.price_include):
if tax.amount_type == 'fixed':
incl_fixed_amount += tax.amount
elif tax.amount_type == 'percent':
@@ -839,7 +839,10 @@ class AccountTax(models.Model):
# took into account on the base amount except for 'division' tax:
# (tax.amount_type == 'percent' && not tax.price_include)
# == (tax.amount_type == 'division' && tax.price_include)
tax_amount = tax.with_context(force_price_include=False)._compute_amount(base, price_unit, quantity, product, partner)
# N.B: don't use the with_context if force_price_include already False in context
if 'force_price_include' not in self._context or self._context['force_price_include']:
tax = tax.with_context(force_price_include=False)
tax_amount = tax._compute_amount(base, price_unit, quantity, product, partner)
if not round_tax:
tax_amount = round(tax_amount, prec)
else:
@@ -819,6 +819,7 @@ class AccountBankStatementLine(models.Model):
whose value is the same as described in process_reconciliation except that ids are used instead of recordsets.
"""
AccountMoveLine = self.env['account.move.line']
ctx = dict(self._context, force_price_include=False)
for st_line, datum in zip(self, data):
payment_aml_rec = AccountMoveLine.browse(datum.get('payment_aml_ids', []))
for aml_dict in datum.get('counterpart_aml_dicts', []):
@@ -826,7 +827,7 @@ class AccountBankStatementLine(models.Model):
del aml_dict['counterpart_aml_id']
if datum.get('partner_id') is not None:
st_line.write({'partner_id': datum['partner_id']})
st_line.process_reconciliation(datum.get('counterpart_aml_dicts', []), payment_aml_rec, datum.get('new_aml_dicts', []))
st_line.with_context(ctx).process_reconciliation(datum.get('counterpart_aml_dicts', []), payment_aml_rec, datum.get('new_aml_dicts', []))
def fast_counterpart_creation(self):
for st_line in self:
+1 -1
View File
@@ -1194,7 +1194,7 @@ class AccountMoveLine(models.Model):
taxes = self.env['account.tax'].browse(tax_ids)
currency = self.env['res.currency'].browse(vals.get('currency_id'))
partner = self.env['res.partner'].browse(vals.get('partner_id'))
res = taxes.with_context(round=True).compute_all(amount,
res = taxes.with_context(dict(self._context, round=True)).compute_all(amount,
currency, 1, vals.get('product_id'), partner)
# Adjust line amount if any tax is price_include
if abs(res['total_excluded']) < abs(amount):