many2one field by default displays either
name field or the field which is defined in
_rec_name. If you want to display value of other fields then you need to override
name_get method in your object.
For example I want to display two fields (name, name2) in my many2one field:
def name_get(self, cr, uid, ids, context=None): if not len(ids): return  res = [(r['id'], r['name'] and '%s [%s]' % (r['name'], r['name2']) or r['name'] ) for r in self.read(cr, uid, ids, ['name', 'name2'], context=context) ] return res
You may refer: ORM Method: name_get.
You need to override the name_get function for the class.
By default this function returns either the value of name or the value of the field specified in _rec_name.
Product Category gets composite values this way.
There is a function, overriding the default, at
def name_get(self, cr, uid, ids, context=None): if isinstance(ids, (list, tuple)) and not len(ids): return  if isinstance(ids, (long, int)): ids = [ids] reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) res =  for record in reads: name = record['name'] if record['parent_id']: name = record['parent_id']+' / '+name res.append((record['id'], name)) return res
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 12/25/13, 9:52 AM|
|Seen: 2960 times|
|Last updated: 3/16/15, 8:10 AM|