1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import fields,osv
23 from hr_recruitment import hr_recruitment
24 from decimal_precision import decimal_precision as dp
30 ('cancel', 'Refused'),
35 class hr_recruitment_report(osv.osv):
36 _name = "hr.recruitment.report"
37 _description = "Recruitments Statistics"
41 def _get_data(self, cr, uid, ids, field_name, arg, context={}):
43 """ @param cr: the current row, from the database cursor,
44 @param uid: the current user’s ID for security checks,
45 @param ids: List of case and section Data’s IDs
46 @param context: A standard dictionary for contextual values """
51 #TODO: Calculate avg_answer, perc_done, perc_cancel
55 'user_id':fields.many2one('res.users', 'User', readonly=True),
56 'nbr': fields.integer('# of Cases', readonly=True),
57 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
58 'avg_answers': fields.function(_get_data, string='Avg. Answers', method=True, type="integer"),
59 'perc_done': fields.function(_get_data, string='%Done', method=True, type="float"),
60 'perc_cancel': fields.function(_get_data, string='%Cancel', method=True, type="float"),
61 'month':fields.selection([('01', 'January'), ('02', 'February'), \
62 ('03', 'March'), ('04', 'April'),\
63 ('05', 'May'), ('06', 'June'), \
64 ('07', 'July'), ('08', 'August'),\
65 ('09', 'September'), ('10', 'October'),\
66 ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
67 'company_id': fields.many2one('res.company', 'Company', readonly=True),
68 'day': fields.char('Day', size=128, readonly=True),
69 'year': fields.char('Year', size=4, readonly=True),
70 'date': fields.date('Date', readonly=True),
71 'date_closed': fields.date('Closed', readonly=True),
72 'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True),
73 'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage'),
74 'type_id': fields.many2one('hr.recruitment.degree', 'Degree'),
75 'department_id':fields.many2one('hr.department','Department',readonly=True),
76 'priority': fields.selection(hr_recruitment.AVAILABLE_PRIORITIES, 'Appreciation'),
77 'salary_prop' : fields.float("Salary Proposed", digits_compute=dp.get_precision('Account')),
78 'salary_prop_avg' : fields.float("Avg Salary Proposed", group_operator="avg", digits_compute=dp.get_precision('Account')),
79 'salary_exp' : fields.float("Salary Expected", digits_compute=dp.get_precision('Account')),
80 'partner_id': fields.many2one('res.partner', 'Partner',readonly=True),
81 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact Name',readonly=True),
82 'available' : fields.float("Availability"),
83 'delay_open': fields.float('Avg. Delay to Open', digits=(16,2), readonly=True, group_operator="avg",
84 help="Number of Days to close the project issue"),
85 'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg",
86 help="Number of Days to close the project issue"),
90 tools.drop_view_if_exists(cr, 'hr_recruitment_report')
92 create or replace view hr_recruitment_report as (
95 date_trunc('day',s.create_date) as date,
96 date_trunc('day',s.date_closed) as date_closed,
97 to_char(s.create_date, 'YYYY') as year,
98 to_char(s.create_date, 'MM') as month,
99 to_char(s.create_date, 'YYYY-MM-DD') as day,
103 s.partner_address_id,
107 sum(s.availability) as available,
111 sum(salary_proposed) as salary_prop,
112 (sum(salary_proposed)/count(*)) as salary_prop_avg,
113 sum(salary_expected) as salary_exp,
114 extract('epoch' from (s.date_open-s.create_date))/(3600*24) as delay_open,
115 extract('epoch' from (s.date_closed-s.create_date))/(3600*24) as delay_close,
119 to_char(s.create_date, 'YYYY'),
120 to_char(s.create_date, 'MM'),
121 to_char(s.create_date, 'YYYY-MM-DD') ,
122 date_trunc('day',s.create_date),
123 date_trunc('day',s.date_closed),
129 s.partner_address_id,
139 hr_recruitment_report()
141 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: