Files
suite/l10n_us_hr_payroll/models/hr_salary_rule.py
Jared Kipe 3ec63381b2 IMP l10n_us_hr_payroll Refactor to simply tax exempt deductions.
Additionally, it is possible (from testing on other databases) to have contracts without an employee, resulting in a failed migration.  Avoid this by filtering for employees on the contract and log if something (maybe a record rule) prevents you from seeing it instead of failing the migration itself.
2020-01-10 06:34:15 -08:00

36 lines
1.6 KiB
Python

from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
from odoo.exceptions import UserError
class HRSalaryRule(models.Model):
_inherit = 'hr.salary.rule'
@api.multi
def _compute_rule(self, localdict):
"""
:param localdict: dictionary containing the environement in which to compute the rule
:return: returns a tuple build as the base/amount computed, the quantity and the rate
:rtype: (float, float, float)
"""
self.ensure_one()
if self.amount_select == 'fix':
try:
return self.amount_fix, float(safe_eval(self.quantity, localdict)), 100.0
except:
raise UserError(_('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
elif self.amount_select == 'percentage':
try:
return (float(safe_eval(self.amount_percentage_base, localdict)),
float(safe_eval(self.quantity, localdict)),
self.amount_percentage)
except:
raise UserError(_('Wrong percentage base or quantity defined for salary rule %s (%s).') % (self.name, self.code))
else:
try:
safe_eval(self.amount_python_compute, localdict, mode='exec', nocopy=True)
# Hibou Fix for setting 0.0 for result rate or result qty
return float(localdict['result']), localdict.get('result_qty', 1.0), localdict.get('result_rate', 100.0)
except:
raise UserError(_('Wrong python code defined for salary rule %s (%s).') % (self.name, self.code))