@ -0,0 +1,50 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
||||
|
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
Hr Leave Dashboard |
||||
|
================== |
||||
|
This module helps you to brings a multipurpose graphical dashboard for Time Off module and making the relationship management better and easier. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
* No Additional configuration is needed. |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
General Public License, Version 3 (AGPL v3). |
||||
|
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
* Developer: |
||||
|
(V16) Rahul Rajeev, |
||||
|
(V17) Jumana Haseen, |
||||
|
(V18) Gayathri V |
||||
|
Contact: odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
from . import models |
||||
|
from . import report |
@ -0,0 +1,65 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
{ |
||||
|
'name': "Hr Leave Dashboard", |
||||
|
'version': '18.0.1.0.0', |
||||
|
'category': 'Human Resources', |
||||
|
'summary': """Advanced Leave Dashboard helps to view your and your |
||||
|
subordinate's details""", |
||||
|
'description': """Advanced Leave Dashboard brings a multipurpose graphical |
||||
|
dashboard for Time Off module and making the relationship management better |
||||
|
and easier""", |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': "https://www.cybrosys.com", |
||||
|
'depends': ['base', 'hr_holidays', 'hr_org_chart'], |
||||
|
'data': [ |
||||
|
'report/hr_leave_reports.xml', |
||||
|
'report/hr_leave_report_templates.xml', |
||||
|
], |
||||
|
'assets': { |
||||
|
'web.assets_backend': [ |
||||
|
'hr_leave_dashboard/static/src/js/calendar_model.js', |
||||
|
'hr_leave_dashboard/static/src/js/calendar_year_renderer.js', |
||||
|
'hr_leave_dashboard/static/src/js/hooks.js', |
||||
|
'hr_leave_dashboard/static/src/js/emp_org_chart.js', |
||||
|
'hr_leave_dashboard/static/src/js/time_off_emp_card.js', |
||||
|
'hr_leave_dashboard/static/src/js/time_off_emp_dashboard.js', |
||||
|
'hr_leave_dashboard/static/src/xml/approval_status_card_templates.xml', |
||||
|
'hr_leave_dashboard/static/src/xml/time_off_emp_dashboard_templates.xml', |
||||
|
'hr_leave_dashboard/static/src/xml/emp_org_chart_templates.xml', |
||||
|
'hr_leave_dashboard/static/src/xml/emp_department_card_templates.xml', |
||||
|
'hr_leave_dashboard/static/src/xml/time_off_emp_card_templates.xml', |
||||
|
'hr_leave_dashboard/static/src/css/hr_leave_dashboard.css', |
||||
|
'hr_org_chart/static/src/fields/hr_org_chart.scss', |
||||
|
'hr_leave_dashboard/static/src/scss/time_off_dashboard.scss', |
||||
|
'hr_holidays/static/src/dashboard/time_off_card.scss', |
||||
|
'hr_leave_dashboard/static/src/scss/calendar_renderer.scss' |
||||
|
], |
||||
|
}, |
||||
|
'images': ['static/description/banner.jpg'], |
||||
|
'license': 'AGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
## Module <hr_leave_dashboard> |
||||
|
|
||||
|
#### 13.11.2024 |
||||
|
#### Version 18.0.1.0.0 |
||||
|
#### ADD |
||||
|
|
||||
|
- Initial Commit Hr Leave Dashboard |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
from . import hr_employee |
||||
|
from . import hr_leave |
@ -0,0 +1,56 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class HrEmployee(models.Model): |
||||
|
"""Inherit the model hr.employee to add the functionality for retrieving |
||||
|
public holiday information""" |
||||
|
_inherit = 'hr.employee' |
||||
|
|
||||
|
def get_public_holidays(self, start_date, end_date): |
||||
|
"""The function get_public_holidays takes in a start date and end |
||||
|
date as arguments and returns a dictionary with all the public |
||||
|
holidays within that range. It does this by calling the |
||||
|
_get_public_holidays method and then iterating through the results to |
||||
|
add each holiday to the dictionary.""" |
||||
|
all_days = {} |
||||
|
user = self or self.env.user.employee_id |
||||
|
public_holidays = user._get_public_holidays(start_date, end_date) |
||||
|
for holiday in public_holidays: |
||||
|
num_days = (holiday.date_to - holiday.date_from).days |
||||
|
for day in range(num_days + 1): |
||||
|
all_days[str(holiday.date_from.date())] = day |
||||
|
return all_days |
||||
|
|
||||
|
def _get_public_holidays(self, start_date, end_date): |
||||
|
"""The _get_public_holidays function searches for public holidays |
||||
|
within a given date range, for all companies associated with the |
||||
|
current environment's user. It returns a recordset of |
||||
|
resource.calendar.leaves that match the search criteria.""" |
||||
|
public_holidays = self.env['resource.calendar.leaves'].search([ |
||||
|
('date_from', '<=', end_date), |
||||
|
('date_to', '>=', start_date), |
||||
|
('resource_id', '=', False), |
||||
|
('company_id', 'in', self.env.companies.ids), |
||||
|
]) |
||||
|
return public_holidays |
@ -0,0 +1,172 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
import pytz |
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class HrLeave(models.Model): |
||||
|
"""Inherit the model hr.leave to introduce supplementary functionality |
||||
|
aimed at incorporating specific employee details.""" |
||||
|
_inherit = 'hr.leave' |
||||
|
|
||||
|
def _prepare_employee_data(self, employee): |
||||
|
"""Function to prepare employee data for the dashboard""" |
||||
|
return { |
||||
|
'id': employee.id, |
||||
|
'name': employee.name, |
||||
|
'job_id': employee.job_id.name, |
||||
|
'approval_status_count': self.get_approval_status_count(employee.id) |
||||
|
} |
||||
|
|
||||
|
@api.model |
||||
|
def get_current_employee(self): |
||||
|
"""This function fetches current employee details in a dictionary""" |
||||
|
current_employee = self.env.user.employee_ids |
||||
|
return { |
||||
|
'id': current_employee.id, |
||||
|
'name': current_employee.name, |
||||
|
'job_id': current_employee.job_id.id, |
||||
|
'image_1920': current_employee.image_1920, |
||||
|
'work_email': current_employee.work_email, |
||||
|
'work_phone': current_employee.work_phone, |
||||
|
'resource_calendar_id': current_employee.resource_calendar_id.name, |
||||
|
'link': '/mail/view?model=%s&res_id=%s' % ( |
||||
|
'hr.employee.public', current_employee.id,), |
||||
|
'department_id': current_employee.department_id.name, |
||||
|
'company': current_employee.company_id.name, |
||||
|
'job_position': current_employee.job_id.name, |
||||
|
'parent_id': current_employee.parent_id.ids, |
||||
|
'child_ids': current_employee.child_ids.ids, |
||||
|
'child_all_count': current_employee.child_all_count, |
||||
|
'manager': self._prepare_employee_data( |
||||
|
current_employee.parent_id) if ( |
||||
|
current_employee.parent_id) else {}, |
||||
|
'manager_all_count': len(current_employee.parent_id.ids), |
||||
|
'children': [self._prepare_employee_data(child) for child in |
||||
|
current_employee.child_ids if |
||||
|
child != current_employee], |
||||
|
} |
||||
|
|
||||
|
@api.model |
||||
|
def get_absentees(self): |
||||
|
"""The function retrieves a list of employees who are absent on the |
||||
|
current date by querying the hr_leave table and comparing the |
||||
|
date_from and date_to fields of validated leave requests. It returns |
||||
|
a list of dictionaries containing the employee's name, employee_id, |
||||
|
date_from, and date_to""" |
||||
|
current_employee = self.env.user.employee_ids |
||||
|
children = [self._prepare_employee_data(child) for child in |
||||
|
current_employee.child_ids if |
||||
|
child != current_employee] |
||||
|
child_list = [child.get('id') for child in children] |
||||
|
if len(child_list) > 1: |
||||
|
query = "SELECT employee_id,name,date_from,date_to FROM hr_leave " \ |
||||
|
"INNER JOIN hr_employee ON hr_leave.employee_id = " \ |
||||
|
"hr_employee.id WHERE state = 'validate' AND " \ |
||||
|
"employee_id in %s" % str(tuple(child_list)) |
||||
|
self._cr.execute(query) |
||||
|
elif len(child_list) == 1: |
||||
|
query = "SELECT employee_id,name,date_from,date_to FROM hr_leave " \ |
||||
|
"INNER JOIN hr_employee ON hr_leave.employee_id = " \ |
||||
|
"hr_employee.id WHERE state = 'validate' AND " \ |
||||
|
"employee_id = %s" % child_list[0] |
||||
|
self._cr.execute(query) |
||||
|
leave = self._cr.dictfetchall() |
||||
|
absentees = [ |
||||
|
leave[leave_date] for leave_date in range(len(leave)) |
||||
|
if leave[leave_date].get('date_from') <= fields.datetime.now() <= leave[ |
||||
|
leave_date].get('date_to') |
||||
|
] |
||||
|
return absentees |
||||
|
|
||||
|
@api.model |
||||
|
def get_current_shift(self): |
||||
|
""" This function fetches current employee's current shift""" |
||||
|
current_employee = self.env.user.employee_ids |
||||
|
employee_tz = current_employee.tz or self.env.context.get('tz') |
||||
|
employee_pytz = pytz.timezone(employee_tz) if employee_tz else pytz.utc |
||||
|
employee_datetime = fields.datetime.now().astimezone(employee_pytz) |
||||
|
hour = employee_datetime.strftime("%H") |
||||
|
minute = employee_datetime.strftime("%M") |
||||
|
day = employee_datetime.strftime("%A") |
||||
|
time = hour + '.' + minute |
||||
|
day_num = '0' if day == 'Monday' else '1' if day == 'Tuesday' \ |
||||
|
else '2' if day == 'Wednesday' else '3' if day == 'Thursday' \ |
||||
|
else '4' if day == 'Friday' else '5' if day == 'Saturday' else '6' |
||||
|
for shift in current_employee.resource_calendar_id.attendance_ids: |
||||
|
if shift.dayofweek == day_num and shift.hour_from <= float( |
||||
|
time) <= shift.hour_to: |
||||
|
return shift.name |
||||
|
return False |
||||
|
|
||||
|
@api.model |
||||
|
def get_upcoming_holidays(self): |
||||
|
""" This function fetches upcoming holidays""" |
||||
|
current_employee = self.env.user.employee_ids |
||||
|
employee_tz = current_employee.tz or self.env.context.get('tz') |
||||
|
employee_pytz = pytz.timezone(employee_tz) if employee_tz else pytz.utc |
||||
|
employee_datetime = fields.datetime.now().astimezone(employee_pytz) |
||||
|
query = "SELECT * FROM public.resource_calendar_leaves WHERE " \ |
||||
|
"resource_id is null" |
||||
|
self._cr.execute(query) |
||||
|
holidays = self._cr.dictfetchall() |
||||
|
upcoming_holidays = [holiday for holiday in holidays if |
||||
|
employee_datetime.date() < holiday.get( |
||||
|
'date_to').date()] |
||||
|
return upcoming_holidays |
||||
|
|
||||
|
@api.model |
||||
|
def get_approval_status_count(self, current_employee): |
||||
|
""" This function fetches approval status count""" |
||||
|
return { |
||||
|
'validate_count': self.env['hr.leave'].search_count([ |
||||
|
('employee_id', '=', current_employee), |
||||
|
('state', '=', 'validate') |
||||
|
]), |
||||
|
'confirm_count': self.env['hr.leave'].search_count([ |
||||
|
('employee_id', '=', current_employee), |
||||
|
('state', '=', 'confirm') |
||||
|
]), |
||||
|
'refuse_count': self.env['hr.leave'].search_count([ |
||||
|
('employee_id', '=', current_employee), |
||||
|
('state', '=', 'refuse') |
||||
|
]) |
||||
|
} |
||||
|
|
||||
|
@api.model |
||||
|
def get_all_validated_leaves(self): |
||||
|
""" This function fetches all validated leaves""" |
||||
|
leaves = self.env['hr.leave'].search([('state', '=', 'validate')]) |
||||
|
all_validated_leaves = [ |
||||
|
{ |
||||
|
'id': leave.id, |
||||
|
'employee_id': leave.employee_id.id, |
||||
|
'employee_name': leave.employee_id.name, |
||||
|
'request_date_from': leave.request_date_from, |
||||
|
'request_date_to': leave.request_date_to, |
||||
|
'leave_type_id': leave.holiday_status_id.id, |
||||
|
'leave_type': leave.holiday_status_id.name, |
||||
|
'number_of_days': leave.number_of_days |
||||
|
} |
||||
|
for leave in leaves |
||||
|
] |
||||
|
return all_validated_leaves |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Jumana Haseen (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
from . import hr_leave_report |
@ -0,0 +1,108 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Jumana Haseen (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
from datetime import timedelta |
||||
|
from odoo import api, fields, models |
||||
|
from odoo.tools import date_utils |
||||
|
|
||||
|
|
||||
|
class HrLeaveReport(models.AbstractModel): |
||||
|
"""Model for the dashboard for viewing the employees leave""" |
||||
|
_name = 'report.hr_leave_dashboard.hr_leave_report' |
||||
|
_description = 'HR Leave Report' |
||||
|
|
||||
|
@api.model |
||||
|
def _get_report_values(self, docids, data=None): |
||||
|
"""Function for getting the report values""" |
||||
|
today = fields.Date.today() |
||||
|
if data.get('duration') == 'this_month': |
||||
|
start_of_month = date_utils.start_of(today, 'month') |
||||
|
end_of_month = date_utils.end_of(today, 'month') - timedelta(days=1) |
||||
|
option = self.generate_date_range(start_of_month, end_of_month) |
||||
|
elif data.get('duration') == 'this_year': |
||||
|
start_of_year = date_utils.start_of(today, 'year') |
||||
|
end_of_year = date_utils.end_of(today, 'year') - timedelta(days=1) |
||||
|
option = self.generate_date_range(start_of_year, end_of_year) |
||||
|
elif data.get('duration') == 'this_week': |
||||
|
start_of_week = date_utils.start_of(today, 'week') |
||||
|
end_of_week = date_utils.end_of(today, 'week') |
||||
|
option = self.generate_date_range(start_of_week, end_of_week) |
||||
|
else: |
||||
|
option = [str(today)] |
||||
|
|
||||
|
if not self.env.user.employee_ids.child_ids: |
||||
|
query = """SELECT l.id, lt.id as hr_leave_type_id, e.id as |
||||
|
emp_id, e.name as emp_name, e.department_id as emp_department, |
||||
|
e.parent_id as emp_parent_id, request_date_from, request_date_to, |
||||
|
l.number_of_days, lt.name ::jsonb->> 'en_US' as leave_type, |
||||
|
SUM(al.number_of_days) AS allocated_days, SUM(CASE WHEN l.state = |
||||
|
'validate' THEN l.number_of_days ELSE 0 END) AS taken_days, |
||||
|
SUM(al.number_of_days) - SUM(CASE WHEN l.state = 'validate' THEN |
||||
|
l.number_of_days ELSE 0 END) AS balance_days FROM hr_employee e |
||||
|
inner join hr_leave_allocation al ON al.employee_id = e.id inner |
||||
|
join hr_leave l on l.employee_id = e.id inner join hr_leave_type |
||||
|
lt on l.holiday_status_id = lt.id WHERE l.state = 'validate' AND |
||||
|
e.department_id = '%s' GROUP BY e.id,lt.id,l.id""" % \ |
||||
|
self.env.user.employee_ids.department_id.id |
||||
|
else: |
||||
|
query = """SELECT l.id, lt.id as hr_leave_type_id, e.id as |
||||
|
emp_id, e.name as emp_name, e.department_id as emp_department, |
||||
|
e.parent_id as emp_parent_id, request_date_from, request_date_to, |
||||
|
l.number_of_days, lt.name ::jsonb->> 'en_US' as leave_type, |
||||
|
SUM(al.number_of_days) AS allocated_days, SUM(CASE WHEN l.state = |
||||
|
'validate' THEN l.number_of_days ELSE 0 END) AS taken_days, |
||||
|
SUM(al.number_of_days) - SUM(CASE WHEN l.state = 'validate' THEN |
||||
|
l.number_of_days ELSE 0 END) AS balance_days FROM hr_employee e |
||||
|
inner join hr_leave_allocation al ON al.employee_id = e.id inner |
||||
|
join hr_leave l on l.employee_id = e.id inner join hr_leave_type |
||||
|
lt on l.holiday_status_id = lt.id WHERE l.state = 'validate' |
||||
|
GROUP BY e.id,lt.id,l.id""" |
||||
|
|
||||
|
self.env.cr.execute(query) |
||||
|
leave_data = self.env.cr.dictfetchall() |
||||
|
filtered_list = [] |
||||
|
filtered_tuple = [] |
||||
|
for leave in leave_data: |
||||
|
leave_list = self.generate_date_range(leave.get('request_date_from'), |
||||
|
leave.get('request_date_to') - timedelta(days=1)) |
||||
|
for date in leave_list: |
||||
|
if date in option: |
||||
|
filtered_list.append(leave) |
||||
|
break |
||||
|
for leave in filtered_list: |
||||
|
if (leave.get('hr_leave_type_id'), leave.get('emp_id')) in filtered_tuple: |
||||
|
filtered_list.remove(leave) |
||||
|
else: |
||||
|
filtered_tuple.append( |
||||
|
(leave.get('hr_leave_type_id'), leave.get('emp_id'))) |
||||
|
return { |
||||
|
'duration': data.get('duration'), |
||||
|
'filtered_list': filtered_list, |
||||
|
} |
||||
|
|
||||
|
def generate_date_range(self, start_date, end_date): |
||||
|
"""Generate a list of dates within the given range""" |
||||
|
date_list = [] |
||||
|
current_date = start_date |
||||
|
while current_date <= end_date: |
||||
|
date_list.append(current_date.strftime("%Y-%m-%d")) |
||||
|
current_date += timedelta(days=1) |
||||
|
return date_list |
@ -0,0 +1,89 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<!-- Template for the hr leave report --> |
||||
|
<template id="hr_leave_report"> |
||||
|
<t t-call="web.html_container"> |
||||
|
<t t-call="web.external_layout"> |
||||
|
<div class="page"> |
||||
|
<div class="oe_structure"> |
||||
|
<div class="text-center"> |
||||
|
<h1>Leave Report</h1> |
||||
|
</div> |
||||
|
<div class="text-center" t-if="duration=='today'"> |
||||
|
<h5>Absentees Today</h5> |
||||
|
</div> |
||||
|
<div class="text-center" t-if="duration=='this_week'"> |
||||
|
<h5>Absentees this week</h5> |
||||
|
</div> |
||||
|
<div class="text-center" t-if="duration=='this_month'"> |
||||
|
<h5>Absentees this month</h5> |
||||
|
</div> |
||||
|
<div class="text-center" t-if="duration=='this_year'"> |
||||
|
<h5>Absentees this year</h5> |
||||
|
</div> |
||||
|
<div class="row"> |
||||
|
<table class="table"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Employee ID |
||||
|
</strong> |
||||
|
</th> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Employee Name |
||||
|
</strong> |
||||
|
</th> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Leave Type |
||||
|
</strong> |
||||
|
</th> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Allocated Balance |
||||
|
</strong> |
||||
|
</th> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Taken Leaves |
||||
|
</strong> |
||||
|
</th> |
||||
|
<th> |
||||
|
<strong> |
||||
|
Remaining Balance |
||||
|
</strong> |
||||
|
</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<t t-foreach="filtered_list" t-as="leave_data"> |
||||
|
<tr> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['emp_id']"/> |
||||
|
</td> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['emp_name']"/> |
||||
|
</td> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['leave_type']"/> |
||||
|
</td> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['allocated_days']"/> |
||||
|
</td> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['taken_days']"/> |
||||
|
</td> |
||||
|
<td> |
||||
|
<span t-esc="leave_data['balance_days']"/> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</t> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</t> |
||||
|
</t> |
||||
|
</template> |
||||
|
</odoo> |
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<!-- Report Action--> |
||||
|
<record id="hr_leave_report_action" model="ir.actions.report"> |
||||
|
<field name="name">Leave report</field> |
||||
|
<field name="model">hr.leave.report</field> |
||||
|
<field name="report_type">qweb-pdf</field> |
||||
|
<field name="report_name">hr_leave_dashboard.hr_leave_report</field> |
||||
|
<field name="report_file">hr_leave_dashboard.hr_leave_report</field> |
||||
|
</record> |
||||
|
</odoo> |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 912 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 95 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 44 KiB |