콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
Hi, I would like to know if there is a way to include this code in the Odoo user interface, and exactly where to put it because I would like to implement it.




def name_get(self):

  marcas_list = []

  for record in self:

      name = record.x_name + record.x_desc

      marcas_list.append((record.id, name))

  return marcas_list

아바타
취소
베스트 답변

Hello,

To include the 'name_get' method in the Odoo user interface, you need to define it in the Python class of the model where you want it to be used. Typically, 'name_get' is used to customize the display of records in many2one fields or in various views where the record name is displayed.

Here's how you can implement it in your Odoo module:

1. Find or create the Python class corresponding to the model where you want to use 'name_get'. This class should inherit from 'models.Model'.

2. Add the 'name_get' method to the class. Ensure that the method takes 'self' as the first parameter and returns a list of tuples '(id, name)' where 'id' is the ID of the record and 'name' is the display name you want to show for that record.


Here's an example of how your class might look:

from odoo import models, fields


class YourClassName(models.Model):

    _name = 'your.model.name'  # Replace with the actual model name

    _description = 'Your Model Description'


    x_name = fields.Char(string='Name', required=True)

    x_desc = fields.Char(string='Description')


    def name_get(self):

        marcas_list = []

        for record in self:

            name = record.x_name + ' ' + record.x_desc

            marcas_list.append((record.id, name))

        return marcas_list

Replace 'your.model.name' with the actual model name where you want to use this method. Also, ensure that 'x_name' and 'x_desc' match the field names in your model.


After adding this method to your model class, it should be automatically used in the user interface wherever the record name is displayed.


Hope it helps.



아바타
취소
관련 게시물 답글 화면 활동
1
12월 22
6111
0
3월 15
3904
2
3월 15
10263
2
9월 24
6104
0
3월 15
3960