make unit test hr base
This commit is contained in:
parent
255bf2ea5b
commit
87bab36cb2
|
|
@ -227,7 +227,7 @@ class employee_overtime_request(models.Model):
|
||||||
'debit': record.price_hour,
|
'debit': record.price_hour,
|
||||||
'account_id': account_debit_id.id,
|
'account_id': account_debit_id.id,
|
||||||
'partner_id': record.employee_id.user_id.partner_id.id,
|
'partner_id': record.employee_id.user_id.partner_id.id,
|
||||||
# 'analytic_account_id': analytic_account_id.id,
|
'analytic_account_id': analytic_account_id.id,
|
||||||
}
|
}
|
||||||
credit_line_vals = {
|
credit_line_vals = {
|
||||||
'name': record.employee_id.name,
|
'name': record.employee_id.name,
|
||||||
|
|
@ -242,6 +242,8 @@ class employee_overtime_request(models.Model):
|
||||||
'date': item.request_date,
|
'date': item.request_date,
|
||||||
'ref': record.employee_id.name,
|
'ref': record.employee_id.name,
|
||||||
'line_ids': [(0, 0, debit_line_vals), (0, 0, credit_line_vals)],
|
'line_ids': [(0, 0, debit_line_vals), (0, 0, credit_line_vals)],
|
||||||
|
'res_model': 'employee.overtime.request',
|
||||||
|
'res_id': self.id
|
||||||
|
|
||||||
})
|
})
|
||||||
record.account_id = account_debit_id.id
|
record.account_id = account_debit_id.id
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# from . import test_overtime_process
|
from . import test_overtime_process
|
||||||
# from . import test_employee_department_jobs
|
from . import test_employee_department_jobs
|
||||||
# from . import test_hr_clearance_form
|
from . import test_hr_clearance_form
|
||||||
from . import test_hr_personal_permission
|
from . import test_hr_personal_permission
|
||||||
|
|
@ -80,346 +80,246 @@ class HrSalaryRules(models.Model):
|
||||||
raise UserError(_("The Salary Rule is Not Deduction"))
|
raise UserError(_("The Salary Rule is Not Deduction"))
|
||||||
|
|
||||||
def _compute_rule(self, localdict):
|
def _compute_rule(self, localdict):
|
||||||
|
|
||||||
self.ensure_one()
|
|
||||||
payslip = localdict.get('payslip')
|
payslip = localdict.get('payslip')
|
||||||
contract = localdict.get('contract')
|
contract = localdict.get('contract')
|
||||||
current_date = fields.Date.today()
|
|
||||||
|
|
||||||
fix_amount_value = self.amount_fix if hasattr(self, 'amount_fix') else getattr(self, 'fixed_amount', 0.0)
|
|
||||||
|
|
||||||
|
|
||||||
def get_related_amount():
|
|
||||||
salary_type = getattr(self, 'salary_type', 'fixed')
|
|
||||||
if salary_type == 'related_levels' and contract.salary_level:
|
|
||||||
related = self.salary_amount_ids.filtered(lambda r: r.salary_scale_level.id == contract.salary_level.id)
|
|
||||||
return related.salary if related else 0.0
|
|
||||||
elif salary_type == 'related_groups' and contract.salary_group:
|
|
||||||
related = self.salary_amount_ids.filtered(lambda r: r.salary_scale_group.id == contract.salary_group.id)
|
|
||||||
return related.salary if related else 0.0
|
|
||||||
elif salary_type == 'related_degrees' and contract.salary_degree:
|
|
||||||
related = self.salary_amount_ids.filtered(
|
|
||||||
lambda r: r.salary_scale_degree.id == contract.salary_degree.id)
|
|
||||||
return related.salary if related else 0.0
|
|
||||||
return fix_amount_value
|
|
||||||
|
|
||||||
if self.amount_select == 'percentage':
|
if self.amount_select == 'percentage':
|
||||||
total_percent = 0.0
|
total_percent, total = 0, 0
|
||||||
related_rules = getattr(self, 'related_benefits_discounts', [])
|
if self.related_benefits_discounts:
|
||||||
|
for line in self.related_benefits_discounts:
|
||||||
if related_rules:
|
|
||||||
for line in related_rules:
|
|
||||||
calc_line = line._compute_rule(localdict)[0]
|
calc_line = line._compute_rule(localdict)[0]
|
||||||
line_in_advantages = False
|
|
||||||
advantages = contract.advantages if contract else []
|
|
||||||
|
|
||||||
if advantages:
|
if line.amount_select == 'fix':
|
||||||
con = next((adv for adv in advantages if adv.benefits_discounts.id == line.id), None)
|
if contract.advantages:
|
||||||
if con:
|
for con in contract.advantages:
|
||||||
line_in_advantages = True
|
if line.id == con.benefits_discounts.id:
|
||||||
is_valid_date = False
|
if payslip:
|
||||||
|
if con.date_from > payslip.date_from:
|
||||||
if payslip:
|
total_percent = calc_line
|
||||||
if con.date_from > payslip.date_from:
|
elif con.date_to is not None and str(
|
||||||
total_percent += calc_line
|
con.date_to) >= payslip.date_to or con.date_to is None:
|
||||||
continue
|
if con.type == 'exception':
|
||||||
elif (not con.date_to) or (con.date_to >= payslip.date_to):
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
is_valid_date = True
|
pass
|
||||||
else:
|
elif con.amount < calc_line:
|
||||||
if con.date_from <= current_date:
|
total = calc_line - con.amount
|
||||||
if (not con.date_to) or (con.date_to >= current_date):
|
elif con.type == 'customize':
|
||||||
is_valid_date = True
|
total = con.amount
|
||||||
|
total_percent += total
|
||||||
if is_valid_date:
|
|
||||||
total_to_add = 0.0
|
|
||||||
if con.type == 'exception':
|
|
||||||
if con.amount < calc_line:
|
|
||||||
total_to_add = calc_line - con.amount
|
|
||||||
else:
|
else:
|
||||||
total_to_add = 0.0
|
if str(con.date_from) < str(datetime.now().date()):
|
||||||
elif con.type == 'customize':
|
if con.date_to:
|
||||||
total_to_add = con.amount
|
if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
||||||
|
>= datetime.now().date().month or not con.date_to:
|
||||||
if line.amount_select == 'percentage':
|
if con.type == 'exception':
|
||||||
total_percent -= calc_line
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
total_percent += total_to_add
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount
|
||||||
|
total_percent += total
|
||||||
else:
|
else:
|
||||||
total_percent += total_to_add
|
total_percent = calc_line
|
||||||
else:
|
else:
|
||||||
total_percent += calc_line
|
total_percent += calc_line
|
||||||
|
|
||||||
if not line_in_advantages:
|
elif line.amount_select == 'percentage':
|
||||||
total_percent += calc_line
|
if contract.advantages:
|
||||||
|
for con in contract.advantages:
|
||||||
|
if line.id == con.benefits_discounts.id:
|
||||||
|
if payslip:
|
||||||
|
if con.date_from > payslip.date_from:
|
||||||
|
total_percent = calc_line
|
||||||
|
elif con.date_to is not None and str(
|
||||||
|
con.date_to) >= payslip.date_to or con.date_to is None:
|
||||||
|
if con.type == 'exception':
|
||||||
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount
|
||||||
|
total_percent -= calc_line
|
||||||
|
total_percent += total
|
||||||
|
else:
|
||||||
|
if str(con.date_from) < str(datetime.now().date()):
|
||||||
|
if con.date_to:
|
||||||
|
if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
||||||
|
>= datetime.now().date().month or not con.date_to:
|
||||||
|
if con.type == 'exception':
|
||||||
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount
|
||||||
|
total_percent -= calc_line
|
||||||
|
total_percent += total
|
||||||
|
else:
|
||||||
|
if con.type != 'exception':
|
||||||
|
total_percent += calc_line
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
total_percent += calc_line
|
||||||
|
|
||||||
|
else:
|
||||||
|
if contract.advantages:
|
||||||
|
for con in contract.advantages:
|
||||||
|
if line.id == con.benefits_discounts.id:
|
||||||
|
if payslip:
|
||||||
|
if con.date_from > payslip.date_from:
|
||||||
|
total_percent = calc_line
|
||||||
|
elif con.date_to is not None and con.date_to >= payslip.date_to or con.date_to is None:
|
||||||
|
if con.type == 'exception':
|
||||||
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount
|
||||||
|
total_percent = 0
|
||||||
|
total_percent += total
|
||||||
|
else:
|
||||||
|
if con.date_from < (datetime.now().date()):
|
||||||
|
if con.date_to:
|
||||||
|
if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
||||||
|
>= datetime.now().date().month or not con.date_to:
|
||||||
|
if con.type == 'exception':
|
||||||
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount
|
||||||
|
total_percent = 0
|
||||||
|
total_percent += total
|
||||||
|
else:
|
||||||
|
if datetime.strptime(str(con.date_from),
|
||||||
|
"%Y-%m-%d").date().month >= datetime.now().date().month:
|
||||||
|
if con.type == 'exception':
|
||||||
|
if con.amount > calc_line or con.amount == calc_line:
|
||||||
|
pass
|
||||||
|
elif con.amount < calc_line:
|
||||||
|
total = calc_line - con.amount
|
||||||
|
elif con.type == 'customize':
|
||||||
|
total = con.amount + calc_line
|
||||||
|
total_percent = 0
|
||||||
|
total_percent += total
|
||||||
|
|
||||||
|
else:
|
||||||
|
if not total_percent:
|
||||||
|
total_percent = calc_line
|
||||||
|
else:
|
||||||
|
total_percent += calc_line
|
||||||
if total_percent:
|
if total_percent:
|
||||||
try:
|
if self.salary_type == 'fixed':
|
||||||
qty = float(safe_eval(self.quantity, localdict))
|
try:
|
||||||
rate = self.amount_percentage
|
return float(total_percent * self.amount_percentage / 100), \
|
||||||
return float(total_percent * self.amount_percentage / 100), qty, rate
|
float(safe_eval(self.quantity, localdict)), self.amount_percentage
|
||||||
except Exception as e:
|
except:
|
||||||
raise UserError(_('Error calculating percentage rule %s: %s') % (self.name, e))
|
raise UserError(
|
||||||
|
_('Wrong percentage base or quantity defined for salary rule %s (%s).') % (
|
||||||
|
self.name, self.code))
|
||||||
|
elif self.salary_type == 'related_levels':
|
||||||
|
levels_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_level.id == contract.salary_level.id)
|
||||||
|
if levels_ids:
|
||||||
|
for l in levels_ids:
|
||||||
|
try:
|
||||||
|
return float(l.salary * total_percent / 100), float(
|
||||||
|
safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (
|
||||||
|
self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
|
elif self.salary_type == 'related_groups':
|
||||||
|
groups_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_group.id == contract.salary_group.id)
|
||||||
|
if groups_ids:
|
||||||
|
for g in groups_ids:
|
||||||
|
try:
|
||||||
|
return float(g.salary * total_percent / 100), float(
|
||||||
|
safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (
|
||||||
|
self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
|
elif self.salary_type == 'related_degrees':
|
||||||
|
degrees_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_degree.id == contract.salary_degree.id)
|
||||||
|
if degrees_ids:
|
||||||
|
for d in degrees_ids:
|
||||||
|
try:
|
||||||
|
return float(d.salary * total_percent / 100), float(
|
||||||
|
safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (
|
||||||
|
self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
else:
|
else:
|
||||||
return 0.0, 0.0, 0.0
|
try:
|
||||||
|
return 0, 0, 0
|
||||||
|
except:
|
||||||
|
raise UserError(_('There is no total for rule : %s') % self.name)
|
||||||
|
|
||||||
elif self.amount_select == 'fix':
|
elif self.amount_select == 'fix':
|
||||||
try:
|
if self.salary_type == 'fixed':
|
||||||
qty = float(safe_eval(self.quantity, localdict))
|
try:
|
||||||
amount = get_related_amount()
|
return self.fixed_amount, float(safe_eval(self.quantity, localdict)), 100.0
|
||||||
return amount, qty, 100.0
|
except:
|
||||||
except Exception as e:
|
raise UserError(_('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
||||||
raise UserError(_('Error computing fix rule %s: %s') % (self.name, e))
|
elif self.salary_type == 'related_levels':
|
||||||
|
levels_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_level.id == contract.salary_level.id)
|
||||||
|
if levels_ids:
|
||||||
|
for l in levels_ids:
|
||||||
|
try:
|
||||||
|
return l.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
|
elif self.salary_type == 'related_groups':
|
||||||
|
groups_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_group.id == contract.salary_group.id)
|
||||||
|
if groups_ids:
|
||||||
|
for g in groups_ids:
|
||||||
|
try:
|
||||||
|
return g.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
|
elif self.salary_type == 'related_degrees':
|
||||||
|
degrees_ids = self.salary_amount_ids.filtered(
|
||||||
|
lambda item: item.salary_scale_degree.id == contract.salary_degree.id)
|
||||||
|
if degrees_ids:
|
||||||
|
for d in degrees_ids:
|
||||||
|
try:
|
||||||
|
return d.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
||||||
|
except:
|
||||||
|
raise UserError(
|
||||||
|
_('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
||||||
|
else:
|
||||||
|
return 0, 0, 0
|
||||||
|
else:
|
||||||
|
raise UserError(_('Error, Select Salary type to calculate rule'))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
safe_eval(self.amount_python_compute, localdict, mode='exec', nocopy=True)
|
safe_eval(self.amount_python_compute, localdict, mode='exec', nocopy=True)
|
||||||
return float(localdict.get('result', 0.0)), \
|
return float(localdict['result']), 'result_qty' in localdict and localdict[
|
||||||
localdict.get('result_qty', 1.0), \
|
'result_qty'] or 1.0, 'result_rate' in localdict and localdict['result_rate'] or 100.0
|
||||||
localdict.get('result_rate', 100.0)
|
except:
|
||||||
except Exception as e:
|
raise UserError(_('Wrong python code defined for salary rule %s (%s).') % (self.name, self.code))
|
||||||
raise UserError(_('Error computing python rule %s: %s') % (self.name, e))
|
|
||||||
# Override function compute rule in hr salary rule
|
|
||||||
|
|
||||||
# def _compute_rule(self, localdict):
|
|
||||||
# payslip = localdict.get('payslip')
|
|
||||||
# contract = localdict.get('contract')
|
|
||||||
# if self.amount_select == 'percentage':
|
|
||||||
# total_percent, total = 0, 0
|
|
||||||
# if self.related_benefits_discounts:
|
|
||||||
# for line in self.related_benefits_discounts:
|
|
||||||
# calc_line = line._compute_rule(localdict)[0]
|
|
||||||
#
|
|
||||||
# if line.amount_select == 'fix':
|
|
||||||
# if contract.advantages:
|
|
||||||
# for con in contract.advantages:
|
|
||||||
# if line.id == con.benefits_discounts.id:
|
|
||||||
# if payslip:
|
|
||||||
# if con.date_from > payslip.date_from:
|
|
||||||
# total_percent = calc_line
|
|
||||||
# elif con.date_to is not None and str(
|
|
||||||
# con.date_to) >= payslip.date_to or con.date_to is None:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# if str(con.date_from) < str(datetime.now().date()):
|
|
||||||
# if con.date_to:
|
|
||||||
# if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
|
||||||
# >= datetime.now().date().month or not con.date_to:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# total_percent = calc_line
|
|
||||||
# else:
|
|
||||||
# total_percent += calc_line
|
|
||||||
#
|
|
||||||
# elif line.amount_select == 'percentage':
|
|
||||||
# if contract.advantages:
|
|
||||||
# for con in contract.advantages:
|
|
||||||
# if line.id == con.benefits_discounts.id:
|
|
||||||
# if payslip:
|
|
||||||
# if con.date_from > payslip.date_from:
|
|
||||||
# total_percent = calc_line
|
|
||||||
# elif con.date_to is not None and str(
|
|
||||||
# con.date_to) >= payslip.date_to or con.date_to is None:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent -= calc_line
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# if str(con.date_from) < str(datetime.now().date()):
|
|
||||||
# if con.date_to:
|
|
||||||
# if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
|
||||||
# >= datetime.now().date().month or not con.date_to:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent -= calc_line
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# if con.type != 'exception':
|
|
||||||
# total_percent += calc_line
|
|
||||||
# break
|
|
||||||
# else:
|
|
||||||
# total_percent += calc_line
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
# if contract.advantages:
|
|
||||||
# for con in contract.advantages:
|
|
||||||
# if line.id == con.benefits_discounts.id:
|
|
||||||
# if payslip:
|
|
||||||
# if con.date_from > payslip.date_from:
|
|
||||||
# total_percent = calc_line
|
|
||||||
# elif con.date_to is not None and con.date_to >= payslip.date_to or con.date_to is None:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent = 0
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# if con.date_from < (datetime.now().date()):
|
|
||||||
# if con.date_to:
|
|
||||||
# if datetime.strptime(str(con.date_to), "%Y-%m-%d").date().month \
|
|
||||||
# >= datetime.now().date().month or not con.date_to:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount
|
|
||||||
# total_percent = 0
|
|
||||||
# total_percent += total
|
|
||||||
# else:
|
|
||||||
# if datetime.strptime(str(con.date_from),
|
|
||||||
# "%Y-%m-%d").date().month >= datetime.now().date().month:
|
|
||||||
# if con.type == 'exception':
|
|
||||||
# if con.amount > calc_line or con.amount == calc_line:
|
|
||||||
# pass
|
|
||||||
# elif con.amount < calc_line:
|
|
||||||
# total = calc_line - con.amount
|
|
||||||
# elif con.type == 'customize':
|
|
||||||
# total = con.amount + calc_line
|
|
||||||
# total_percent = 0
|
|
||||||
# total_percent += total
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
# if not total_percent:
|
|
||||||
# total_percent = calc_line
|
|
||||||
# else:
|
|
||||||
# total_percent += calc_line
|
|
||||||
# if total_percent:
|
|
||||||
# if self.salary_type == 'fixed':
|
|
||||||
# try:
|
|
||||||
# return float(total_percent * self.amount_percentage / 100), \
|
|
||||||
# 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))
|
|
||||||
# elif self.salary_type == 'related_levels':
|
|
||||||
# levels_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_level.id == contract.salary_level.id)
|
|
||||||
# if levels_ids:
|
|
||||||
# for l in levels_ids:
|
|
||||||
# try:
|
|
||||||
# return float(l.salary * total_percent / 100), float(
|
|
||||||
# safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (
|
|
||||||
# self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# elif self.salary_type == 'related_groups':
|
|
||||||
# groups_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_group.id == contract.salary_group.id)
|
|
||||||
# if groups_ids:
|
|
||||||
# for g in groups_ids:
|
|
||||||
# try:
|
|
||||||
# return float(g.salary * total_percent / 100), float(
|
|
||||||
# safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (
|
|
||||||
# self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# elif self.salary_type == 'related_degrees':
|
|
||||||
# degrees_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_degree.id == contract.salary_degree.id)
|
|
||||||
# if degrees_ids:
|
|
||||||
# for d in degrees_ids:
|
|
||||||
# try:
|
|
||||||
# return float(d.salary * total_percent / 100), float(
|
|
||||||
# safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (
|
|
||||||
# self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# else:
|
|
||||||
# try:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# except:
|
|
||||||
# raise UserError(_('There is no total for rule : %s') % self.name)
|
|
||||||
#
|
|
||||||
# elif self.amount_select == 'fix':
|
|
||||||
# if self.salary_type == 'fixed':
|
|
||||||
# try:
|
|
||||||
# return self.fixed_amount, 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.salary_type == 'related_levels':
|
|
||||||
# levels_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_level.id == contract.salary_level.id)
|
|
||||||
# if levels_ids:
|
|
||||||
# for l in levels_ids:
|
|
||||||
# try:
|
|
||||||
# return l.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# elif self.salary_type == 'related_groups':
|
|
||||||
# groups_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_group.id == contract.salary_group.id)
|
|
||||||
# if groups_ids:
|
|
||||||
# for g in groups_ids:
|
|
||||||
# try:
|
|
||||||
# return g.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# elif self.salary_type == 'related_degrees':
|
|
||||||
# degrees_ids = self.salary_amount_ids.filtered(
|
|
||||||
# lambda item: item.salary_scale_degree.id == contract.salary_degree.id)
|
|
||||||
# if degrees_ids:
|
|
||||||
# for d in degrees_ids:
|
|
||||||
# try:
|
|
||||||
# return d.salary, float(safe_eval(self.quantity, localdict)), 100.0
|
|
||||||
# except:
|
|
||||||
# raise UserError(
|
|
||||||
# _('Wrong quantity defined for salary rule %s (%s).') % (self.name, self.code))
|
|
||||||
# else:
|
|
||||||
# return 0, 0, 0
|
|
||||||
# else:
|
|
||||||
# raise UserError(_('Error, Select Salary type to calculate rule'))
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# except:
|
|
||||||
# raise UserError(_('Wrong python code defined for salary rule %s (%s).') % (self.name, self.code))
|
|
||||||
|
|
||||||
|
|
||||||
class SalaryConfig(models.Model):
|
class SalaryConfig(models.Model):
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class TestSalaryRuleComputation(TransactionCase):
|
||||||
'name': 'Basic Salary', 'code': 'BASIC',
|
'name': 'Basic Salary', 'code': 'BASIC',
|
||||||
'category_id': self.category_basic.id,
|
'category_id': self.category_basic.id,
|
||||||
'amount_select': 'fix',
|
'amount_select': 'fix',
|
||||||
'amount_fix': 1000.0,
|
'fixed_amount': 1000,
|
||||||
'sequence': 1,
|
'sequence': 1,
|
||||||
'salary_type': 'fixed',
|
'salary_type': 'fixed',
|
||||||
})
|
})
|
||||||
|
|
@ -37,7 +37,7 @@ class TestSalaryRuleComputation(TransactionCase):
|
||||||
'name': 'Housing Allowance', 'code': 'HOUSING',
|
'name': 'Housing Allowance', 'code': 'HOUSING',
|
||||||
'category_id': self.category_allowance.id,
|
'category_id': self.category_allowance.id,
|
||||||
'amount_select': 'fix',
|
'amount_select': 'fix',
|
||||||
'amount_fix': 500.0,
|
'fixed_amount': 500,
|
||||||
'sequence': 2,
|
'sequence': 2,
|
||||||
'salary_type': 'fixed',
|
'salary_type': 'fixed',
|
||||||
})
|
})
|
||||||
|
|
@ -85,7 +85,7 @@ class TestSalaryRuleComputation(TransactionCase):
|
||||||
'benefits_discounts': self.rule_basic.id,
|
'benefits_discounts': self.rule_basic.id,
|
||||||
'type': 'exception',
|
'type': 'exception',
|
||||||
|
|
||||||
'amount': 200.0,
|
'amount': 200,
|
||||||
'date_from': yesterday,
|
'date_from': yesterday,
|
||||||
'date_to': today + timedelta(days=30),
|
'date_to': today + timedelta(days=30),
|
||||||
})
|
})
|
||||||
|
|
@ -114,7 +114,7 @@ class TestSalaryRuleComputation(TransactionCase):
|
||||||
'employee_id': self.employee.id,
|
'employee_id': self.employee.id,
|
||||||
'benefits_discounts': self.rule_basic.id,
|
'benefits_discounts': self.rule_basic.id,
|
||||||
'type': 'exception',
|
'type': 'exception',
|
||||||
'amount': 200.0,
|
'amount': 200,
|
||||||
'date_from': old_date,
|
'date_from': old_date,
|
||||||
'date_to': old_date + timedelta(days=30),
|
'date_to': old_date + timedelta(days=30),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue