hr_expense_payment_status/models/hr_expense_sheet.py
2026-03-31 11:55:30 +07:00

28 lines
1.4 KiB
Python

from odoo import api, models
class HrExpenseSheet(models.Model):
_inherit = 'hr.expense.sheet'
@api.depends('account_move_ids.payment_state', 'account_move_ids.payment_id.is_matched')
def _compute_from_account_move_ids(self):
# Call the original method to compute default values first
super()._compute_from_account_move_ids()
# Override specific logic to prevent company-paid expenses from immediately jumping to 'Paid'
for sheet in self:
if sheet.payment_mode == 'company_account':
if sheet.account_move_ids:
moves = sheet.account_move_ids - sheet.account_move_ids.filtered('reversal_move_id')
if moves:
payments = moves.mapped('payment_id')
# Find if any linked payment is not yet matched to a bank statement
unmatched_payments = payments.filtered(lambda p: not p.is_matched)
if unmatched_payments:
# If there are unmatched payments, it should stay 'In Payment'
sheet.payment_state = 'in_payment'
else:
# If all payments are matched (or we have manual entries), it is Paid
sheet.payment_state = 'paid'