Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] hr_payroll_community: Fix Bug When Generate Payslip #101

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions hr_payroll_community/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ def get_worked_day_lines(self, contracts, date_from, date_to):

# compute leave days
leaves = {}
query = "SELECT id FROM hr_leave WHERE employee_id = '" + str(
self.employee_id.id) + "' " \
"AND request_date_from > '" + str(
self.date_from) + "' AND " \
"request_date_to < '" + str(self.date_to) + (
"' AND state = "
"'validate'")
query = """
SELECT id FROM hr_leave hl WHERE hl.employee_id = %s
AND hl.request_date_from >= '%s'
AND hl.request_date_to <= '%s'
AND hl.state = 'validate'
"""
query = query % (str(contract.employee_id.id), day_from.strftime('%Y-%m-%d'), day_to.strftime('%Y-%m-%d'))
self.env.cr.execute(query)
docs = self.env.cr.dictfetchall()
leave_ids = []
for rec in docs:
leave_ids.append(rec['id'])
hr_leaves = self.env['hr.leave'].browse(leave_ids)
work_hours = self.contract_id.resource_calendar_id.hours_per_day
work_hours = contract.resource_calendar_id.hours_per_day
if hr_leaves:
list_leave = []
for item in hr_leaves:
Expand All @@ -268,17 +268,14 @@ def get_worked_day_lines(self, contracts, date_from, date_to):
list_leave.append(data)
for rec in list_leave:
holiday = rec['time off']
current_leave_struct = leaves.setdefault(
holiday.holiday_status_id, {
'name': holiday.holiday_status_id.name or _(
'Global Leaves'),
'sequence': 5,
'code': holiday.holiday_status_id.code or 'GLOBAL',
'number_of_days': 0.0,
'number_of_hours': 0.0,
'contract_id': contract.id,
})

current_leave_struct = leaves.setdefault(holiday.holiday_status_id, {
'name': holiday.holiday_status_id.name or _('Global Leaves'),
'sequence': 5,
'code': holiday.holiday_status_id.code or 'GLOBAL',
'number_of_days': 0.0,
'number_of_hours': 0.0,
'contract_id': contract.id,
})
current_leave_struct['number_of_hours'] += rec['duration']
current_leave_struct[
'number_of_days'] += (rec['duration'] / work_hours)
Expand Down