From c85d71f0c4fdf6cfc9670c1885c230fc660d8fbf Mon Sep 17 00:00:00 2001 From: romc-odoo Date: Fri, 3 Apr 2026 09:40:40 +0200 Subject: [PATCH] [IMP] util.hr_payroll: ensure salary rule neutralization on removal When a salary rule is explicitely removed, it should never be used again or it will break the computation of future payslips. To ensure that, the salary rule is set to always compute a result of 0. Archiving the rule *should* be sufficient, this is only an extra layer of safety for payroll compliance. --- src/util/hr_payroll.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/util/hr_payroll.py b/src/util/hr_payroll.py index 0a811401f..4e5ec53de 100644 --- a/src/util/hr_payroll.py +++ b/src/util/hr_payroll.py @@ -7,6 +7,26 @@ _logger = logging.getLogger(__name__) +def _neutralize_rule(cr, xmlid): + rid = ref(cr, xmlid) + if rid is None: + return + if not delete_unused(cr, xmlid, deactivate=True): + # if the rule hasn't been deleted + _logger.info("Salary rule %r has been neutralized and deactivated", xmlid) + cr.execute( + """ + UPDATE hr_salary_rule + SET condition_select = 'python', + condition_python = 'result = False', + amount_select = 'fix', + amount_fix = 0.0 + WHERE id = %s + """, + [rid], + ) + + def _remove_salary_rule(cr, xmlid): rid = ref(cr, xmlid) cr.execute( @@ -40,12 +60,12 @@ def _remove_salary_rule(cr, xmlid): xmlid, ) remove_field(cr, "hr.payroll.report", fname) - delete_unused(cr, xmlid, deactivate=True) + _neutralize_rule(cr, xmlid) if not version_between("16.0", "saas~18.4"): def remove_salary_rule(cr, xmlid): - delete_unused(cr, xmlid, deactivate=True) + _neutralize_rule(cr, xmlid) else: remove_salary_rule = _remove_salary_rule