From 2b8e405d7533ed5caa06320bcb6cd978a691aece Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 13 May 2020 12:21:43 +0000 Subject: [PATCH] [FIX] account: Wrong base amount with included tax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/account/models/account_move.py | 6 +++ .../account/tests/test_account_move_entry.py | 53 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 03ffa85c85c..b14840168b0 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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: diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index aba886a1929..c9aed21ba67 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -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}, + ])