Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 373211a09f | |||
| 4939587f93 | |||
| 1db0e2a556 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
'name': 'HR Expense Payment Status Override',
|
'name': 'HR Expense Payment Status Override',
|
||||||
'version': '17.0.1.0.0',
|
'version': '19.0.1.0.0',
|
||||||
'summary': 'Override the hardcoded "Paid" status for expenses paid by the company, keeping them "In Payment" until reconciled.',
|
'summary': 'Override the hardcoded "Paid" status for expenses paid by the company, keeping them "In Payment" until reconciled.',
|
||||||
'category': 'Human Resources/Expenses',
|
'category': 'Human Resources/Expenses',
|
||||||
'author': 'Suherdy Yacob',
|
'author': 'Suherdy Yacob',
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
from . import hr_expense_sheet
|
from . import hr_expense
|
||||||
|
|||||||
24
models/hr_expense.py
Normal file
24
models/hr_expense.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
class HrExpense(models.Model):
|
||||||
|
_inherit = 'hr.expense'
|
||||||
|
|
||||||
|
@api.depends('account_move_id.payment_state', 'account_move_id.origin_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.origin_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'
|
||||||
@ -1,27 +0,0 @@
|
|||||||
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'
|
|
||||||
Loading…
Reference in New Issue
Block a user