This question has been flagged
4 Replies
1961 Views

As it seems nobody can answer what seems to me a simple question, I give it another try:

When I have a Many2one relation from model ufodata.case to model ufodata.investigator, why is this relation represented in the form view in the following way:

"ufodata.investigator,1"?

Of course, nobody neither wants to see the model's technical name nor take a guess which of the investigators has the id 1. Everyone would expect to be presented the investigator's name, and be enabled (in edit mode) to assign another investigator by his name.

So how odoo intends to handle this? What must I do to have the investigator's name representing the related dataset in the form view?

Avatar
Discard
Best Answer

 If I understand correctly, you have a problem  with definition of your model ufodata.investigator
In this model, you should define a field named name or add the _rec_name parameter to the class definition.

_rec_name name by default looks for name field, if name field is not available then it will display like your model_name,db_id , so we have to pass at least one field to _rec_name in case of no name field.  

One more solution is to define a custom name_get() method.

Avatar
Discard
Best Answer

Hi Ingbert

I have one suggestion for you!  Try to do this in Odoo Studio (either use the demo database or download Odoo Enterprise and use as a trial), then you can see how Odoo handles this (which is as Zbik has explained):  

The Model (database table) will have a Name field and that is what will be displayed. If you delete the Name field you will get what you are seeing. 

Avatar
Discard
Author Best Answer

Hello Zbik and Chris,

thank you for your advice! With rec_name it worked as expected, and finally, I settled upon implementing name_get, as I want to concatenate field values.

def name_get(self):
result = []
for record in self:
result.append((record.id, "%s %s %s" % (record.first_name, record.middle_name, record.surname)))
return result

Best regards!

Avatar
Discard