تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
987 أدوات العرض
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
ديسمبر 22
6119
0
مارس 15
3917
2
مارس 15
10267
2
سبتمبر 24
6112
0
مارس 15
3963