hr_expense_payment_status/models/hr_expense.py

25 lines
1.1 KiB
Python

from odoo import api, models
class HrExpense(models.Model):
_inherit = 'hr.expense'
@api.depends('account_move_id.payment_state', 'account_move_id.payment_id.is_matched')
def _compute_state(self):
super()._compute_state()
for expense in self:
if expense.payment_mode == 'company_account' and expense.account_move_id:
move = expense.account_move_id
if move.state == 'posted':
payment = move.payment_id
if payment:
if not payment.is_matched:
expense.state = 'in_payment'
else:
expense.state = 'paid'
else:
# If it's a journal entry without a payment object (e.g. manual entry)
# we keep it as 'paid' as per standard Odoo 19 shortcut or
# we could check if the move is reconciled.
# For now, keeping it simple to match the intent of the original module.
expense.state = 'paid'