[IMP] hr_evaluation,hr_recruitment :- improve print survey method.
[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 from tools.translate import _
24
25 AVAILABLE_STATES = [
26     ('draft','New'),
27     ('open','In Progress'),
28     ('cancel', 'Refused'),
29     ('done', 'Hired'),
30     ('pending','Pending')
31 ]
32
33 AVAILABLE_PRIORITIES = [
34     ('5','Not Good'),
35     ('4','On Average'),
36     ('3','Good'),
37     ('2','Very Good'),
38     ('1','Excellent')
39 ]
40
41
42 class hr_applicant(osv.osv):
43     _name = "hr.applicant"
44     _description = "Applicant Cases"
45     _order = "id desc"
46     _inherit ='crm.case'
47     _columns = {
48         'date_closed': fields.datetime('Closed', readonly=True),
49         'date': fields.datetime('Date'),
50         'priority': fields.selection(AVAILABLE_PRIORITIES, 'Appreciation'),
51         'job_id': fields.many2one('hr.job', 'Applied Job'),
52         'salary_proposed': fields.float('Proposed Salary'),
53         'salary_expected': fields.float('Expected Salary'),
54         'availability': fields.integer('Availability (Days)'),
55         'partner_name': fields.char("Applicant's Name", size=64),
56         'partner_phone': fields.char('Phone', size=32),
57         'partner_mobile': fields.char('Mobile', size=32),
58         'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('object_id.model', '=', 'hr.applicant')]"),
59         'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('object_id.model', '=', 'hr.applicant')]"),
60         'department_id':fields.many2one('hr.department','Department'),
61         'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
62         'survey' : fields.related('job_id', 'survey_id', type='many2one', relation='survey', string='Survey'),
63         'response' : fields.integer("Response"),
64     }
65
66     def stage_previous(self, cr, uid, ids, context=None):
67         """This function computes previous stage for case from its current stage
68              using available stage for that case type 
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 case IDs
73         @param context: A standard dictionary for contextual values"""
74         if not context:
75             context = {}
76         for case in self.browse(cr, uid, ids, context):
77             section = (case.section_id.id or False)
78             st = case.stage_id.id  or False
79             stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [])
80             if st and stage_ids.index(st):
81                 self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)-1]})
82         return True
83
84     def stage_next(self, cr, uid, ids, context=None):
85         """This function computes next stage for case from its current stage
86              using available stage for that case type 
87         @param self: The object pointer
88         @param cr: the current row, from the database cursor,
89         @param uid: the current user’s ID for security checks,
90         @param ids: List of case IDs
91         @param context: A standard dictionary for contextual values"""
92         if not context:
93             context = {}
94         for case in self.browse(cr, uid, ids, context):
95             section = (case.section_id.id or False)
96             st = case.stage_id.id  or False
97             stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [])
98             if st and len(stage_ids) != stage_ids.index(st)+1:
99                 self.write(cr, uid, [case.id], {'stage_id': stage_ids[stage_ids.index(st)+1]})
100         return True
101
102     def action_makeMeeting(self, cr, uid, ids, context=None):
103         """
104         This opens Meeting's calendar view to schedule meeting on current Opportunity
105         @param self: The object pointer
106         @param cr: the current row, from the database cursor,
107         @param uid: the current user’s ID for security checks,
108         @param ids: List of Opportunity to Meeting IDs
109         @param context: A standard dictionary for contextual values
110
111         @return : Dictionary value for created Meeting view
112         """
113         value = {}
114         for opp in self.browse(cr, uid, ids):
115             data_obj = self.pool.get('ir.model.data')
116
117             # Get meeting views
118             result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
119             res = data_obj.read(cr, uid, result, ['res_id'])
120             id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
121             id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
122             id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
123             if id1:
124                 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
125             if id2:
126                 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
127             if id3:
128                 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
129
130             context = {
131                 'default_opportunity_id': opp.id,
132                 'default_partner_id': opp.partner_id and opp.partner_id.id or False,
133                 'default_section_id': opp.section_id and opp.section_id.id or False,
134                 'default_email_from': opp.email_from,
135                 'default_state': 'open',
136                 'default_name': opp.name
137             }
138             value = {
139                 'name': _('Meetings'),
140                 'domain': "[('user_id','=',%s)]" % (uid),
141                 'context': context,
142                 'view_type': 'form',
143                 'view_mode': 'calendar,form,tree',
144                 'res_model': 'crm.meeting',
145                 'view_id': False,
146                 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
147                 'type': 'ir.actions.act_window',
148                 'search_view_id': res['res_id'],
149                 'nodestroy': True
150             }
151         return value
152
153     def action_print_survey(self, cr, uid, ids, context=None):
154         """
155         If response is available then print this response otherwise print survey form(print template of the survey).
156
157         @param self: The object pointer
158         @param cr: the current row, from the database cursor,
159         @param uid: the current user’s ID for security checks,
160         @param ids: List of Survey IDs
161         @param context: A standard dictionary for contextual values
162         @return : Dictionary value for print survey form.
163         """
164         if not context:
165             context = {}
166         datas = {}
167         record = self.browse(cr, uid, ids, context)
168         record = record and record[0]
169         page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
170         report = {}
171         if record:
172             datas['ids'] = [record.survey.id]
173             response_id = record.response
174             if response_id:
175                 context.update({'survey_id': datas['ids'], 'response_id' : [response_id], 'response_no':0,})
176                 datas['form'] = page_setting
177                 datas['model'] = 'survey.print.answer'
178                 report = {
179                     'type': 'ir.actions.report.xml',
180                     'report_name': 'survey.browse.response',
181                     'datas': datas,
182                     'nodestroy': True,
183                     'context' : context
184                 }
185             else:
186                 datas['form'] = page_setting
187                 datas['model'] = 'survey.print'
188                 report = {
189                     'type': 'ir.actions.report.xml',
190                     'report_name': 'survey.form',
191                     'datas': datas,
192                     'nodestroy':True,
193                     'context' : context
194                 }
195         return report
196     
197 hr_applicant()
198
199 class hr_job(osv.osv):
200     _inherit = "hr.job"
201     _name = "hr.job"
202     _columns = {
203         'survey_id': fields.many2one('survey', 'Survey'),
204     }
205
206 hr_job()