[FIX] account: Wrong base amount with included tax

Steps to reproduce the bug:

Let's consider a company C with french accounting
Create a new journal entry JE with one line L with debit = 100 and credit = 0
and account = 601100 Achats stockés - Matières premières ou groupe A)
Set TVA déductible (achat) 20,0% TTC on JE (where this tax is included
in price but not included in base amount)
Bug:

A new line is created on account 445660 TVA déductible sur autre bien et service with a debit = 16,67 instead of 20.0 and credit 0

Now with this fix, we consider that the amount encoded by the user is the base on which each taxes must be computed (instead of
magically subtracting included tax from the base)

opw:2244708

closes odoo/odoo#51219

X-original-commit: c9ce26534d2f8fa69068bfdbeb9994eb12d4124e
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-05-14 06:48:25 +00:00
parent 5184eedc0e
commit 2b8e405d75
2 changed files with 59 additions and 0 deletions
+6
View File
@@ -547,6 +547,11 @@ class AccountMove(models.Model):
price_unit_foreign_curr = base_line.amount_currency
price_unit_comp_curr = base_line.balance
if move.is_invoice(include_receipts=True):
handle_price_include = True
else:
handle_price_include = False
balance_taxes_res = base_line.tax_ids._origin.compute_all(
price_unit_comp_curr,
currency=base_line.company_currency_id,
@@ -554,6 +559,7 @@ class AccountMove(models.Model):
product=base_line.product_id,
partner=base_line.partner_id,
is_refund=self.move_type in ('out_refund', 'in_refund'),
handle_price_include=handle_price_include,
)
if base_line.currency_id:
@@ -573,3 +573,56 @@ class TestAccountMove(AccountTestInvoicingCommon):
},
],
)
def test_included_tax(self):
'''
Test an account.move.line is created automatically when adding a tax.
This test uses the following scenario:
- Create manually a debit line of 1000 having an included tax.
- Assume a line containing the tax amount is created automatically.
- Create manually a credit line to balance the two previous lines.
- Save the move.
included tax = 20%
Name | Debit | Credit | Tax_ids | Tax_line_id's name
-----------------------|-----------|-----------|---------------|-------------------
debit_line_1 | 1000 | | tax |
included_tax_line | 200 | | | included_tax_line
credit_line_1 | | 1200 | |
'''
self.included_percent_tax = self.env['account.tax'].create({
'name': 'included_tax_line',
'amount_type': 'percent',
'amount': 20,
'price_include': True,
'include_base_amount': False,
})
self.account = self.env['account.account'].search([('deprecated', '=', False)], limit=1)
move_form = Form(self.env['account.move'])
# Create a new account.move.line with debit amount.
with move_form.line_ids.new() as debit_line:
debit_line.name = 'debit_line_1'
debit_line.account_id = self.account
debit_line.debit = 1000
debit_line.tax_ids.clear()
debit_line.tax_ids.add(self.included_percent_tax)
self.assertTrue(debit_line.recompute_tax_line)
# Create a third account.move.line with credit amount.
with move_form.line_ids.new() as credit_line:
credit_line.name = 'credit_line_1'
credit_line.account_id = self.account
credit_line.credit = 1200
move = move_form.save()
self.assertRecordValues(move.line_ids, [
{'name': 'debit_line_1', 'debit': 1000.0, 'credit': 0.0, 'tax_ids': [self.included_percent_tax.id], 'tax_line_id': False},
{'name': 'included_tax_line', 'debit': 200.0, 'credit': 0.0, 'tax_ids': [], 'tax_line_id': self.included_percent_tax.id},
{'name': 'credit_line_1', 'debit': 0.0, 'credit': 1200.0, 'tax_ids': [], 'tax_line_id': False},
])