Skip to Content
Menu
This question has been flagged
2 Replies
1532 Views

When I try to execute multiple slips for the same structure, If any of the rules uses the employee variable it raises an error saying that the variable is a recordset of more than one value. (The variable is holding the value of all the employees which payslip is being calculated).

Does someone know if this is a bug or am I doing something wrong?

This is the code of the rule:

result = result_rules.DDVM['total'] * (employee.holidays_accrued / 30)

The holidays_accrued is a field I added to the hr.employee model.

This is the error:

Wrong python code defined for salary rule Pago por Disfrute Vacacional (PDDVM). Error: : "Expected singleton: hr.employee(2, 3, 4, 5)" while evaluating "\nresult = result_rules.DDVM['total'] * (employee.holidays_accrued / 30)\n 

I also checked for the code on the hr_payroll module and both in the compute_rule and in the get_local_dict it is written so it works with each rule. (Which makes me wonder were it's getting the recordset value for the employee that is showing to me in the error).

Any help would be appreciated, thanks!

Avatar
Discard
Best Answer

Hi Miguel Gozaine,

Can you please share the detail of the "holiday_accrued" field and its type for analysing this issue.

Thanks

Avatar
Discard
Author Best Answer

Hello Malay. This is the definition of the field:

holidays_accrued = fields.Float(compute="_compute_holidays_accrued")

And this is the compute:

@api.depends("contract_id.salary_type")     def _compute_holidays_accrued(self):         for employee in self:             salary_type = employee.contract_id.salary_type             employee.holidays_accrued = 0             if type(employee.id) == int:                 employee_salary_payments = employee.get_all_payroll_moves()                 if salary_type and employee_salary_payments:                     if salary_type == "fixed":                         employee.holidays_accrued = employee_salary_payments[-1]["total_accrued"]                     else:                         last_month_accrued = employee_salary_payments[-1]["total_accrued"]                         second_to_last_month_accrued = (                             employee_salary_payments[-2]["total_accrued"]                             if len(employee_salary_payments) > 1                             else 0                         )                         third_to_last_month_accrued = (                             employee_salary_payments[-3]["total_accrued"]                             if len(employee_salary_payments) > 2                             else 0                         )                          employee.holidays_accrued = (                             last_month_accrued                             + second_to_last_month_accrued                             + third_to_last_month_accrued                         ) / 3


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1487
1
Nov 24
1196
2
Sep 24
1047
1
Aug 24
2456
3
Aug 24
2687