Search code examples
odooopenerp-8

How to add a many2one relation to a custom model


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.

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:

Problem

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

custom data structure: custom data structure

many2one relation from sale.order to custom structure: many2one relation from sale.order to custom structure

views for custom structure: views for custom structure

reference from order form, which is displayed oddly reference from order form, which is displayed oddly


Solution

  • Define _rec_name into your class.

    _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.