fix: prevent double counting of deduction lines by filtering write-off values in account payment move generation
This commit is contained in:
parent
eb424840ce
commit
96f217f358
@ -243,12 +243,23 @@ class AccountPayment(models.Model):
|
|||||||
- Bank: credit 1850 (final_payment_amount)
|
- Bank: credit 1850 (final_payment_amount)
|
||||||
Total: debit 2000 = credit 2000 (balanced)
|
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
|
# Get standard line values from parent
|
||||||
line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance)
|
line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance)
|
||||||
|
|
||||||
# Only modify if we have deductions
|
# Only modify if we have deductions
|
||||||
if self.amount_substract and self.amount_substract > 0 and self.deduction_line_ids:
|
if self.amount_substract and self.amount_substract > 0 and self.deduction_line_ids:
|
||||||
if self.payment_type == 'outbound':
|
if self.payment_type == 'outbound':
|
||||||
|
|
||||||
# Get existing deduction account IDs to prevent duplicates
|
# Get existing deduction account IDs to prevent duplicates
|
||||||
existing_deduction_accounts = {
|
existing_deduction_accounts = {
|
||||||
line.get('account_id')
|
line.get('account_id')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user