Skip to content

Commit

Permalink
[FIX] account: fix price included taxes in reconciliation widget
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smetl committed Oct 24, 2017
1 parent 58ed404 commit 9bf4b70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions addons/account/models/account.py
Expand Up @@ -817,7 +817,7 @@ def recompute_base(base_amount, fixed_amount, percent_amount):
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':
Expand All @@ -839,7 +839,10 @@ def recompute_base(base_amount, fixed_amount, percent_amount):
# 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:
Expand Down
3 changes: 2 additions & 1 deletion addons/account/models/account_bank_statement.py
Expand Up @@ -819,14 +819,15 @@ def process_reconciliations(self, data):
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', []):
aml_dict['move_line'] = AccountMoveLine.browse(aml_dict['counterpart_aml_id'])
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:
Expand Down
2 changes: 1 addition & 1 deletion addons/account/models/account_move.py
Expand Up @@ -1194,7 +1194,7 @@ def create(self, vals):
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):
Expand Down

0 comments on commit 9bf4b70

Please sign in to comment.