[FIX] hr_payroll: Fix localdict ambiguity on rule computation
Purpose ======= On a payslip rule computation you can return 3 parameters: - result_qty - result_rate - result From this, we compute the total amount as following: tot_rule = amount * qty * rate / 100.0 If we set parameters result_qty=0 or result_rate=0 to force the tot_rule to be equal to 0, then their values are set to the default one, which is ambiguous. So result_qty = 0 result_rate = 0 Become qty=1 amount=100 We can't fix this in a stable release as this could imply unwanted behavior changes for customers, and also quite difficult to spot. closes odoo/odoo#29206
This commit is contained in:
committed by
Yannick Tivisse
parent
f0d5a5ba13
commit
9a95781439
@@ -211,7 +211,7 @@ class HrSalaryRule(models.Model):
|
||||
else:
|
||||
try:
|
||||
safe_eval(self.amount_python_compute, localdict, mode='exec', nocopy=True)
|
||||
return float(localdict['result']), 'result_qty' in localdict and localdict['result_qty'] or 1.0, 'result_rate' in localdict and localdict['result_rate'] or 100.0
|
||||
return float(localdict['result']), localdict.get('result_qty', 1.0), localdict.get('result_rate', 100.0)
|
||||
except Exception as e:
|
||||
raise UserError(_('Wrong python code defined for salary rule %s (%s).\nError: %s') % (self.name, self.code, e))
|
||||
|
||||
@@ -234,7 +234,7 @@ class HrSalaryRule(models.Model):
|
||||
else: # python code
|
||||
try:
|
||||
safe_eval(self.condition_python, localdict, mode='exec', nocopy=True)
|
||||
return 'result' in localdict and localdict['result'] or False
|
||||
return localdict.get('result', False)
|
||||
except:
|
||||
raise UserError(_('Wrong python condition defined for salary rule %s (%s).') % (self.name, self.code))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user