From 8eb1e6dadaf4264830ec8f81ec34ad7ba2f52048 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 6 Apr 2026 09:56:37 +0700 Subject: [PATCH] feat: pass expense_account_id to payment registration context for deduction handling --- models/hr_expense_realization.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/models/hr_expense_realization.py b/models/hr_expense_realization.py index 17da95f..1752ec5 100644 --- a/models/hr_expense_realization.py +++ b/models/hr_expense_realization.py @@ -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) } }