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 ##############################################################################
23 from osv import fields, osv
25 class res_partner_contact(osv.osv):
26 _name = "res.partner.contact"
27 _description = "res.partner.contact"
29 def _title_get(self,cr, user, context={}):
30 obj = self.pool.get('res.partner.title')
31 ids = obj.search(cr, user, [])
32 res = obj.read(cr, user, ids, ['shortcut', 'name','domain'], context)
33 res = [(r['shortcut'], r['name']) for r in res if r['domain']=='contact']
37 'name': fields.char('Last Name', size=30,required=True),
38 'first_name': fields.char('First Name', size=30),
39 'mobile':fields.char('Mobile',size=30),
40 'title': fields.selection(_title_get, 'Title'),
41 'website':fields.char('Website',size=120),
42 'lang_id':fields.many2one('res.lang','Language'),
43 'job_ids':fields.one2many('res.partner.job','contact_id','Functions and Addresses'),
44 'country_id':fields.many2one('res.country','Nationality'),
45 'birthdate':fields.date('Birth Date'),
46 'active' : fields.boolean('Active'),
47 'partner_id':fields.related('job_ids','address_id','partner_id',type='many2one', relation='res.partner', string='Main Employer'),
48 'function_id':fields.related('job_ids','function_id',type='many2one', relation='res.partner.function', string='Main Function'),
49 'job_id':fields.related('job_ids',type='many2one', relation='res.partner.job', string='Main Job'),
50 'email': fields.char('E-Mail', size=240),
51 'comment' : fields.text('Notes', translate=True),
52 'photo' : fields.binary('Image'),
56 'active' : lambda *a: True,
59 _order = "name,first_name"
61 def name_get(self, cr, user, ids, context={}):
62 #will return name and first_name.......
66 for r in self.read(cr, user, ids, ['name','first_name','title']):
67 addr = r['title'] and str(r['title'])+" " or ''
68 addr += r.get('name', '')
69 if r['name'] and r['first_name']:
71 addr += (r.get('first_name', '') or '')
72 res.append((r['id'], addr))
76 class res_partner_address(osv.osv):
78 #overriding of the name_get defined in base in order to remove the old contact name
79 def name_get(self, cr, user, ids, context={}):
83 for r in self.read(cr, user, ids, ['zip','city','partner_id', 'street']):
84 if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
85 res.append((r['id'], r['partner_id'][1]))
88 addr += "%s %s %s" % ( r.get('street', '') or '', r.get('zip', '') or '', r.get('city', '') or '' )
89 res.append((r['id'], addr.strip() or '/'))
92 _name = 'res.partner.address'
93 _inherit='res.partner.address'
94 _description ='Partner Address'
96 'job_id':fields.related('job_ids','contact_id','job_id',type='many2one', relation='res.partner.job', string='Main Job'),
97 'job_ids':fields.one2many('res.partner.job', 'address_id', 'Contacts'),
101 class res_partner_job(osv.osv):
103 def name_get(self, cr, uid, ids, context={}):
107 for r in self.browse(cr, uid, ids):
108 funct = r.function_id and (", " + r.function_id.name) or ""
109 res.append((r.id, self.pool.get('res.partner.contact').name_get(cr, uid, [r.contact_id.id])[0][1] + funct ))
112 def search(self, cr, user, args, offset=0, limit=None, order=None,
113 context=None, count=False):
115 if arg[0]=='address_id':
116 self._order = 'sequence_partner'
117 if arg[0]=='contact_id':
118 self._order = 'sequence_contact'
119 return super(res_partner_job,self).search(cr, user, args, offset, limit, order, context, count)
121 _name = 'res.partner.job'
122 _description ='Contact Partner Function'
123 _order = 'sequence_contact'
125 'name': fields.related('address_id','partner_id', type='many2one', relation='res.partner', string='Partner', help="You may enter Address first,Partner will be linked automatically if any."),
126 'address_id':fields.many2one('res.partner.address','Address', help='Address which is linked to the Partner'),
127 'contact_id':fields.many2one('res.partner.contact','Contact', required=True, ondelete='cascade'),
128 'function_id': fields.many2one('res.partner.function','Partner Function', help="Function of this contact with this partner"),
129 'sequence_contact':fields.integer('Contact Seq.',help='Order of importance of this address in the list of addresses of the linked contact'),
130 'sequence_partner':fields.integer('Partner Seq.',help='Order of importance of this job title in the list of job title of the linked partner'),
131 'email': fields.char('E-Mail', size=240, help="Job E-Mail"),
132 'phone': fields.char('Phone', size=64, help="Job Phone no."),
133 'fax': fields.char('Fax', size=64, help="Job FAX no."),
134 'extension': fields.char('Extension', size=64, help='Internal/External extension phone number'),
135 'other': fields.char('Other', size=64, help='Additional phone field'),
136 'date_start' : fields.date('Date Start',help="Start date of job(Joining Date)"),
137 'date_stop' : fields.date('Date Stop', help="Last date of job"),
138 'state' : fields.selection([('past', 'Past'),('current', 'Current')], 'State', required=True, help="Status of Address"),
142 'sequence_contact' : lambda *a: 0,
143 'state' : lambda *a: 'current',
148 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: