تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
2113 أدوات العرض
Hello,

I have a Many2one field that relates labs to drugs. 
Each medicine must have its associated laboratory.

Related models are Medicines and Laboratories The problem is that I need the dropdown not to show me the name of the model and the ID of the registered laboratory.
I need you to show me the lab name field.


الصورة الرمزية
إهمال
الكاتب


I am using Odoo Studio Online, the free version.


How should I add or edit those lines of code?

Hi,

If there is no name field in the newly added model, Use _rec_name = 'some_field', in your model
Or you can define the name_get function for the model.

Hope it helps.

الكاتب أفضل إجابة


I was able to solve it, thank you very much everyone!

الصورة الرمزية
إهمال
أفضل إجابة

You can use _rec_name = 'your_field'

or def name_get for your model

الصورة الرمزية
إهمال
أفضل إجابة

Hi  Lautaro Diaz,

Choose the form view you want to modify. Drag and drop the M2O field to the desired location in the form view, Select the related model for the M2O field. You can configure its properties by clicking on the field in the form.


الصورة الرمزية
إهمال
أفضل إجابة

Hi 

You can use the _rec_name attribute or name_get function in the lab model, and return the name as Lab name.

for example, if your lab model is a lab.medical you can update it as following 

class Lab(models.Model)

_name = 'lab.medical'

_rec_name = 'name'


name = fields.Char(string="Name")


for more references check the following 


https://www.cybrosys.com/blog/how-to-use-of-name-get-function-in-odoo

https://www.odoo.com/forum/help-1/rec-name-predefined-fields-17172


Regards

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
فبراير 25
10261
2
يوليو 17
3637
0
مارس 15
3899
2
فبراير 25
5792
1
ديسمبر 24
1373