Skip to content

Commit

Permalink
[FIX] Bug Fixed 'hr_payroll_community'
Browse files Browse the repository at this point in the history
  • Loading branch information
AjmalCybro committed Aug 3, 2023
1 parent 3ca067b commit 51eaa37
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion hr_payroll_community/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
'name': 'Odoo16 Payroll',
'category': 'Generic Modules/Human Resources',
'version': '16.0.1.0.1',
'version': '16.0.1.0.2',
'author': 'Odoo SA,Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
Expand Down
64 changes: 42 additions & 22 deletions hr_payroll_community/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,37 @@ def get_worked_day_lines(self, contracts, date_from, date_to):

# compute leave days
leaves = {}
calendar = contract.resource_calendar_id
tz = timezone(calendar.tz)
day_leave_intervals = contract.employee_id.list_leaves(day_from,
day_to,
calendar=contract.resource_calendar_id)

for day, hours, leave in day_leave_intervals:
for each in leave:
holiday = each.holiday_id
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'")
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
if hr_leaves:
list_leave = []
for item in hr_leaves:
duration = item.duration_display
if duration.find('days') != -1:
hours = float(item.duration_display.replace("days",
"")) * work_hours
else:
hours = float(
item.duration_display.replace("hours", ""))
data = {
'duration': hours,
'time off': item
}
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 _(
Expand All @@ -256,15 +278,10 @@ def get_worked_day_lines(self, contracts, date_from, date_to):
'number_of_hours': 0.0,
'contract_id': contract.id,
})
current_leave_struct['number_of_hours'] += hours
work_hours = calendar.get_work_hours_count(
tz.localize(datetime.combine(day, time.min)),
tz.localize(datetime.combine(day, time.max)),
compute_leaves=False,
)
if work_hours:
current_leave_struct[
'number_of_days'] += hours / work_hours

current_leave_struct['number_of_hours'] += rec['duration']
current_leave_struct[
'number_of_days'] += (rec['duration'] / work_hours)

# # compute worked days
work_data = contract.employee_id.get_work_days_data(day_from,
Expand Down Expand Up @@ -343,7 +360,8 @@ def sum(self, code, from_date, to_date=None):
WHERE hp.employee_id = %s AND hp.state = 'done'
AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s""",
(
self.employee_id, from_date, to_date, code))
self.employee_id, from_date, to_date,
code))
return self.env.cr.fetchone()[0] or 0.0

class WorkedDays(BrowsableObject):
Expand All @@ -358,7 +376,8 @@ def _sum(self, code, from_date, to_date=None):
WHERE hp.employee_id = %s AND hp.state = 'done'
AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s""",
(
self.employee_id, from_date, to_date, code))
self.employee_id, from_date, to_date,
code))
return self.env.cr.fetchone()

def sum(self, code, from_date, to_date=None):
Expand All @@ -380,7 +399,8 @@ def sum(self, code, from_date, to_date=None):
WHERE hp.employee_id = %s AND hp.state = 'done'
AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pl.slip_id AND pl.code = %s""",
(
self.employee_id, from_date, to_date, code))
self.employee_id, from_date, to_date,
code))
res = self.env.cr.fetchone()
return res and res[0] or 0.0

Expand Down Expand Up @@ -547,7 +567,6 @@ def onchange_employee_id(self, date_from, date_to, employee_id=False,
@api.onchange('employee_id', 'date_from', 'date_to')
def onchange_employee(self):


if (not self.employee_id) or (not self.date_from) or (not self.date_to):
return

Expand All @@ -573,6 +592,7 @@ def onchange_employee(self):
self.contract_id = self.env['hr.contract'].browse(contract_ids[0])

if not self.contract_id.struct_id:
self.worked_days_line_ids = False
return
self.struct_id = self.contract_id.struct_id
if self.contract_id:
Expand Down

0 comments on commit 51eaa37

Please sign in to comment.