feat: pass expense_account_id to payment registration context for deduction handling

This commit is contained in:
Suherdy Yacob 2026-04-06 09:56:37 +07:00
parent a9c9b36057
commit 8eb1e6dada

View File

@ -229,6 +229,13 @@ class HrExpenseRealization(models.Model):
if not partner:
raise UserError(_("Employee must have a work contact to register a payment."))
# Find the correct account to clear from the realization's journal entry
expense_account_id = False
if self.move_id:
balancing_line = self.move_id.line_ids.filtered(lambda l: l.account_id.code in ('114101', '216109'))
if balancing_line:
expense_account_id = balancing_line[0].account_id.id
return {
'name': _('Register Payment'),
'type': 'ir.actions.act_window',
@ -242,6 +249,7 @@ class HrExpenseRealization(models.Model):
'default_amount': abs(self.discrepancy_amount),
'default_ref': f"Realization Balance: {self.name}",
'default_realization_id': self.id,
'default_expense_account_id': expense_account_id, # Required when applying deductions (vendor_payment_diff_amount)
}
}