fix: update payment state computation to correctly identify in-payment status based on payment matching

This commit is contained in:
Suherdy Yacob 2026-04-06 15:31:26 +07:00
parent 3b6e99df13
commit 7aecb175bd

View File

@ -150,7 +150,7 @@ class HrExpenseSheet(models.Model):
else:
sheet.receipt_status = 'pending'
@api.depends('account_move_ids.payment_state', 'account_move_ids.amount_residual', 'account_move_ids.state')
@api.depends('account_move_ids.payment_state', 'account_move_ids.amount_residual', 'account_move_ids.state', 'account_move_ids.payment_id.is_matched')
def _compute_from_account_move_ids(self):
"""
Overriding to fix the 'IN PAYMENT' ribbon issue.
@ -164,8 +164,15 @@ class HrExpenseSheet(models.Model):
active_moves = sheet.account_move_ids.filtered(lambda m: m.state == 'posted')
if active_moves:
# If there are active moves that are not reversed
if active_moves - active_moves.filtered('reversal_move_id'):
sheet.payment_state = 'paid'
moves = active_moves - active_moves.filtered('reversal_move_id')
if moves:
payments = moves.mapped('payment_id')
unmatched_payments = payments.filtered(lambda p: not p.is_matched)
if unmatched_payments:
sheet.payment_state = 'in_payment'
else:
sheet.payment_state = 'paid'
sheet.amount_residual = 0.
else:
sheet.payment_state = 'reversed'