From 96f217f358caea0a0dfbf345023ef3d7d4382d4c Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 6 Apr 2026 16:14:25 +0700 Subject: [PATCH] fix: prevent double counting of deduction lines by filtering write-off values in account payment move generation --- models/account_payment.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/models/account_payment.py b/models/account_payment.py index 11b01eb..8cd547b 100755 --- a/models/account_payment.py +++ b/models/account_payment.py @@ -243,12 +243,23 @@ class AccountPayment(models.Model): - Bank: credit 1850 (final_payment_amount) Total: debit 2000 = credit 2000 (balanced) """ + # Filter out existing deductions from write_off_line_vals to prevent double counting + # by Odoo's native balancing logic. + if write_off_line_vals and self.deduction_line_ids: + deduction_account_ids = self.deduction_line_ids.mapped('substract_account_id').ids + filtered_write_offs = [] + for w in write_off_line_vals: + if w.get('account_id') not in deduction_account_ids: + filtered_write_offs.append(w) + write_off_line_vals = filtered_write_offs + # Get standard line values from parent line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance) # Only modify if we have deductions if self.amount_substract and self.amount_substract > 0 and self.deduction_line_ids: if self.payment_type == 'outbound': + # Get existing deduction account IDs to prevent duplicates existing_deduction_accounts = { line.get('account_id')