rename labels to be more clear
[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_recruitment
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         'year': fields.char('Year', size=4, readonly=True),
34         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
35             ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
36             ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
37         'day': fields.char('Day', size=128, readonly=True),
38         'date': fields.date('Date', readonly=True),
39         'date_closed': fields.date('Closed', readonly=True),
40         'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True),
41         'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]",readonly=True),
42         'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"),
43         'department_id':fields.many2one('hr.department','Department',readonly=True),
44         'priority': fields.selection(hr_recruitment.AVAILABLE_PRIORITIES, 'Appreciation'),
45         'salary_prop' : fields.float("Salary Proposed"),
46         'salary_exp' : fields.float("Salary Expected"),
47         'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
48         'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact Name',readonly=True),
49         'available' : fields.float("Availability")
50
51     }
52     _order = 'date desc'
53     def init(self, cr):
54         tools.drop_view_if_exists(cr, 'hr_recruitment_report')
55         cr.execute("""
56             create or replace view hr_recruitment_report as (
57                  select
58                      min(s.id) as id,
59                      date_trunc('day',s.create_date) as date,
60                      date_trunc('day',s.date_closed) as date_closed,
61                      to_char(s.create_date, 'YYYY') as year,
62                      to_char(s.create_date, 'MM') as month,
63                      to_char(s.create_date, 'YYYY-MM-DD') as day,
64                      s.state,
65                      s.partner_id,
66                      s.company_id,
67                      s.partner_address_id,
68                      s.user_id,
69                      s.job_id,
70                      s.type_id,
71                      sum(s.availability) as available,
72                      s.department_id,
73                      s.priority,
74                      s.stage_id,
75                      sum(salary_proposed) as salary_prop,
76                      sum(salary_expected) as salary_exp,
77                      count(*) as nbr
78                  from hr_applicant s
79                  group by
80                      to_char(s.create_date, 'YYYY'),
81                      to_char(s.create_date, 'MM'),
82                      to_char(s.create_date, 'YYYY-MM-DD') ,
83                      date_trunc('day',s.create_date),
84                      date_trunc('day',s.date_closed),
85                      s.state,
86                      s.partner_id,
87                      s.partner_address_id,
88                      s.company_id,
89                      s.user_id,
90                      s.stage_id,
91                      s.type_id,
92                      s.priority,
93                      s.job_id,
94                      s.department_id
95             )
96         """)
97 hr_recruitment_report()
98