我需要两个不同的m2o字段来显示数据库中的不同名称。
我引用this并使用上下文进行注释,但是无法在name_get函数中获取上下文。
*。xml
<field name="car_no" context="{'special_display_name': 'carno'}"/>
<field name="processing_attache" context="{'special_display_name': 'process'}"/>
*。py
class A
car_no = fields.Many2one("yc.weight", string="car no")
processing_attache = fields.Many2one("yc.weight.details", "processing name")
class B
@api.multi
def name_get(self, context= None):
if context is None:
context={}
result = []
if context.get('special_display_name','carno'):
for record in self:
name = record.carno
result.append((record.id, name))
elif context.get('special_display_name','process'):
for record in self:
name = record.processing_id
result.append((record.id, name))
return result
非常感谢。