跳至内容
菜单
此问题已终结
2 回复
8529 查看

Hello,

is there a way to show another field instead of rec name in many2one field without changing the rec name?

i mean to keep the rec_name as it is but show another field in a specific form?

Thanks    

形象
丢弃
最佳答案

To display another field in specific form only you need to add context to xml of the Many2One field Then you will override name_get method in the model of Many2one field as below 


def name_get(self):
if context is None:
    context = {}
res = []
if context.get('special_display_name', False):
    for record in self:
        res.append(record.id, rec.YOurFieldYouWantToShow)
else:
    for record in self:
        res.append(record.id, record.name)
return res


please check the below links for 

https://stackoverflow.com/questions/31724556/odoo-display-name-of-many2one-field-combination-of-2-fields


形象
丢弃

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

最佳答案

Hi,

Try use use name_get method for this
For more reference check the following blog.

https://www.cybrosys.com/blog/how-to-use-of-name-get-function-in-odoo

Regards

形象
丢弃
相关帖文 回复 查看 活动
3
10月 20
5395
2
4月 25
7107
2
2月 25
5865
1
12月 24
1425
2
6月 24
6330