[IMP]:Improved code and set access rights for evaluation report.
[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 import tools
23 from osv import fields,osv
24
25
26 class hr_evaluation_report(osv.osv):
27     _name = "hr.evaluation.report"
28     _description = "Evaluations Statistics"
29     _auto = False
30     _rec_name = 'date'
31     _columns = {
32         'create_date': fields.datetime('Create Date', readonly=True),
33         'deadline': fields.date("Deadline", readonly=True),
34         'closed': fields.date("closed", readonly=True),
35         'year': fields.char('Year', size=4, readonly=True),
36         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
37             ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
38             ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
39         'employee_id': fields.many2one('hr.employee', "Employee", readonly=True),
40         'nbr':fields.integer('# of Requests', readonly=True),
41         'state': fields.selection([
42             ('draft','Draft'),
43             ('wait','Plan In Progress'),
44             ('progress','Final Validation'),
45             ('done','Done'),
46             ('cancel','Cancelled'),
47         ], 'State',readonly=True),
48     }
49     _order = 'create_date desc'
50     def init(self, cr):
51         tools.drop_view_if_exists(cr, 'hr_evaluation_report')
52         cr.execute("""
53             create or replace view hr_evaluation_report as (
54                  select
55                      min(l.id) as id,
56                      s.create_date as create_date,
57                      s.employee_id,
58                      s.date as deadline,
59                      s.date_close as closed,
60                      to_char(s.create_date, 'YYYY') as year,
61                      to_char(s.create_date, 'MM') as month,
62                      count(*) as nbr,
63                      s.state
64                      from
65                  hr_evaluation_interview l
66                  left join
67                      hr_evaluation_evaluation s on (s.id=l.evaluation_id)
68                  group by
69                      s.create_date,s.state,s.employee_id,
70                      s.date,s.date_close
71             )
72         """)
73 hr_evaluation_report()
74