如何在odoo中的一个下拉框中显示名称和日期

时间:2016-12-29 10:30:31

标签: html user-interface odoo-8

我需要在下拉列表中显示姓名和日期以选择特定的人

示例:

我有两个同名的名字'Silpa'。当我试图选择时,两个名字都会在下拉列表中显示。所以我需要显示该人的出生日期及其姓名。

2 个答案:

答案 0 :(得分:0)

尝试使用函数字段,如下面的代码。

功能声明

def _combine(self, cr, uid, ids, field_name, arg, context=None):
    values = {}
    #here cur_obj gets the value from the current object. 
    #But this could be the object in which you have saved your data.
    cur_obj=self.browse(cr, uid, ids, context=context)
    code = cur_obj.name
    dob = cur_obj.dob
    for id in ids:
        rec = self.browse(cr, uid, [id], context=context)[0]
        values[id] = {}
        values[id] = '%s -- %s' % (code , dob)
    return values

实地宣言

_columns = {
         'field_name': fields.function(_combine, type='selection'),
        }

答案 1 :(得分:0)

使用name_get功能

示例:

def name_get(self, cr, uid, ids, context=None):
    result= []
    if not all(ids):
        return result
    for pl in self.browse(cr, uid, ids, context=context):
        code = pl.seq
        name = pl.name.name
        name = '[%s] %s' % (code,name)
        result.append((pl.id,name))
    return result