From a91e13991e51e528c4cb128f03f3fd5576d5acd6 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 6 Apr 2026 11:58:28 +0700 Subject: [PATCH] feat: force synchronization of expense deductions before posting account payments --- models/account_payment.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/models/account_payment.py b/models/account_payment.py index 2046263..ae7a219 100644 --- a/models/account_payment.py +++ b/models/account_payment.py @@ -6,6 +6,17 @@ class AccountPayment(models.Model): realization_id = fields.Many2one('hr.expense.realization', string='Originating Realization', readonly=True) + def action_post(self): + """ + Force synchronization before posting to ensure deductions are included, + even if the payment was previously 'Reset to Draft' without edits. + """ + for payment in self: + if payment.state == 'draft' and payment.expense_sheet_id: + # Force sync by pretending amount changed to refresh the lines + payment._synchronize_to_moves({'amount', 'deduction_line_ids', 'amount_substract'}) + return super().action_post() + def _synchronize_to_moves(self, changed_fields): """ Bypass standard Odoo restriction for payments linked to expense reports