[ADD]:Added SQL view report for hr_recruitment.
[odoo/odoo.git] / addons / hr_recruitment / report / hr_recruitment_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 from hr_recruitment import hr_hr
25
26 class hr_recruitment_report(osv.osv):
27     _name = "hr.recruitment.report"
28     _description = "Recruitments Statistics"
29     _inherit = "crm.case.report"
30     _auto = False
31     _rec_name = 'date'
32     _columns = {
33         'date': fields.datetime('Date', readonly=True),
34         'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True),
35         'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]",readonly=True),
36         'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"),
37         'department_id':fields.many2one('hr.department','Department',readonly=True),
38         'priority': fields.selection(hr_hr.AVAILABLE_PRIORITIES, 'Appreciation'),
39
40     }
41     _order = 'date desc'
42     def init(self, cr):
43         tools.drop_view_if_exists(cr, 'hr_recruitment_report')
44         cr.execute("""
45             create or replace view hr_recruitment_report as (
46                  select
47                      min(s.id) as id,
48                      s.date as date,
49                      to_char(s.date, 'YYYY') as name,
50                      to_char(s.date, 'MM') as month,
51                      s.state,
52                      s.company_id,
53                      s.user_id,
54                      s.job_id,
55                      s.type_id,
56                      s.department_id,
57                      s.priority,
58                      s.stage_id
59                  from hr_applicant s
60                  group by
61                      s.date,s.state,s.company_id,s.user_id,s.stage_id,s.type_id,s.priority,
62                      s.job_id,s.department_id
63             )
64         """)
65 hr_recruitment_report()
66