From 1ca3b3df3421961caec3b747a364071c80f5c7da Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 17:14:58 +0700 Subject: initial commit --- hrms_dashboard/report/__init__.py | 3 +++ hrms_dashboard/report/broadfactor.py | 49 +++++++++++++++++++++++++++++++++++ hrms_dashboard/report/broadfactor.xml | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 hrms_dashboard/report/__init__.py create mode 100644 hrms_dashboard/report/broadfactor.py create mode 100644 hrms_dashboard/report/broadfactor.xml (limited to 'hrms_dashboard/report') diff --git a/hrms_dashboard/report/__init__.py b/hrms_dashboard/report/__init__.py new file mode 100644 index 0000000..c5b299d --- /dev/null +++ b/hrms_dashboard/report/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import broadfactor diff --git a/hrms_dashboard/report/broadfactor.py b/hrms_dashboard/report/broadfactor.py new file mode 100644 index 0000000..dfda9d3 --- /dev/null +++ b/hrms_dashboard/report/broadfactor.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from datetime import date, datetime + +from odoo import tools +from odoo import api, fields, models + + +class EmployeeBroadFactor(models.Model): + _name = "hr.employee.broad.factor" + _description = "Employee Broadfactor" + _auto = False + + name = fields.Char() + no_of_occurrence = fields.Integer() + no_of_days = fields.Integer() + broad_factor = fields.Integer() + + def init(self): + tools.drop_view_if_exists(self._cr, 'hr_employee_broad_factor') + date_today = date.today() + print("date_today", date_today) + self._cr.execute(""" + create or replace view hr_employee_broad_factor as ( + select + e.id, + e.name, + count(h.*) as no_of_occurrence, + sum(h.number_of_days) as no_of_days, + count(h.*)*count(h.*)*sum(h.number_of_days) as broad_factor + from hr_employee e + full join (select * from hr_leave where state = 'validate' and date_to <= now()::timestamp) h + on e.id =h.employee_id + group by e.id + )""") + + +class ReportOverdue(models.AbstractModel): + _name = 'report.hrms_dashboard.report_broadfactor' + + @api.model + def get_report_values(self, docids=None, data=None): + sql = """select * from hr_employee_broad_factor""" + self.env.cr.execute(sql) + lines = self.env.cr.dictfetchall() + return { + 'doc_model': 'hr.employee.broad_factor', + 'lines': lines, + 'Date': fields.date.today(), + } diff --git a/hrms_dashboard/report/broadfactor.xml b/hrms_dashboard/report/broadfactor.xml new file mode 100644 index 0000000..032a8dc --- /dev/null +++ b/hrms_dashboard/report/broadfactor.xml @@ -0,0 +1,47 @@ + + + + + + -- cgit v1.2.3