Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2492 Widoki

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!

Awatar
Odrzuć
Najlepsza odpowiedź

Hi Miguel Gozaine,

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

Thanks

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lip 25
2499
2
lip 25
7939
2
lip 25
4374
2
lip 25
4087
2
cze 25
2688