[FIX] hr_recuirement: section_id should not used
[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 import tools
22 from osv import fields,osv
23 from hr_recruitment import hr_recruitment
24
25 AVAILABLE_STATES = [
26     ('draft','Draft'),
27     ('open','Open'),
28     ('cancel', 'Cancelled'),
29     ('done', 'Closed'),
30     ('pending','Pending')
31 ]
32
33 class hr_recruitment_report(osv.osv):
34     _name = "hr.recruitment.report"
35     _description = "Recruitments Statistics"
36     _auto = False
37     _rec_name = 'date'
38
39     def _get_data(self, cr, uid, ids, field_name, arg, context={}):
40
41         """ @param cr: the current row, from the database cursor,
42             @param uid: the current user’s ID for security checks,
43             @param ids: List of case and section Data’s IDs
44             @param context: A standard dictionary for contextual values """
45
46         res = {}
47         state_perc = 0.0
48         avg_ans = 0.0
49         #TODO: Calculate avg_answer, perc_done, perc_cancel
50         return res
51
52     _columns = {
53         'user_id':fields.many2one('res.users', 'User', readonly=True),
54         'nbr': fields.integer('# of Cases', readonly=True),
55         'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
56         'avg_answers': fields.function(_get_data, string='Avg. Answers', method=True, type="integer"),
57         'perc_done': fields.function(_get_data, string='%Done', method=True, type="float"),
58         'perc_cancel': fields.function(_get_data, string='%Cancel', method=True, type="float"),
59         'month':fields.selection([('01', 'January'), ('02', 'February'), \
60                                   ('03', 'March'), ('04', 'April'),\
61                                   ('05', 'May'), ('06', 'June'), \
62                                   ('07', 'July'), ('08', 'August'),\
63                                   ('09', 'September'), ('10', 'October'),\
64                                   ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
65         'company_id': fields.many2one('res.company', 'Company', readonly=True),
66         'day': fields.char('Day', size=128, readonly=True),
67         'year': fields.char('Year', size=4, readonly=True),
68         'date': fields.date('Date', readonly=True),
69         'date_closed': fields.date('Closed', readonly=True),
70         'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True),
71         'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage'),
72         'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('object_id.model', '=', 'hr.applicant')]"),
73         'department_id':fields.many2one('hr.department','Department',readonly=True),
74         'priority': fields.selection(hr_recruitment.AVAILABLE_PRIORITIES, 'Appreciation'),
75         'salary_prop' : fields.float("Salary Proposed"),
76         'salary_exp' : fields.float("Salary Expected"),
77         'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
78         'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact Name',readonly=True),
79         'available' : fields.float("Availability"),
80         'delay_open': fields.float('Avg. Delay to Open', digits=(16,2), readonly=True, group_operator="avg",
81                                        help="Number of Days to close the project issue"),
82         'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg",
83                                        help="Number of Days to close the project issue"),
84
85     }
86     _order = 'date desc'
87     def init(self, cr):
88         tools.drop_view_if_exists(cr, 'hr_recruitment_report')
89         cr.execute("""
90             create or replace view hr_recruitment_report as (
91                  select
92                      min(s.id) as id,
93                      date_trunc('day',s.create_date) as date,
94                      date_trunc('day',s.date_closed) as date_closed,
95                      to_char(s.create_date, 'YYYY') as year,
96                      to_char(s.create_date, 'MM') as month,
97                      to_char(s.create_date, 'YYYY-MM-DD') as day,
98                      s.state,
99                      s.partner_id,
100                      s.company_id,
101                      s.partner_address_id,
102                      s.user_id,
103                      s.job_id,
104                      s.type_id,
105                      sum(s.availability) as available,
106                      s.department_id,
107                      s.priority,
108                      s.stage_id,
109                      sum(salary_proposed) as salary_prop,
110                      sum(salary_expected) as salary_exp,
111                      extract('epoch' from (s.date_open-s.create_date))/(3600*24) as  delay_open,
112                      extract('epoch' from (s.date_closed-s.create_date))/(3600*24) as  delay_close,
113                      count(*) as nbr
114                  from hr_applicant s
115                  group by
116                      to_char(s.create_date, 'YYYY'),
117                      to_char(s.create_date, 'MM'),
118                      to_char(s.create_date, 'YYYY-MM-DD') ,
119                      date_trunc('day',s.create_date),
120                      date_trunc('day',s.date_closed),
121                      s.date_open,
122                      s.create_date,
123                      s.date_closed,
124                      s.state,
125                      s.partner_id,
126                      s.partner_address_id,
127                      s.company_id,
128                      s.user_id,
129                      s.stage_id,
130                      s.type_id,
131                      s.priority,
132                      s.job_id,
133                      s.department_id
134             )
135         """)
136 hr_recruitment_report()
137
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: