From dd2ac143f797dbfb0271c3a857bf51cead11c12a Mon Sep 17 00:00:00 2001 From: fw-bot Date: Thu, 17 Sep 2020 14:08:45 +0000 Subject: [PATCH] [FIX] account: cash basis taxes: set move lines as tax_exigible=False only when some other line has a payable or receivable account in the move. Before that, making a misc operation with cash basis taxes always set the move lines as tax_exigible=False (or at least, it was supposed to, see below). This was wrong, as if the move did not contain any payable/receivable account, it would result in no cash basis move being ever created, and so the entry would never affect the tax report. Additionnally, the tax line was wrongly managed for cash basis taxes on misc entries, as vals.get('tax_ids') returned an ORM command, so a non-False value, even when the tax_ids field was empty. this caused the condition to execute and to reassign taxes to an empty list, which then caused tax_exigible not to be set to False, even when it should. X-original-commit: https://github.com/odoo/odoo/commit/2437eb0691d07f92094152b84c96a2149c8f4fd8 [FIX] account: make tax exigible correct in cases where the move lines are created separetely from the move. Additional fix on top of https://github.com/odoo/odoo/commit/02fe997932070cc101a96eb869023702c224318b Also, add tax_exigible to the form view of account.move.line, as it will not be computed automatically anymore when modifying a single line in draft state through its form view. It now needs to be manually changed in case the user wants to change something having an impact on it through this form (note that this is absolutely not a typical use case). closes odoo/odoo#58260 X-original-commit: 867797e4983b704599be7943490fc6f071d8c0b7 Signed-off-by: Laurent Smet Signed-off-by: oco-odoo --- addons/account/models/account_move.py | 35 +++++++++++-------- .../tests/test_account_move_in_invoice.py | 4 +-- .../tests/test_account_move_in_refund.py | 4 +-- .../tests/test_account_move_out_invoice.py | 4 +-- .../tests/test_account_move_out_refund.py | 4 +-- addons/account/views/account_move_views.xml | 1 + 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 71bc0b682e7..2905ff4764d 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -704,6 +704,19 @@ class AccountMove(models.Model): if in_draft_mode: taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance()) + def update_lines_tax_exigibility(self): + if all(account.user_type_id.type not in {'payable', 'receivable'} for account in self.mapped('line_ids.account_id')): + self.line_ids.write({'tax_exigible': True}) + else: + tax_lines_caba = self.line_ids.filtered(lambda x: x.tax_line_id.tax_exigibility == 'on_payment') + base_lines_caba = self.line_ids.filtered(lambda x: any(tax.tax_exigibility == 'on_payment' + or (tax.amount_type == 'group' + and 'on_payment' in tax.mapped('children_tax_ids.tax_exigibility')) + for tax in x.tax_ids)) + caba_lines = tax_lines_caba + base_lines_caba + caba_lines.write({'tax_exigible': False}) + (self.line_ids - caba_lines).write({'tax_exigible': True}) + def _recompute_cash_rounding_lines(self): ''' Handle the cash rounding feature on invoices. @@ -1755,7 +1768,10 @@ class AccountMove(models.Model): raise UserError(_('You cannot create a move already in the posted state. Please create a draft move and post it after.')) vals_list = self._move_autocomplete_invoice_lines_create(vals_list) - return super(AccountMove, self).create(vals_list) + rslt = super(AccountMove, self).create(vals_list) + if 'line_ids' in vals_list: + rslt.update_lines_tax_exigibility() + return rslt def write(self, vals): for move in self: @@ -1801,8 +1817,10 @@ class AccountMove(models.Model): res |= super(AccountMove, move).write(vals_hashing) # Ensure the move is still well balanced. - if 'line_ids' in vals and self._context.get('check_move_validity', True): - self._check_balanced() + if 'line_ids' in vals: + if self._context.get('check_move_validity', True): + self._check_balanced() + self.update_lines_tax_exigibility() self._synchronize_business_models(set(vals.keys())) @@ -3688,17 +3706,6 @@ class AccountMoveLine(models.Model): move.date, )) - # Ensure consistency between taxes & tax exigibility fields. - if 'tax_exigible' in vals: - continue - if vals.get('tax_repartition_line_id'): - repartition_line = self.env['account.tax.repartition.line'].browse(vals['tax_repartition_line_id']) - tax = repartition_line.invoice_tax_id or repartition_line.refund_tax_id - vals['tax_exigible'] = tax.tax_exigibility == 'on_invoice' - elif vals.get('tax_ids'): - taxes = self.new({'tax_ids': vals['tax_ids']}).tax_ids.flatten_taxes_hierarchy() - vals['tax_exigible'] = not any(tax.tax_exigibility == 'on_payment' for tax in taxes) - lines = super(AccountMoveLine, self).create(vals_list) moves = lines.mapped('move_id') diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 278260d40c5..c9df200825c 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -770,7 +770,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'debit': 64.0, 'credit': 0.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_1.name, @@ -790,7 +790,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'debit': 96.0, 'credit': 0.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_2.name, diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index 262a1a82513..593cdde3a41 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -481,7 +481,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'debit': 0.0, 'credit': 96.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_1.name, @@ -501,7 +501,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'debit': 0.0, 'credit': 64.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_2.name, diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 0d31b231ede..e50a62b5689 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -773,7 +773,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'debit': 0.0, 'credit': 120.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_1.name, @@ -793,7 +793,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'debit': 0.0, 'credit': 80.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_2.name, diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index c1720dd2ba8..967eb2326a6 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -481,7 +481,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'debit': 80.0, 'credit': 0.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_1.name, @@ -501,7 +501,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'debit': 120.0, 'credit': 0.0, 'date_maturity': False, - 'tax_exigible': True, + 'tax_exigible': False, }, { 'name': child_tax_2.name, diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 27381a5e04f..66d6b010264 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -41,6 +41,7 @@ +