콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
3459 화면

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?

아바타
취소
베스트 답변

 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.

아바타
취소
베스트 답변

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. 

아바타
취소
작성자 베스트 답변

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!

아바타
취소
관련 게시물 답글 화면 활동
3
9월 21
9669
0
11월 18
4711
0
4월 17
4014
1
1월 25
2371
3
10월 22
6248