Skip to content

Commit c85d71f

Browse files
[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.
1 parent 0a39da9 commit c85d71f

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/util/hr_payroll.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
_logger = logging.getLogger(__name__)
88

99

10+
def _neutralize_rule(cr, xmlid):
11+
rid = ref(cr, xmlid)
12+
if rid is None:
13+
return
14+
if not delete_unused(cr, xmlid, deactivate=True):
15+
# if the rule hasn't been deleted
16+
_logger.info("Salary rule %r has been neutralized and deactivated", xmlid)
17+
cr.execute(
18+
"""
19+
UPDATE hr_salary_rule
20+
SET condition_select = 'python',
21+
condition_python = 'result = False',
22+
amount_select = 'fix',
23+
amount_fix = 0.0
24+
WHERE id = %s
25+
""",
26+
[rid],
27+
)
28+
29+
1030
def _remove_salary_rule(cr, xmlid):
1131
rid = ref(cr, xmlid)
1232
cr.execute(
@@ -40,12 +60,12 @@ def _remove_salary_rule(cr, xmlid):
4060
xmlid,
4161
)
4262
remove_field(cr, "hr.payroll.report", fname)
43-
delete_unused(cr, xmlid, deactivate=True)
63+
_neutralize_rule(cr, xmlid)
4464

4565

4666
if not version_between("16.0", "saas~18.4"):
4767

4868
def remove_salary_rule(cr, xmlid):
49-
delete_unused(cr, xmlid, deactivate=True)
69+
_neutralize_rule(cr, xmlid)
5070
else:
5171
remove_salary_rule = _remove_salary_rule

0 commit comments

Comments
 (0)