~qtheuret/unifield-addons/ref_addons

« back to all changes in this revision

Viewing changes to hr_recruitment/wizard/hr_recruitment_create_partner_job.py

  • Committer: Quentin THEURET
  • Date: 2014-03-05 12:14:13 UTC
  • mfrom: (4612.2.2 unifield-addons)
  • Revision ID: qt@tempo-consulting.fr-20140305121413-qgiq1n9ujvojbtmv
Merge latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
 
#    $Id$
7
 
#
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.
12
 
#
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.
17
 
#
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/>.
20
 
#
21
 
##############################################################################
22
 
from osv import osv, fields
23
 
from tools.translate import _
24
 
 
25
 
class hr_recruitment_partner_create(osv.osv_memory):
26
 
    _name = 'hr.recruitment.partner.create'
27
 
    _description = 'Create Partner from job application'
28
 
    _columns = {
29
 
        'close': fields.boolean('Close job request'),
30
 
                }
31
 
 
32
 
    def view_init(self, cr , uid , fields_list, context=None):
33
 
        case_obj = self.pool.get('hr.applicant')
34
 
        if context is None:
35
 
            context = {}
36
 
        for case in case_obj.browse(cr, uid, context['active_ids'], context=context):
37
 
            if case.partner_id:
38
 
                raise osv.except_osv(_('Error !'),
39
 
                    _('A partner is already defined on this job request.'))
40
 
        pass
41
 
 
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
 
        contact_obj = self.pool.get('res.partner.address')
46
 
        case_obj = self.pool.get('hr.applicant')
47
 
 
48
 
        if context is None:
49
 
            context = {}
50
 
        data = self.read(cr, uid, ids, [], context=context)[0]
51
 
        result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
52
 
        res = mod_obj.read(cr, uid, result, ['res_id'], context=context)
53
 
 
54
 
        for case in case_obj.browse(cr, uid, context['active_ids'], context=context):
55
 
            partner_id = partner_obj.search(cr, uid, [('name', '=', case.partner_name or case.name)], context=context)
56
 
            if partner_id:
57
 
                raise osv.except_osv(_('Error !'),_('A partner is already existing with the same name.'))
58
 
            partner_id = partner_obj.create(cr, uid, {
59
 
                'name': case.partner_name or case.name,
60
 
                'user_id': case.user_id.id,
61
 
                'comment': case.description,
62
 
            }, context=context)
63
 
            contact_id = contact_obj.create(cr, uid, {
64
 
                'partner_id': partner_id,
65
 
                'name': case.partner_name,
66
 
                'phone': case.partner_phone,
67
 
                'mobile': case.partner_mobile,
68
 
                'email': case.email_from
69
 
            }, context=context)
70
 
 
71
 
            case_obj.write(cr, uid, case.id, {
72
 
                'partner_id': partner_id,
73
 
                'partner_address_id': contact_id
74
 
            }, context=context)
75
 
        if data['close']:
76
 
            case_obj.case_close(cr, uid, context['active_ids'])
77
 
 
78
 
        return {
79
 
            'domain': "[]",
80
 
            'view_type': 'form',
81
 
            'view_mode': 'form,tree',
82
 
            'res_model': 'res.partner',
83
 
            'res_id': int(partner_id),
84
 
            'view_id': False,
85
 
            'type': 'ir.actions.act_window',
86
 
            'search_view_id': res['res_id']
87
 
                }
88
 
 
89
 
hr_recruitment_partner_create()
90
 
 
91
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'