1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 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 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 General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from osv import fields, osv
27 class res_partner_contact(osv.osv):
28 _name = "res.partner.contact"
29 _description = "res.partner.contact"
31 def _title_get(self,cr, user, context={}):
32 obj = self.pool.get('res.partner.title')
33 ids = obj.search(cr, user, [])
34 res = obj.read(cr, user, ids, ['shortcut', 'name','domain'], context)
35 res = [(r['shortcut'], r['name']) for r in res if r['domain']=='contact']
39 'name': fields.char('Last Name', size=30,required=True),
40 'first_name': fields.char('First Name', size=30),
41 'mobile':fields.char('Mobile',size=30),
42 'title': fields.selection(_title_get, 'Title'),
43 'website':fields.char('Website',size=120),
44 'lang_id':fields.many2one('res.lang','Language'),
45 'job_ids':fields.one2many('res.partner.job','contact_id','Functions and Addresses'),
46 'country_id':fields.many2one('res.country','Nationality'),
47 'birthdate':fields.date('Birth Date'),
48 'active' : fields.boolean('Active'),
49 'partner_id':fields.related('job_ids','address_id','partner_id',type='many2one', relation='res.partner', string='Main Employer'),
50 'function_id':fields.related('job_ids','function_id',type='many2one', relation='res.partner.function', string='Main Job'),
53 'active' : lambda *a: True,
55 def name_get(self, cr, user, ids, context={}):
56 #will return name and first_name.......
60 for r in self.read(cr, user, ids, ['name','first_name','title']):
61 addr = r['title'] and str(r['title'])+" " or ''
62 addr +=str(r['name'] or '')
63 if r['name'] and r['first_name']:
65 addr += str(r['first_name'] or '')
66 res.append((r['id'], addr))
70 class res_partner_address(osv.osv):
72 #overriding of the name_get defined in base in order to remove the old contact name
73 def name_get(self, cr, user, ids, context={}):
77 for r in self.read(cr, user, ids, ['zip','city','partner_id', 'street']):
78 if context.get('contact_display', 'contact')=='partner':
79 res.append((r['id'], r['partner_id'][1]))
82 addr += str(r['street'] or '') + ' ' + str(r['zip'] or '') + ' ' + str(r['city'] or '')
83 res.append((r['id'], addr.strip() or '/'))
86 _name = 'res.partner.address'
87 _inherit='res.partner.address'
88 _description ='Partner Address'
90 'job_ids':fields.one2many('res.partner.job', 'address_id', 'Contacts'),
91 'email': fields.related('job_ids', 'email', type='char', string='Default Email'),
95 class res_partner_job(osv.osv):
97 def name_get(self, cr, uid, ids, context={}):
101 for r in self.browse(cr, uid, ids):
102 res.append((r.id, self.pool.get('res.partner.contact').name_get(cr, uid, [r.contact_id.id])[0][1] +", "+ r.function_id.name))
105 def search(self, cr, user, args, offset=0, limit=None, order=None,
106 context=None, count=False):
108 if arg[0]=='address_id':
109 self._order = 'sequence_partner'
110 if arg[0]=='contact_id':
111 self._order = 'sequence_contact'
112 return super(res_partner_job,self).search(cr, user, args, offset, limit, order, context, count)
114 _name = 'res.partner.job'
115 _description ='Contact Job Title'
116 _order = 'sequence_contact'
118 'name': fields.related('address_id','partner_id', type='many2one', relation='res.partner', string='Partner'),
119 'address_id':fields.many2one('res.partner.address','Address', required=True),
120 'contact_id':fields.many2one('res.partner.contact','Contact', required=True),
121 'function_id': fields.many2one('res.partner.function','Job Title', required=True),
122 'sequence_contact':fields.integer('Sequence (Contact)',help='order of importance of this address in the list of addresses of the linked contact'),
123 'sequence_partner':fields.integer('Sequence (Partner)',help='order of importance of this job title in the list of job title of the linked partner'),
124 'email': fields.char('E-Mail', size=240),
125 'phone': fields.char('Phone', size=64),
126 'date_start' : fields.date('Date Start'),
127 'date_stop' : fields.date('Date Stop'),
128 'state' : fields.selection([('past', 'Past'),('current', 'Current')], 'State', required=True),
132 'sequence_contact' : lambda *a: 0,
133 'state' : lambda *a: 'current',
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: