如何在openerp中显示name_get()?

时间:2015-06-25 06:03:58

标签: openerp-7

我试图显示多对一字段的名称,描述字段。代码如下,帮我解决这个问题

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 个答案:

答案 0 :(得分:1)

尝试以下,

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