[FIX] correct various date issues in reporting
[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 from openerp import tools
23 from openerp.osv import fields, osv
24 from .. import hr_recruitment
25 from openerp.addons.decimal_precision import decimal_precision as dp
26
27
28 class hr_recruitment_report(osv.Model):
29     _name = "hr.recruitment.report"
30     _description = "Recruitments Statistics"
31     _auto = False
32     _rec_name = 'date_create'
33     _order = 'date_create desc'
34
35     _columns = {
36         'user_id': fields.many2one('res.users', 'User', readonly=True),
37         'company_id': fields.many2one('res.company', 'Company', readonly=True),
38         'date_create': fields.datetime('Create Date', readonly=True),
39         'date_last_stage_update': fields.datetime('Last Stage Update', readonly=True),
40         'date_closed': fields.date('Closed', readonly=True),
41         'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True),
42         'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage'),
43         'type_id': fields.many2one('hr.recruitment.degree', 'Degree'),
44         'department_id': fields.many2one('hr.department','Department',readonly=True),
45         'priority': fields.selection(hr_recruitment.AVAILABLE_PRIORITIES, 'Appreciation'),
46         'salary_prop' : fields.float("Salary Proposed", digits_compute=dp.get_precision('Account')),
47         'salary_prop_avg' : fields.float("Avg. Proposed Salary", group_operator="avg", digits_compute=dp.get_precision('Account')),
48         'salary_exp' : fields.float("Salary Expected", digits_compute=dp.get_precision('Account')),
49         'salary_exp_avg' : fields.float("Avg. Expected Salary", group_operator="avg", digits_compute=dp.get_precision('Account')),
50         'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
51         'available': fields.float("Availability"),
52         'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg",
53                                        help="Number of Days to close the project issue"),
54         'last_stage_id': fields.many2one ('hr.recruitment.stage', 'Last Stage'),
55     }
56     
57     def init(self, cr):
58         tools.drop_view_if_exists(cr, 'hr_recruitment_report')
59         cr.execute("""
60             create or replace view hr_recruitment_report as (
61                  select
62                      min(s.id) as id,
63                      s.create_date as date_create,
64                      date(s.date_closed) as date_closed,
65                      s.date_last_stage_update as date_last_stage_update,
66                      s.partner_id,
67                      s.company_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                      s.last_stage_id,
76                      sum(salary_proposed) as salary_prop,
77                      (sum(salary_proposed)/count(*)) as salary_prop_avg,
78                      sum(salary_expected) as salary_exp,
79                      (sum(salary_expected)/count(*)) as salary_exp_avg,
80                      extract('epoch' from (s.write_date-s.create_date))/(3600*24) as delay_close,
81                      count(*) as nbr
82                  from hr_applicant s
83                  group by
84                      s.date_open,
85                      s.create_date,
86                      s.write_date,
87                      s.date_closed,
88                      s.date_last_stage_update,
89                      s.partner_id,
90                      s.company_id,
91                      s.user_id,
92                      s.stage_id,
93                      s.last_stage_id,
94                      s.type_id,
95                      s.priority,
96                      s.job_id,
97                      s.department_id
98             )
99         """)
100
101 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
102
103