1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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,orm
23 from tools.translate import _
27 ('open','In Progress'),
28 ('cancel', 'Refused'),
33 AVAILABLE_PRIORITIES = [
42 class hr_applicant(osv.osv):
43 _name = "hr.applicant"
44 _description = "Applicant Cases"
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"),
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"""
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]})
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"""
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]})
102 def action_makeMeeting(self, cr, uid, ids, context=None):
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
111 @return : Dictionary value for created Meeting view
114 for opp in self.browse(cr, uid, ids):
115 data_obj = self.pool.get('ir.model.data')
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')
124 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
126 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
128 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
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
139 'name': _('Meetings'),
140 'domain': "[('user_id','=',%s)]" % (uid),
143 'view_mode': 'calendar,form,tree',
144 'res_model': 'crm.meeting',
146 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
147 'type': 'ir.actions.act_window',
148 'search_view_id': res['res_id'],
153 def action_print_survey(self, cr, uid, ids, context=None):
155 If response is available then print this response otherwise print survey form(print template of the survey).
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.
167 record = self.read(cr, uid, ids, ['survey', 'response'])
168 page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
171 datas['ids'] = [record[0]['survey'][0]]
172 response_id = record[0]['response']
174 context.update({'survey_id': datas['ids'], 'response_id' : [response_id], 'response_no':0,})
175 datas['form'] = page_setting
176 datas['model'] = 'survey.print.answer'
178 'type': 'ir.actions.report.xml',
179 'report_name': 'survey.browse.response',
185 datas['form'] = page_setting
186 datas['model'] = 'survey.print'
188 'type': 'ir.actions.report.xml',
189 'report_name': 'survey.form',
198 class hr_job(osv.osv):
202 'survey_id': fields.many2one('survey', 'Survey'),