From f0140a7f9721046746cb368fc5c90b39feb55955 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 6 Apr 2026 11:26:48 +0700 Subject: [PATCH] feat: trigger account move synchronization when expense deduction fields are updated --- models/account_payment.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/models/account_payment.py b/models/account_payment.py index 8008a9a..b2641e1 100644 --- a/models/account_payment.py +++ b/models/account_payment.py @@ -12,6 +12,11 @@ class AccountPayment(models.Model): if the payment is still in Draft state. This allows applying deductions or refining clearing accounts. """ + # Include deduction fields in the fields that trigger synchronization + if 'deduction_line_ids' in changed_fields or 'amount_substract' in changed_fields: + # If deductions change, we MUST sync to moves to ensure the deduction lines are created + pass + # If we have draft payments linked to a sheet, we want to skip the hr_expense UserError draft_payouts = self.filtered(lambda p: p.state == 'draft' and p.expense_sheet_id) if draft_payouts: @@ -35,6 +40,16 @@ class AccountPayment(models.Model): return super()._synchronize_to_moves(changed_fields) + def write(self, vals): + """ + Override write to manually trigger synchronization when deductions change. + """ + res = super().write(vals) + if 'deduction_line_ids' in vals or 'amount_substract' in vals: + # If deductions change, trigger sync to moves + self._synchronize_to_moves({'deduction_line_ids', 'amount_substract'}) + return res + def action_cancel(self): res = super().action_cancel() for payment in self: