26ac6a1396eea73919e8c3b0197eff28b7efcdc0
[odoo/odoo.git] / addons / hr_recruitment / hr_recruitment.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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 osv import fields,osv,orm
23
24 AVAILABLE_STATES = [
25     ('draft','New'),
26     ('open','In Progress'),
27     ('cancel', 'Refused'),
28     ('done', 'Hired'),
29     ('pending','Pending')
30 ]
31
32 AVAILABLE_PRIORITIES = [
33     ('5','Not Good'),
34     ('4','On Average'),
35     ('3','Good'),
36     ('2','Very Good'),
37     ('1','Excellent')
38 ]
39
40
41 class hr_applicant(osv.osv):
42     _name = "hr.applicant"
43     _description = "Applicant Cases"
44     _order = "id desc"
45     _inherit ='crm.case'
46     _columns = {
47         'date_closed': fields.datetime('Closed', readonly=True),
48         'date': fields.datetime('Date'),
49         'priority': fields.selection(AVAILABLE_PRIORITIES, 'Appreciation'),
50         'job_id': fields.many2one('hr.job', 'Applied Job'),
51         'salary_proposed': fields.float('Proposed Salary'),
52         'salary_expected': fields.float('Expected Salary'),
53         'availability': fields.integer('Availability (Days)'),
54         'partner_name': fields.char("Applicant's Name", size=64),
55         'partner_phone': fields.char('Phone', size=32),
56         'partner_mobile': fields.char('Mobile', size=32),
57         'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"),
58         'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('section_id','=',section_id),('object_id.model', '=', 'hr.applicant')]"),
59         'department_id':fields.many2one('hr.department','Department'),
60         'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
61         'survey' : fields.related('job_id', 'survey_id', type='many2one', relation='survey', string='Survey'),
62         'response' : fields.integer("Response"),
63     }
64     
65     def action_print_survey(self, cr, uid, ids, context=None):
66         """
67         If response is available then print this response otherwise print survey form(print template of the survey).
68
69         @param self: The object pointer
70         @param cr: the current row, from the database cursor,
71         @param uid: the current user’s ID for security checks,
72         @param ids: List of Survey IDs
73         @param context: A standard dictionary for contextual values
74         @return : Dictionary value for print survey form.
75         """
76         if not context:
77             context = {}
78         datas = {}
79         record = self.read(cr, uid, ids, ['survey', 'response'])
80         page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
81         report = {}
82         if record:
83             datas['ids'] = [record[0]['survey'][0]]
84             response_id = record[0]['response']
85             if response_id:
86                 context.update({'survey_id': datas['ids'], 'response_id' : [response_id], 'response_no':0,})
87                 datas['form'] = page_setting
88                 datas['model'] = 'survey.print.answer'
89                 report = {
90                     'type': 'ir.actions.report.xml',
91                     'report_name': 'survey.browse.response',
92                     'datas': datas,
93                     'nodestroy': True,
94                     'context' : context
95                 }
96             else:
97                 datas['form'] = page_setting
98                 datas['model'] = 'survey.print'
99                 report = {
100                     'type': 'ir.actions.report.xml',
101                     'report_name': 'survey.form',
102                     'datas': datas,
103                     'nodestroy':True,
104                     'context' : context
105                 }
106         return report
107     
108 hr_applicant()
109
110 class hr_job(osv.osv):
111     _inherit = "hr.job"
112     _name = "hr.job"
113     _columns = {
114         'survey_id': fields.many2one('survey', 'Survey'),
115     }
116
117 hr_job()