如果您不想更改
many2one与模型相关的其余部分的显示名称,则
xx.insurance.type可以在XML视图中向
many2one要修改其显示名称的上下文中添加一个上下文:
<field name="xx_insurance_type" context="{'special_display_name': True}"/>然后,在您的
name_get函数中:
def name_get(self, cr, uid, ids, context=None): if context is None: context = {} if isinstance(ids, (int, long)): ids = [ids] res = [] if context.get('special_display_name', False): for record in self.browse(cr, uid, ids, context=context): name = record.name percentage = record.insurance_percentage res.append(record.id, name + " - " + percentage + "%") else: # Do a for and set here the standard display name, for example if the standard display name were name, you should do the next for for record in self.browse(cr, uid, ids, context=context): res.append(record.id, record.name) return res


