Python odoo-多个字段的显示名称一个字段组合两个字段

Python odoo-多个字段的显示名称一个字段组合两个字段,python,python-2.7,odoo-8,odoo,Python,Python 2.7,Odoo 8,Odoo,在我的模块中,我有以下多个字段: 'xx\u insurance\u type':fields.manyOne('xx.insurance.type',string='insurance') 其中,xx.保险类型如下: class InsuranceType(osv.Model): _name='xx.insurance.type' _columns = { 'name' : fields.char(size=128, string = 'Name'),

在我的模块中,我有以下多个字段:
'xx\u insurance\u type':fields.manyOne('xx.insurance.type',string='insurance')

其中,
xx.保险类型
如下:

class InsuranceType(osv.Model):
    _name='xx.insurance.type'

    _columns = {
        'name' : fields.char(size=128, string = 'Name'),
        'sale_ids': fields.one2many('sale.order', 'xx_insurance_type', string = 'Sale orders'),
        'insurance_percentage' : fields.float('Insurance cost in %')
    }
def get_name(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
         percentage = record.insurance_percentage
         res.append(record.id, name + " - " + percentage + "%")
    return res
我知道manyOne字段以name字段作为其显示名称,但我希望它使用
name
insurance\u percentage
的组合,形式为
name+“-”+insurance\u percentage+“%”

我读到最好覆盖
get\u name
方法,因此我尝试了以下方法:

class InsuranceType(osv.Model):
    _name='xx.insurance.type'

    _columns = {
        'name' : fields.char(size=128, string = 'Name'),
        'sale_ids': fields.one2many('sale.order', 'xx_insurance_type', string = 'Sale orders'),
        'insurance_percentage' : fields.float('Insurance cost in %')
    }
def get_name(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
         percentage = record.insurance_percentage
         res.append(record.id, name + " - " + percentage + "%")
    return res
并将其放在ÌnsuranceType`类中。 因为什么都没发生:
我必须把它放在包含字段的主类中吗?如果是这样,是否还有其他方法可以这样做,因为这可能也会更改其他多个One字段的显示方式?

如果您不想更改与型号
xx.insurance.type
相关的其他
多个One
字段的显示名称,您可以在XML视图中将上下文添加到要修改其显示名称的
manyOne

<field name="xx_insurance_type" context="{'special_display_name': True}"/>

该方法的名称是
name\u get
而不是
get\u name
,不幸的是,它还设置了记录的名称,因此它会弄乱我的数据库。最伟大的答案之一感谢您提供的信息最简单的答案在Yen Van Ginneken coment中: