Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
3194 Zobrazení

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
Zrušit
Nejlepší odpověď

 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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
zář 21
9387
0
lis 18
4431
0
dub 17
3650
1
led 25
1879
3
říj 22
5896