From 9a9578143913ab4cbc7b57b9eee50ca49a9121e1 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 3 Dec 2018 01:45:58 +0000 Subject: [PATCH] [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 --- addons/hr_payroll/models/hr_salary_rule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_payroll/models/hr_salary_rule.py b/addons/hr_payroll/models/hr_salary_rule.py index 9a6ccecf90c..65d6562be4e 100644 --- a/addons/hr_payroll/models/hr_salary_rule.py +++ b/addons/hr_payroll/models/hr_salary_rule.py @@ -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))