diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 42d526d7d08..f0372c241f6 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2608,10 +2608,6 @@ class AccountMove(models.Model): # invoice_repartition_line => refund_repartition_line mapping = {} - # Do nothing if the move is not a credit note. - if move_vals['move_type'] not in ('out_refund', 'in_refund'): - return mapping - for line_command in move_vals.get('line_ids', []): line_vals = line_command[2] # (0, 0, {...}) @@ -2631,7 +2627,18 @@ class AccountMove(models.Model): move_vals = self.with_context(include_business_fields=True).copy_data(default=default_values)[0] - tax_repartition_lines_mapping = compute_tax_repartition_lines_mapping(move_vals) + is_refund = False + if move_vals['move_type'] in ('out_refund', 'in_refund'): + is_refund = True + elif move_vals['move_type'] == 'entry': + base_lines = self.line_ids.filtered(lambda line: line.tax_ids) + tax_type = set(base_lines.tax_ids.mapped('type_tax_use')) + if tax_type == {'sale'} and sum(base_lines.mapped('debit')) == 0: + is_refund = True + elif tax_type == {'purchase'} and sum(base_lines.mapped('credit')) == 0: + is_refund = True + + tax_repartition_lines_mapping = compute_tax_repartition_lines_mapping(move_vals) if is_refund else {} for line_command in move_vals.get('line_ids', []): line_vals = line_command[2] # (0, 0, {...}) @@ -2650,7 +2657,7 @@ class AccountMove(models.Model): 'credit': balance < 0.0 and -balance or 0.0, }) - if move_vals['move_type'] not in ('out_refund', 'in_refund'): + if not is_refund: continue # ==== Map tax repartition lines ==== diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 6fa4e61568f..0c25ef6d9d2 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -1907,6 +1907,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): def test_reconcile_cash_basis_revert(self): ''' Ensure the cash basis journal entry can be reverted. ''' self.cash_basis_transfer_account.reconcile = True + self.cash_basis_tax_a_third_amount.cash_basis_transition_account_id = self.tax_account_1 invoice_move = self.env['account.move'].create({ 'move_type': 'entry',