[FIX] account: Fix unbalanced journal entry when switching payment terms
When switching immediate payment term to 30% advance then back to immediate payment term, the receivable line is back to its previous value. This is due to the '_get_fields_onchange_balance' that is not updating correctly the business fields since price_subtotal == amount_currency. So, when `writing`, debit/credit are removed from the dictionary because the values are the same as before. However, `price_unit` hasn't be updated with the new value and remains as its previous value. It leads to a recomputation of accounting fields regarding the business fields and then, trigger the unbalanced journal entry. closes odoo/odoo#60654 X-original-commit: 18b5ad16a442404061b1028c2ffd82f179beaba3 Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com> Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user