如何向自定义模型添加many2one关系

时间:2022-10-05 12:45:58

I try to add to an order a new attribute that relates to a custom many2one relation. The goal is to choose for each order one specific contract condition. I would like to manage those contract conditions in the database, so that I can easily manage them.

我尝试向订单添加一个与自定义many2one关系相关的新属性。目标是为每个订单选择一个特定的合同条件。我想在数据库中管理这些合同条件,以便我可以轻松地管理它们。

I sort of got far. I can edit those conditions, assign them and get them properly printed. However, on the sale-order form they get displayed in a weird way. Instead of the descirption-text of the condition, I see sort of a description of the associated record. So my question is, how to show the proper description attribute. See here:

我有点远。我可以编辑这些条件,分配它们并正确打印它们。但是,在销售订单表格中,它们以奇怪的方式显示。我没有看到条件的描述文本,而是看到了相关记录的描述。所以我的问题是,如何显示正确的描述属性。看这里:

如何向自定义模型添加many2one关系

Below I added a few screenshots that explain the type of changes that I did.

下面我添加了一些截图,解释了我所做的更改类型。

custom data structure: 如何向自定义模型添加many2one关系

自定义数据结构:

many2one relation from sale.order to custom structure: 如何向自定义模型添加many2one关系

从sale.order到自定义结构的许多关系:

views for custom structure: 如何向自定义模型添加many2one关系

自定义结构的视图:

reference from order form, which is displayed oddly 如何向自定义模型添加many2one关系

订单表格的参考,奇怪地显示

2 个解决方案

#1


2  

Define _rec_name into your class.

将_rec_name定义到您的类中。

_rec_name = 'x_condition'

It's because it will looking for name field into your custom model when you add many2one field for that model, when you define _rec_name it will take that field value.

这是因为当您为该模型添加many2one字段时,它会在您的自定义模型中查找名称字段,当您定义_rec_name时,它将获取该字段值。

#2


0  

Try to use x_name instead of x_condition for field name

尝试使用x_name而不是x_condition作为字段名称

#1


2  

Define _rec_name into your class.

将_rec_name定义到您的类中。

_rec_name = 'x_condition'

It's because it will looking for name field into your custom model when you add many2one field for that model, when you define _rec_name it will take that field value.

这是因为当您为该模型添加many2one字段时,它会在您的自定义模型中查找名称字段,当您定义_rec_name时,它将获取该字段值。

#2


0  

Try to use x_name instead of x_condition for field name

尝试使用x_name而不是x_condition作为字段名称