1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
25 class hr_recruitment_partner_create(osv.osv_memory):
26 _name = 'hr.recruitment.partner.create'
27 _description = 'Create Partner from job application'
29 'close': fields.boolean('Close job request'),
32 def view_init(self, cr , uid , fields_list, context=None):
33 case_obj = self.pool.get('hr.applicant')
36 for case in case_obj.browse(cr, uid, context['active_ids'], context=context):
38 raise osv.except_osv(_('Error !'),
39 _('A contact is already defined on this job request.'))
42 def make_order(self, cr, uid, ids, context=None):
43 mod_obj = self.pool.get('ir.model.data')
44 partner_obj = self.pool.get('res.partner')
45 case_obj = self.pool.get('hr.applicant')
49 data = self.read(cr, uid, ids, [], context=context)[0]
50 result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
51 res = mod_obj.read(cr, uid, result, ['res_id'], context=context)
53 for case in case_obj.browse(cr, uid, context['active_ids'], context=context):
54 partner_id = partner_obj.search(cr, uid, [('name', '=', case.partner_name or case.name)], context=context)
56 raise osv.except_osv(_('Error !'),_('A contact is already existing with the same name.'))
57 partner_id = partner_obj.create(cr, uid, {
58 'name': case.partner_name or case.name,
59 'user_id': case.user_id.id,
60 'comment': case.description,
61 'phone': case.partner_phone,
62 'mobile': case.partner_mobile,
63 'email': case.email_from
66 case_obj.write(cr, uid, [case.id], {
67 'partner_id': partner_id,
70 case_obj.case_close(cr, uid, context['active_ids'])
75 'view_mode': 'form,tree',
76 'res_model': 'res.partner',
77 'res_id': int(partner_id),
79 'type': 'ir.actions.act_window',
80 'search_view_id': res['res_id']
83 hr_recruitment_partner_create()
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: