[FIX] hr_payroll: nicer error message for some bad rule definitions
For example avoids a crash with: TypeError: can't multiply sequence by non-int of type 'float' when setting the quantity field of a salary rule to `1,0` instead of `1.0`. Fixes #5154 Closes #5155
This commit is contained in:
parent
0b5271e90d
commit
34d4508535
|
@ -868,18 +868,20 @@ result = rules.NET > categories.NET * 0.10''',
|
|||
rule = self.browse(cr, uid, rule_id, context=context)
|
||||
if rule.amount_select == 'fix':
|
||||
try:
|
||||
return rule.amount_fix, eval(rule.quantity, localdict), 100.0
|
||||
return rule.amount_fix, float(eval(rule.quantity, localdict)), 100.0
|
||||
except:
|
||||
raise osv.except_osv(_('Error!'), _('Wrong quantity defined for salary rule %s (%s).')% (rule.name, rule.code))
|
||||
elif rule.amount_select == 'percentage':
|
||||
try:
|
||||
return eval(rule.amount_percentage_base, localdict), eval(rule.quantity, localdict), rule.amount_percentage
|
||||
return (float(eval(rule.amount_percentage_base, localdict)),
|
||||
float(eval(rule.quantity, localdict)),
|
||||
rule.amount_percentage)
|
||||
except:
|
||||
raise osv.except_osv(_('Error!'), _('Wrong percentage base or quantity defined for salary rule %s (%s).')% (rule.name, rule.code))
|
||||
else:
|
||||
try:
|
||||
eval(rule.amount_python_compute, localdict, mode='exec', nocopy=True)
|
||||
return 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']), 'result_qty' in localdict and localdict['result_qty'] or 1.0, 'result_rate' in localdict and localdict['result_rate'] or 100.0
|
||||
except:
|
||||
raise osv.except_osv(_('Error!'), _('Wrong python code defined for salary rule %s (%s).')% (rule.name, rule.code))
|
||||
|
||||
|
|
Loading…
Reference in New Issue