Skip to content
Permalink
Browse files

[FIX] account: tax computation on move

- Create the following invoice:
  Line 1: price 0.50, tax 15 %, analytic account set
  Line 2: price 0.10, tax 15 %, analytic account set
- Validate
- Go to the journal entry, cancel it
- Edit the entry, remove an analytic account

The tax line is recomputed from 0.10 to 0.09.

This is because the onchange performs the tax computation on all grouped
lines at once, which is equivalent to a 'round globally' configuration.

We need to split the logic depending on the tax calculation rounding
method.

opw-2117398

closes #39960

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information...
nim-odoo committed Nov 7, 2019
1 parent 472a8f7 commit c03298545571e8c8b8f1182dddeaeea02fc66a71
Showing with 26 additions and 3 deletions.
  1. +26 −3 addons/account/models/account_move.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from copy import deepcopy
import logging
import time
from datetime import date
@@ -218,9 +219,31 @@ def _get_tax_account(tax, amount):
balance = sum([l.balance for l in lines_to_sum])

# Compute the tax amount one by one.
quantity = len(lines_to_sum) if tax.amount_type == 'fixed' else 1
taxes_vals = tax.compute_all(balance,
quantity=quantity, currency=line.currency_id, product=line.product_id, partner=line.partner_id)
if self.company_id.tax_calculation_rounding_method == 'round_globally':
quantity = len(lines_to_sum) if tax.amount_type == 'fixed' else 1
taxes_vals = tax.compute_all(balance,
quantity=quantity, currency=line.currency_id, product=line.product_id, partner=line.partner_id)
else:
taxes_vals_line = [
tax.compute_all(
lts.balance, quantity=1.0, currency=line.currency_id,
product=line.product_id, partner=line.partner_id
)
for lts in lines_to_sum
]
taxes_vals = {
'base': 0.0,
'total_excluded': 0.0,
'total_included': 0.0,
'taxes': deepcopy(taxes_vals_line[0]['taxes']),
}
taxes_vals['taxes'][0]['base'] = 0.0
taxes_vals['taxes'][0]['amount'] = 0.0
for val in taxes_vals_line:
taxes_vals['base'] += val['base']
taxes_vals['total_excluded'] += val['total_excluded']
taxes_vals['taxes'][0]['base'] += sum([v['base'] for v in val['taxes']])
taxes_vals['taxes'][0]['amount'] += sum([v['amount'] for v in val['taxes']])

if tax_line:
# Update the existing tax_line.

0 comments on commit c032985

Please sign in to comment.
You can’t perform that action at this time.