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
28 ('cancel', 'Cancelled'),
33 class hr_recruitment_report(osv.osv):
34 _name = "hr.recruitment.report"
35 _description = "Recruitments Statistics"
39 def _get_data(self, cr, uid, ids, field_name, arg, context={}):
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 """
49 #TODO: Calculate avg_answer, perc_done, perc_cancel
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"),
88 tools.drop_view_if_exists(cr, 'hr_recruitment_report')
90 create or replace view hr_recruitment_report as (
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,
101 s.partner_address_id,
105 sum(s.availability) as available,
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,
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),
126 s.partner_address_id,
136 hr_recruitment_report()
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: