fix: adjust payment validation to support payments with amount_substract by relaxing line count checks for liquidity and counterpart lines.

This commit is contained in:
admin.suherdy 2025-12-06 19:07:59 +07:00
parent fbb48b893c
commit 38b3f179a1
3 changed files with 20 additions and 13 deletions

View File

@ -125,6 +125,11 @@ class AccountPayment(models.Model):
all_lines = move.line_ids all_lines = move.line_ids
liquidity_lines, counterpart_lines, writeoff_lines = pay._seek_for_lines() liquidity_lines, counterpart_lines, writeoff_lines = pay._seek_for_lines()
# Skip validation if payment has amount_substract (from vendor_payment_diff_amount module)
# This module creates additional lines that don't fit the standard pattern
has_substract = hasattr(pay, 'amount_substract') and pay.amount_substract and pay.amount_substract > 0
if not has_substract:
if len(liquidity_lines) != 1: if len(liquidity_lines) != 1:
raise UserError(_( raise UserError(_(
"Journal Entry %s is not valid. In order to proceed, the journal items must " "Journal Entry %s is not valid. In order to proceed, the journal items must "
@ -132,10 +137,12 @@ class AccountPayment(models.Model):
move.display_name, move.display_name,
)) ))
if len(counterpart_lines) != 1: # Allow for additional lines (like substract account from vendor_payment_diff_amount)
# Check if we have at least one counterpart line, not exactly one
if len(counterpart_lines) < 1:
raise UserError(_( raise UserError(_(
"Journal Entry %s is not valid. In order to proceed, the journal items must " "Journal Entry %s is not valid. In order to proceed, the journal items must "
"include one and only one receivable/payable account (with an exception of " "include at least one receivable/payable account (with an exception of "
"internal transfers).", "internal transfers).",
move.display_name, move.display_name,
)) ))