How to display name_get() in openerp?

719 Views Asked by At

I have tried to display name , description fields for the many to one field. The code is as follows, help me to resolve this problem

from openerp.osv import orm, fields
class post_branch(orm.Model):
    _name = "branches"


    _columns = {
        'name':fields.char("Name", size=50, required=True),
        'description':fields.text("Description",),
        'emp_id':fields.one2many("man", "branch_id", "lines")
#         'emp_id':fields.many2one("man","lines",required=True)
    }


    def name_get(self, cr, uid, ids, context=None):
        res = []
        for r in self.read(cr, uid, ids['name', 'description']):
            res.append(r['id'], '%s,%s' (r['name'],r['description']))
        return res
# def name_des(self, cr,uid, context=None):
#     obj_name=self.pool.get('')
1

There are 1 best solutions below

8
On BEST ANSWER

Try following,

def name_get(self, cr, uid, ids, context=None):
    res = []
    if not ids:
        return res
    for r in self.browse(cr, uid, ids, context=context):
        name = str(r.name)  + ',' + str(r.description or '')
        res.append((r.id, name))
    return res