Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
2497 Vizualizări

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!

Imagine profil
Abandonează
Cel mai bun răspuns

Hi Miguel Gozaine,

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

Thanks

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iul. 25
2504
2
iul. 25
7942
2
iul. 25
4382
2
iul. 25
4091
2
iun. 25
2690