Server IP : 127.0.0.2 / Your IP : 18.222.34.209 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/hr_holidays/report/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import timedelta from dateutil.relativedelta import relativedelta from odoo import api, fields, models, _ from odoo.exceptions import UserError class HrHolidaySummaryReport(models.AbstractModel): _name = 'report.hr_holidays.report_holidayssummary' def _get_header_info(self, start_date, holiday_type): st_date = fields.Date.from_string(start_date) return { 'start_date': fields.Date.to_string(st_date), 'end_date': fields.Date.to_string(st_date + relativedelta(days=59)), 'holiday_type': 'Confirmed and Approved' if holiday_type == 'both' else holiday_type } def _get_day(self, start_date): res = [] start_date = fields.Date.from_string(start_date) for x in range(0, 60): color = '#ababab' if start_date.strftime('%a') == 'Sat' or start_date.strftime('%a') == 'Sun' else '' res.append({'day_str': start_date.strftime('%a'), 'day': start_date.day , 'color': color}) start_date = start_date + relativedelta(days=1) return res def _get_months(self, start_date): # it works for geting month name between two dates. res = [] start_date = fields.Date.from_string(start_date) end_date = start_date + relativedelta(days=59) while start_date <= end_date: last_date = start_date + relativedelta(day=1, months=+1, days=-1) if last_date > end_date: last_date = end_date month_days = (last_date - start_date).days + 1 res.append({'month_name': start_date.strftime('%B'), 'days': month_days}) start_date += relativedelta(day=1, months=+1) return res def _get_leaves_summary(self, start_date, empid, holiday_type): res = [] count = 0 start_date = fields.Date.from_string(start_date) end_date = start_date + relativedelta(days=59) for index in range(0, 60): current = start_date + timedelta(index) res.append({'day': current.day, 'color': ''}) if current.strftime('%a') == 'Sat' or current.strftime('%a') == 'Sun': res[index]['color'] = '#ababab' # count and get leave summary details. holiday_type = ['confirm','validate'] if holiday_type == 'both' else ['confirm'] if holiday_type == 'Confirmed' else ['validate'] holidays = self.env['hr.holidays'].search([ ('employee_id', '=', empid), ('state', 'in', holiday_type), ('type', '=', 'remove'), ('date_from', '<=', str(end_date)), ('date_to', '>=', str(start_date)) ]) for holiday in holidays: # Convert date to user timezone, otherwise the report will not be consistent with the # value displayed in the interface. date_from = fields.Datetime.from_string(holiday.date_from) date_from = fields.Datetime.context_timestamp(holiday, date_from).date() date_to = fields.Datetime.from_string(holiday.date_to) date_to = fields.Datetime.context_timestamp(holiday, date_to).date() for index in range(0, ((date_to - date_from).days + 1)): if date_from >= start_date and date_from <= end_date: res[(date_from-start_date).days]['color'] = holiday.holiday_status_id.color_name date_from += timedelta(1) count += abs(holiday.number_of_days) self.sum = count return res def _get_data_from_report(self, data): res = [] Employee = self.env['hr.employee'] if 'depts' in data: for department in self.env['hr.department'].browse(data['depts']): res.append({'dept' : department.name, 'data': [], 'color': self._get_day(data['date_from'])}) for emp in Employee.search([('department_id', '=', department.id)]): res[len(res)-1]['data'].append({ 'emp': emp.name, 'display': self._get_leaves_summary(data['date_from'], emp.id, data['holiday_type']), 'sum': self.sum }) elif 'emp' in data: res.append({'data':[]}) for emp in Employee.browse(data['emp']): res[0]['data'].append({ 'emp': emp.name, 'display': self._get_leaves_summary(data['date_from'], emp.id, data['holiday_type']), 'sum': self.sum }) return res def _get_holidays_status(self): res = [] for holiday in self.env['hr.holidays.status'].search([]): res.append({'color': holiday.color_name, 'name': holiday.name}) return res @api.model def render_html(self, docids, data=None): if not data.get('form'): raise UserError(_("Form content is missing, this report cannot be printed.")) Report = self.env['report'] holidays_report = Report._get_report_from_name('hr_holidays.report_holidayssummary') holidays = self.env['hr.holidays'].browse(self.ids) docargs = { 'doc_ids': self.ids, 'doc_model': holidays_report.model, 'docs': holidays, 'get_header_info': self._get_header_info(data['form']['date_from'], data['form']['holiday_type']), 'get_day': self._get_day(data['form']['date_from']), 'get_months': self._get_months(data['form']['date_from']), 'get_data_from_report': self._get_data_from_report(data['form']), 'get_holidays_status': self._get_holidays_status(), } return Report.render('hr_holidays.report_holidayssummary', docargs)