Reputation: 3750
hi when i use many2one function in odoo 12, and i have many2one relation between them (class) why i am getting a table name and id (that generate automatically looks like by odoo ORM)? and the other odoo example is not? how do i change this value?
here is how my code looked like, below is my model :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class SalesorderSalesorder(models.Model):
_name = 'salesorder.salesorder'
no_faktur = fields.Char(String='No Faktur', required=True)
kd_sales = fields.Many2one('res.users', string='Kode Sales')
details = fields.One2many('salesorderdetails','no_faktur','List Item')
class SalesOrderDetails(models.Model):
_name = 'salesorderdetails'
no_faktur = fields.Many2one('salesorder.salesorder')
kd_produk = fields.Many2one('ms_produk.ms_produk','Kode Product',required=True)
and here is how it looked like :
and i have these column in my database :
i want to show kd_produk instead of table name and id, how do i change this?
Upvotes: 1
Views: 974
Reputation: 833
Add _rec_name
as kd_produk
field in your ms_produk.ms_produk
model,
Eg:
class MsProduk(models.Model):
_name = 'ms_produk.ms_produk'
_rec_name = 'kd_produk'
Upvotes: 1
Reputation: 136
By default name_search
fucntion use value defined in _rec_name
(default as "name"), but your model not have field name
. So just add in your model:
_rec_name = "your_field_you_want_to_show_on_name_search"
Another way is modify function name_get
Upvotes: 5