Skip to Content
Menú
This question has been flagged
2 Respostes
2385 Vistes

Hello Odooverse! 

I want to use Payroll to start registering my company's payroll. Nevertheless, some hourly workers register their worked time in the Timesheets App, and Payroll does not consider Timesheets as a work entry source. Is there a way to do it? I am using this salary structure:


As you observe is not too complex:

However, I want it to be calculated from the timesheet records instead of calculating the worked time based on the work entry sources (attendance, planning, or working schedule).

Avatar
Descartar
Autor Best Answer

Hello Emilio! 

The answer to this question could be as detailed as the business case, depending on case by case. So, to achieve this, you need to create a new salary rule or modify an existing one. 

The computation should be based on Python Code: 

hours = 0   

Line explanation: setting the variable hours to 0.


lines = payslip.env[ 'account.analytic.line' ].search( [ ('employee_id' , '=', payslip.employee_id.id), ('validated_status', '=', 'validate'), ('date', '>=', payslip.date_from), ('date', '


Line explanation:  This code retrieves all the analytic lines (account.analytic.line) for the employee on the payslip that has been validated and is within the current payroll period.


  • payslip.env['account.analytic.line']:  This accesses the account.analytic.line model, which refers to the analytic lines or timesheet records in Odoo.
  • .search: The search() function looks for records that meet the criteria specified in the list of tuples (search criteria).
  • ('employee_id', '=', payslip.employee_id.id): Filters the analytic lines to get only those associated with the specific employee that appears on the payslip (payslip.employee_id.id).
  • ('validated_status', '=', 'validate'): Filters the analytic lines to get only those that have been validated, meaning they have been approved or confirmed.
  • ('date', '>=', payslip.date_from): Filters the analytic lines to get only those that were recorded starting from the payslip start date (payslip.date_from).
  • ('date', ': Filters the analytic lines to get only those that were recorded up to the payslip end date (payslip.date_to).


for line in lines:

    hours += line.unit_amount

result_qty = hours

result = contract.hourly_wage

Explanation: The for loop iterates over each analytic line stored in "Lines," so each "Line" represents a record of time worked by the employee. Then, the code sums all the hours and inputs the total hours in result_qty, which will result in the hourly wage in the employee contract.

Disclaimer: the code may depend on what or how you want to impact your payroll calculations.

Before applying my solution, please think about other important factors that may be relevant to your payroll calculation: 

  • As you may have seen, this does not generate work entries such as overtime. When someone works more than the agreed-upon amount, you may need to create another salary rule to calculate that. 
  • And if Time Off generates Timesheets, consider this when applying this solution.

Disclaimer: This is only a general solution to the business case. Additional specifications are needed to cover it in more detail, which may apply depending on the specific case, as I mentioned earlier.

Avatar
Descartar

On Earth 76483 I already answered this, but yours is better.

Best Answer

Actual salary rule code, working on odoo 17 (based on upper comment with slight edits)

hours = 0   

lines = payslip.env['account.analytic.line'].search([

    ('employee_id', '=', payslip.employee_id.id),

    ('validated_status', '=', 'validate'),

    ('date', '>=', payslip.date_from),

    ('date', '<=', payslip.date_to)  # Corrected the condition here

])

for line in lines:

    hours += line.unit_amount

result_qty = hours

result = contract.hourly_wage

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de febr. 25
2476
2
d’oct. 24
1912
1
d’abr. 24
2531
1
d’abr. 24
1597
2
d’abr. 24
1463