_name = "res.partner.contact"
_description = "Contact"
- def _title_get(self,cr, user, context={}):
- """
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param user: the current user,
- @param context: A standard dictionary for contextual values
- """
-
- obj = self.pool.get('res.partner.title')
- ids = obj.search(cr, user, [])
- res = obj.read(cr, user, ids, ['shortcut', 'name','domain'], context)
- res = [(r['shortcut'], r['name']) for r in res if r['domain']=='contact']
- return res
-
def _main_job(self, cr, uid, ids, fields, arg, context=None):
"""
@param self: The object pointer
@fields: Get Fields
@param context: A standard dictionary for contextual values
@param arg: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...]. """
+ res = dict.fromkeys(ids, False)
+ res_partner_job_obj = self.pool.get('res.partner.job')
+ all_job_ids = res_partner_job_obj.search(cr, uid, [])
+ all_job_names = dict(zip(all_job_ids, res_partner_job_obj.name_get(cr, uid, all_job_ids, context=context)))
- res = dict.fromkeys(ids, False)
- for contact in self.browse(cr, uid, ids, context):
+ for contact in self.browse(cr, uid, ids, context=context):
if contact.job_ids:
- res[contact.id] = contact.job_ids[0].name_get()[0]
+ res[contact.id] = all_job_names.get(contact.job_ids[0].id, False)
+
return res
_columns = {
- 'name': fields.char('Last Name', size=30,required=True),
- 'first_name': fields.char('First Name', size=30),
- 'mobile': fields.char('Mobile',size=30),
- 'title': fields.selection(_title_get, 'Title'),
- 'website': fields.char('Website',size=120),
- 'lang_id': fields.many2one('res.lang','Language'),
- 'job_ids': fields.one2many('res.partner.job','contact_id','Functions and Addresses'),
+ 'name': fields.char('Last Name', size=64, required=True),
+ 'first_name': fields.char('First Name', size=64),
+ 'mobile': fields.char('Mobile', size=64),
+ 'title': fields.many2one('res.partner.title','Title'),
+ 'website': fields.char('Website', size=120),
+ 'lang_id': fields.many2one('res.lang', 'Language'),
+ 'job_ids': fields.one2many('res.partner.job', 'contact_id', 'Functions and Addresses'),
'country_id': fields.many2one('res.country','Nationality'),
'birthdate': fields.date('Birth Date'),
- 'active': fields.boolean('Active', help="If the active field is set to true,\
+ 'active': fields.boolean('Active', help="If the active field is set to False,\
it will allow you to hide the partner contact without removing it."),
- 'partner_id': fields.related('job_ids','address_id','partner_id',type='many2one',\
+ 'partner_id': fields.related('job_ids', 'address_id', 'partner_id', type='many2one',\
relation='res.partner', string='Main Employer'),
- 'function_id': fields.related('job_ids','function_id',type='many2one', \
- relation='res.partner.function', string='Main Function'),
+ 'function': fields.related('job_ids', 'function', type='char', \
+ string='Main Function'),
'job_id': fields.function(_main_job, method=True, type='many2one',\
relation='res.partner.job', string='Main Job'),
'email': fields.char('E-Mail', size=240),
_order = "name,first_name"
- def name_get(self, cr, user, ids, context={}):
+ def name_get(self, cr, user, ids, context=None):
""" will return name and first_name.......
@param self: The object pointer
if not len(ids):
return []
res = []
- for r in self.read(cr, user, ids, ['name','first_name','title']):
- addr = r['title'] and str(r['title'])+" " or ''
- addr += r.get('name', '')
- if r['name'] and r['first_name']:
- addr += ' '
- addr += (r.get('first_name', '') or '')
- res.append((r['id'], addr))
+ for contact in self.browse(cr, user, ids, context=context):
+ _contact = ""
+ if contact.title:
+ _contact += "%s "%(contact.title.name)
+ _contact += contact.name or ""
+ if contact.name and contact.first_name:
+ _contact += " "
+ _contact += contact.first_name or ""
+ res.append((contact.id, _contact))
return res
-
+
+ def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=None):
+ if not args:
+ args = []
+ if context is None:
+ context = {}
+ if name:
+ ids = self.search(cr, uid, ['|',('name', operator, name),('first_name', operator, name)] + args, limit=limit, context=context)
+ else:
+ ids = self.search(cr, uid, args, limit=limit, context=context)
+ return self.name_get(cr, uid, ids, context=context)
+
res_partner_contact()
class res_partner_address(osv.osv):
#overriding of the name_get defined in base in order to remove the old contact name
- def name_get(self, cr, user, ids, context={}):
+ def name_get(self, cr, user, ids, context=None):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
if not len(ids):
return []
res = []
+ if context is None:
+ context = {}
for r in self.read(cr, user, ids, ['zip', 'city', 'partner_id', 'street']):
if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
res.append((r['id'], r['partner_id'][1]))
res_partner_address()
class res_partner_job(osv.osv):
-
- def name_get(self, cr, uid, ids, context={}):
+ def name_get(self, cr, uid, ids, context=None):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param ids: List of partner address’s IDs
@param context: A standard dictionary for contextual values
"""
+ if context is None:
+ context = {}
- if not len(ids):
+ if not ids:
return []
res = []
- for r in self.browse(cr, uid, ids):
- funct = r.function_id and (", " + r.function_id.name) or ""
- res.append((r.id, self.pool.get('res.partner.contact').name_get(cr, uid, \
- [r.contact_id.id])[0][1] + funct))
- return res
- def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
- """ search parnter job
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param user: the current user
- @param args: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...].
- @param offset: The Number of Results to Pass
- @param limit: The Number of Results to Return
- @param context: A standard dictionary for contextual values
- """
+ jobs = self.browse(cr, uid, ids, context=context)
+
+ contact_ids = [rec.contact_id.id for rec in jobs]
+ contact_names = dict(self.pool.get('res.partner.contact').name_get(cr, uid, contact_ids, context=context))
- job_ids = []
- for arg in args:
- if arg[0] == 'address_id':
- self._order = 'sequence_partner'
- elif arg[0] == 'contact_id':
- self._order = 'sequence_contact'
-
- contact_obj = self.pool.get('res.partner.contact')
- if arg[2] and not count:
- search_arg = ['|', ('first_name', 'ilike', arg[2]), ('name', 'ilike', arg[2])]
- contact_ids = contact_obj.search(cr, user, search_arg, offset=offset, limit=limit, order=order, context=context, count=count)
- if not contact_ids:
- continue
- contacts = contact_obj.browse(cr, user, contact_ids, context=context)
- for contact in contacts:
- job_ids.extend([item.id for item in contact.job_ids])
-
- res = super(res_partner_job,self).search(cr, user, args, offset=offset,\
- limit=limit, order=order, context=context, count=count)
- if job_ids:
- res = list(set(res + job_ids))
+ for r in jobs:
+ function_name = r.function
+ funct = function_name and (", " + function_name) or ""
+ res.append((r.id, contact_names.get(r.contact_id.id, '') + funct))
return res
'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."),
- 'address_id': fields.many2one('res.partner.address', 'Address', domain=[('partner_id', '=', name)], \
- help='Address which is linked to the Partner'),
+ 'address_id': fields.many2one('res.partner.address', 'Address', \
+ help='Address which is linked to the Partner'), # TO Correct: domain=[('partner_id', '=', name)]
'contact_id': fields.many2one('res.partner.contact','Contact', required=True, ondelete='cascade'),
- 'function_id': fields.many2one('res.partner.function','Partner Function', \
- help="Function of this contact with this partner"),
+ 'function': fields.char('Partner Function', size=64, help="Function of this contact with this partner"),
'sequence_contact': fields.integer('Contact Seq.',help='Order of\
importance of this address in the list of addresses of the linked contact'),
'sequence_partner': fields.integer('Partner Seq.',help='Order of importance\
'state': lambda *a: 'current',
}
+ def onchange_name(self, cr, uid, ids, address_id='', name='', context=None):
+ return {'value': {'address_id': address_id}, 'domain':{'partner_id':'name'}}
+
def onchange_partner(self, cr, uid, _, partner_id, context=None):
"""
@param self: The object pointer
partner_id = False
if address_id:
address = self.pool.get('res.partner.address')\
- .browse(cr, uid, address_id, context)
+ .browse(cr, uid, address_id, context=context)
partner_id = address.partner_id.id
return {'value': {'name': partner_id}}