Skip to content

Commit

Permalink
Sep 20 [FIX] : Bug Fixed 'hr_payroll_community'
Browse files Browse the repository at this point in the history
  • Loading branch information
AjmalCybro committed Sep 20, 2023
1 parent 9196cf7 commit ad3df8d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 51 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.2',
'version': '16.0.1.0.3',
'author': 'Odoo SA,Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
Expand Down
104 changes: 67 additions & 37 deletions hr_payroll_community/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import date, datetime, time
from datetime import timedelta
from dateutil.relativedelta import relativedelta
from matplotlib.dates import seconds
from pytz import timezone
from pytz import utc

Expand Down Expand Up @@ -237,37 +238,25 @@ 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'")
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']

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)
multi_leaves = []
for day, hours, leave in day_leave_intervals:
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 len(leave) > 1:
for each in leave:
if each.holiday_id:
multi_leaves.append(each.holiday_id)
else:
holiday = leave.holiday_id
current_leave_struct = leaves.setdefault(
holiday.holiday_status_id, {
'name': holiday.holiday_status_id.name or _(
Expand All @@ -278,12 +267,12 @@ 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
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
# compute worked days
work_data = contract.employee_id.get_work_days_data(day_from,
day_to,
calendar=contract.resource_calendar_id)
Expand All @@ -295,8 +284,49 @@ def get_worked_day_lines(self, contracts, date_from, date_to):
'number_of_hours': work_data['hours'],
'contract_id': contract.id,
}

res.append(attendances)

uniq_leaves = [*set(multi_leaves)]
c_leaves = {}
for rec in uniq_leaves:
c_leaves.setdefault(rec.holiday_status_id,
{'hours': float(
rec.duration_display.replace(
"hours",
"")), })
flag = 1
for item in c_leaves:
if not leaves:
data = {
'name': item.name,
'sequence': 20,
'code': item.code or 'LEAVES',
'number_of_hours': c_leaves[item]['hours'],
'number_of_days': c_leaves[item][
'hours'] / work_hours,
'contract_id': contract.id,
}
res.append(data)

for time_off in leaves:
if item == time_off:
leaves[item]['number_of_hours'] += c_leaves[item][
'hours']
leaves[item]['number_of_days'] += c_leaves[item][
'hours'] / work_hours
if item not in leaves and flag == 1:
data = {
'name': item.name,
'sequence': 20,
'code': holiday.holiday_status_id.code or 'GLOBAL',
'number_of_hours': c_leaves[item]['hours'],
'number_of_days': c_leaves[item][
'hours'] / work_hours,
'contract_id': contract.id,
}
res.append(data)
flag = 0

res.extend(leaves.values())
return res

Expand Down
28 changes: 15 additions & 13 deletions hr_payroll_community/wizard/hr_payroll_payslips_by_employees.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HrPayslipEmployees(models.TransientModel):
employee_ids = fields.Many2many('hr.employee', 'hr_employee_group_rel', 'payslip_id', 'employee_id', 'Employees')

def compute_sheet(self):

payslips = self.env['hr.payslip']
[data] = self.read()
active_id = self.env.context.get('active_id')
Expand All @@ -21,20 +22,21 @@ def compute_sheet(self):
if not data['employee_ids']:
raise UserError(_("You must select employee(s) to generate payslip(s)."))
for employee in self.env['hr.employee'].browse(data['employee_ids']):
print(employee.name)
slip_data = self.env['hr.payslip'].onchange_employee_id(from_date, to_date, employee.id, contract_id=False)
res = {
'employee_id': employee.id,
'name': slip_data['value'].get('name'),
'struct_id': slip_data['value'].get('struct_id'),
'contract_id': slip_data['value'].get('contract_id'),
'payslip_run_id': active_id,
'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids')],
'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids')],
'date_from': from_date,
'date_to': to_date,
'credit_note': run_data.get('credit_note'),
'company_id': employee.company_id.id,
}
'employee_id': employee.id,
'name': slip_data['value'].get('name'),
'struct_id': slip_data['value'].get('struct_id'),
'contract_id': slip_data['value'].get('contract_id'),
'payslip_run_id': active_id,
'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids')],
'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids')],
'date_from': from_date,
'date_to': to_date,
'credit_note': run_data.get('credit_note'),
'company_id': employee.company_id.id,
}
payslips += self.env['hr.payslip'].create(res)
payslips.compute_sheet()
payslips.compute_sheet()
return {'type': 'ir.actions.act_window_close'}

0 comments on commit ad3df8d

Please sign in to comment.