How to change displayed value for relational field in Odoo
If you want to change the displayed value for a relational field in Odoo, the simplest way to do that is to define the “_rec_name” model’s attribute with the name of the field that you want to show.
For example, if you want to add new field “description” in the hr.employee.category model and you want that field to be shown as value for this model the code should look like:
class Employee(models.Model):
_inherit = 'hr.employee.category'
_rec_name = 'description'
description = fields.Char()
Now when you try to search for a new employee tag in the hr.employee view it will search by and display the description of the hr.employee.category model.
简而言之,简单的改变关系字段的显示,只需要将对应关系字段的model中_rec_name修改成需要显示的字段即可,这样之后的字段显示就是该字段的值。
From:http://www.odooninja.com/change-displayed-value-relational-field-odoo/
- 2019年12月07日11:01:20 更新
1. 默认显示name字段
2. 如果定义了_rec_name则显示对应的字段值
3. 可以重写name_get方法,通过传入的context来个性化显示字段内容
本文介绍如何在Odoo中自定义关系字段的显示值。通过简单地修改模型的_rec_name属性,可以轻松更改关系字段的显示内容。例如,可以在hr.employee.category模型中添加description字段,并将其设置为_rec_name,使得在hr.employee视图中搜索员工标签时显示description的内容。
1775

被折叠的 条评论
为什么被折叠?



