如何让同一个字段在不同的view中显示不同的内容

many2one 字段默认显示 对象的name字段,

但也可以定义name_get方法显示不同的内容

如res.partner 对象可以根据 context 内容是否显示 客户的地址,职位,email 等其他信息,

例如下面的代码中 可以显示客户的 地址信息。 if context.get('show_address').

    def name_get(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        if isinstance(ids, (int, long)):
            ids = [ids]
        res = []
        for record in self.browse(cr, uid, ids, context=context):
            name = record.name
            if record.parent_id and not record.is_company:
                name =  "%s, %s" % (record.parent_id.name, name)
            if context.get('show_address'):
                name = name + "
" + self._display_address(cr, uid, record, without_company=True, context=context)
                name = name.replace('

','
')
                name = name.replace('

','
')
            if context.get('show_email') and record.email:
                name = "%s <%s>" % (name, record.email)
            res.append((record.id, name))
        return res

  

~~~~~~~ 需要odoo 实施,二开,培训 等服务 QQ:190170444
原文地址:https://www.cnblogs.com/alangwansui/p/3507236.html