summaryrefslogtreecommitdiff
path: root/addons/hr_holidays/report/hr_leave_report.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_holidays/report/hr_leave_report.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/hr_holidays/report/hr_leave_report.py')
-rw-r--r--addons/hr_holidays/report/hr_leave_report.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/addons/hr_holidays/report/hr_leave_report.py b/addons/hr_holidays/report/hr_leave_report.py
new file mode 100644
index 00000000..3ea1f0e7
--- /dev/null
+++ b/addons/hr_holidays/report/hr_leave_report.py
@@ -0,0 +1,111 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models, tools, exceptions, _
+from odoo.osv import expression
+
+
+class LeaveReport(models.Model):
+ _name = "hr.leave.report"
+ _description = 'Time Off Summary / Report'
+ _auto = False
+ _order = "date_from DESC, employee_id"
+
+ employee_id = fields.Many2one('hr.employee', string="Employee", readonly=True)
+ name = fields.Char('Description', readonly=True)
+ number_of_days = fields.Float('Number of Days', readonly=True)
+ leave_type = fields.Selection([
+ ('allocation', 'Allocation'),
+ ('request', 'Time Off')
+ ], string='Request Type', readonly=True)
+ department_id = fields.Many2one('hr.department', string='Department', readonly=True)
+ category_id = fields.Many2one('hr.employee.category', string='Employee Tag', readonly=True)
+ holiday_status_id = fields.Many2one("hr.leave.type", string="Leave Type", readonly=True)
+ state = fields.Selection([
+ ('draft', 'To Submit'),
+ ('cancel', 'Cancelled'),
+ ('confirm', 'To Approve'),
+ ('refuse', 'Refused'),
+ ('validate1', 'Second Approval'),
+ ('validate', 'Approved')
+ ], string='Status', readonly=True)
+ holiday_type = fields.Selection([
+ ('employee', 'By Employee'),
+ ('category', 'By Employee Tag')
+ ], string='Allocation Mode', readonly=True)
+ date_from = fields.Datetime('Start Date', readonly=True)
+ date_to = fields.Datetime('End Date', readonly=True)
+ payslip_status = fields.Boolean('Reported in last payslips', readonly=True)
+
+ def init(self):
+ tools.drop_view_if_exists(self._cr, 'hr_leave_report')
+
+ self._cr.execute("""
+ CREATE or REPLACE view hr_leave_report as (
+ SELECT row_number() over(ORDER BY leaves.employee_id) as id,
+ leaves.employee_id as employee_id, leaves.name as name,
+ leaves.number_of_days as number_of_days, leaves.leave_type as leave_type,
+ leaves.category_id as category_id, leaves.department_id as department_id,
+ leaves.holiday_status_id as holiday_status_id, leaves.state as state,
+ leaves.holiday_type as holiday_type, leaves.date_from as date_from,
+ leaves.date_to as date_to, leaves.payslip_status as payslip_status
+ from (select
+ allocation.employee_id as employee_id,
+ allocation.private_name as name,
+ allocation.number_of_days as number_of_days,
+ allocation.category_id as category_id,
+ allocation.department_id as department_id,
+ allocation.holiday_status_id as holiday_status_id,
+ allocation.state as state,
+ allocation.holiday_type,
+ null as date_from,
+ null as date_to,
+ FALSE as payslip_status,
+ 'allocation' as leave_type
+ from hr_leave_allocation as allocation
+ union all select
+ request.employee_id as employee_id,
+ request.private_name as name,
+ (request.number_of_days * -1) as number_of_days,
+ request.category_id as category_id,
+ request.department_id as department_id,
+ request.holiday_status_id as holiday_status_id,
+ request.state as state,
+ request.holiday_type,
+ request.date_from as date_from,
+ request.date_to as date_to,
+ request.payslip_status as payslip_status,
+ 'request' as leave_type
+ from hr_leave as request) leaves
+ );
+ """)
+
+ @api.model
+ def action_time_off_analysis(self):
+ domain = [('holiday_type', '=', 'employee')]
+
+ if self.env.context.get('active_ids'):
+ domain = expression.AND([
+ domain,
+ [('employee_id', 'in', self.env.context.get('active_ids', []))]
+ ])
+
+ return {
+ 'name': _('Time Off Analysis'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'hr.leave.report',
+ 'view_mode': 'tree,pivot,form',
+ 'search_view_id': self.env.ref('hr_holidays.view_hr_holidays_filter_report').id,
+ 'domain': domain,
+ 'context': {
+ 'search_default_group_type': True,
+ 'search_default_year': True,
+ 'search_default_validated': True,
+ }
+ }
+
+ @api.model
+ def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
+ if not self.user_has_groups('hr_holidays.group_hr_holidays_user') and 'name' in groupby:
+ raise exceptions.UserError(_('Such grouping is not allowed.'))
+ return super(LeaveReport, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)