简体   繁体   English

如何在odoo 12中更改many2one值字段名称?

[英]How to change many2one value field name in odoo 12?

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)? 您好,当我在odoo 12中使用many2one函数时,它们之间(类)之间有many2one关系,为什么我要获取表名和ID(生成的表名和ID会自动由odoo ORM生成)? and the other odoo example is not? 另一个odoo例子不是吗? 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? 我想显示kd_produk而不是表名和ID,我该如何更改?

By default name_search fucntion use value defined in _rec_name (default as "name"), but your model not have field name . 默认情况下, name_search功能使用在_rec_name定义的_rec_name (默认为“ name”),但是您的模型没有field name So just add in your model: 因此,只需添加您的模型:

_rec_name = "your_field_you_want_to_show_on_name_search" _rec_name =“您的field_you_want_to_show_on_name_search”

Another way is modify function name_get 另一种方法是修改函数name_get

Add _rec_name as kd_produk field in your ms_produk.ms_produk model, 添加_rec_namekd_produk场在ms_produk.ms_produk模型,

Eg: 例如:

   class MsProduk(models.Model):
      _name = 'ms_produk.ms_produk'
      _rec_name = 'kd_produk'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM