[FIX] correct various date issues in reporting
[odoo/odoo.git] / addons / hr_evaluation / report / hr_evaluation_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp import tools
23 from openerp.osv import fields, osv
24
25
26 class hr_evaluation_report(osv.Model):
27     _name = "hr.evaluation.report"
28     _description = "Evaluations Statistics"
29     _auto = False
30     _columns = {
31         'create_date': fields.date('Create Date', readonly=True),
32         'delay_date': fields.float('Delay to Start', digits=(16, 2), readonly=True),
33         'overpass_delay': fields.float('Overpassed Deadline', digits=(16, 2), readonly=True),
34         'deadline': fields.date("Deadline", readonly=True),
35         'request_id': fields.many2one('survey.user_input', 'Request_id', readonly=True),
36         'closed': fields.date("closed", readonly=True),
37         'plan_id': fields.many2one('hr_evaluation.plan', 'Plan', readonly=True),
38         'employee_id': fields.many2one('hr.employee', "Employee", readonly=True),
39         'rating': fields.selection([
40             ('0', 'Significantly bellow expectations'),
41             ('1', 'Did not meet expectations'),
42             ('2', 'Meet expectations'),
43             ('3', 'Exceeds expectations'),
44             ('4', 'Significantly exceeds expectations'),
45         ], "Overall Rating", readonly=True),
46         'nbr': fields.integer('# of Requests', readonly=True),
47         'state': fields.selection([
48             ('draft', 'Draft'),
49             ('wait', 'Plan In Progress'),
50             ('progress', 'Final Validation'),
51             ('done', 'Done'),
52             ('cancel', 'Cancelled'),
53         ], 'Status', readonly=True),
54     }
55     _order = 'create_date desc'
56
57     _depends = {
58         'hr.evaluation.interview': ['evaluation_id', 'id', 'request_id'],
59         'hr_evaluation.evaluation': [
60             'create_date', 'date', 'date_close', 'employee_id', 'plan_id',
61             'rating', 'state',
62         ],
63     }
64
65     def init(self, cr):
66         tools.drop_view_if_exists(cr, 'hr_evaluation_report')
67         cr.execute("""
68             create or replace view hr_evaluation_report as (
69                  select
70                      min(l.id) as id,
71                      date(s.create_date) as create_date,
72                      s.employee_id,
73                      l.request_id,
74                      s.plan_id,
75                      s.rating,
76                      s.date as deadline,
77                      s.date_close as closed,
78                      count(l.*) as nbr,
79                      s.state,
80                      avg(extract('epoch' from age(s.create_date,CURRENT_DATE)))/(3600*24) as  delay_date,
81                      avg(extract('epoch' from age(s.date,CURRENT_DATE)))/(3600*24) as overpass_delay
82                      from
83                  hr_evaluation_interview l
84                 LEFT JOIN
85                      hr_evaluation_evaluation s on (s.id=l.evaluation_id)
86                  GROUP BY
87                      s.create_date,
88                      s.state,
89                      s.employee_id,
90                      s.date,
91                      s.date_close,
92                      l.request_id,
93                      s.rating,
94                      s.plan_id
95             )
96         """)
97
98
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
100