diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a4e5a040881..95eca2f7299 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -702,7 +702,7 @@ class AccountMove(models.Model): }) if in_draft_mode: - taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance()) + taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance(force_computation=True)) 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')): @@ -810,7 +810,7 @@ class AccountMove(models.Model): cash_rounding_line = create_method(rounding_line_vals) if in_draft_mode: - cash_rounding_line.update(cash_rounding_line._get_fields_onchange_balance()) + cash_rounding_line.update(cash_rounding_line._get_fields_onchange_balance(force_computation=True)) existing_cash_rounding_line = self.line_ids.filtered(lambda line: line.is_rounding_line) @@ -946,7 +946,7 @@ class AccountMove(models.Model): }) new_terms_lines += candidate if in_draft_mode: - candidate.update(candidate._get_fields_onchange_balance()) + candidate.update(candidate._get_fields_onchange_balance(force_computation=True)) return new_terms_lines existing_terms_lines = self.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable')) diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index e7485924517..f6d4fea0598 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -2706,3 +2706,13 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): invoice_onchange = move_form.save() _check_invoice_values(invoice_onchange) + + def test_out_invoice_multiple_switch_payment_terms(self): + ''' When switching immediate payment term to 30% advance then back to immediate payment term, ensure the + receivable line is back to its previous value. If some business fields are not well updated, it could lead to a + recomputation of debit/credit when writing and then, an unbalanced journal entry. + ''' + # assertNotUnbalancedEntryWhenSaving + with Form(self.invoice) as move_form: + move_form.invoice_payment_term_id = self.pay_terms_b # Switch to 30% in advance payment terms + move_form.invoice_payment_term_id = self.pay_terms_b # Back to immediate payment term