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}, + ])