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

Hi,

I'm trying to set a default value for the field create_uid in my python file. After research on the forum I found that the correct way to do this should be something like:

create_uid=fields.Many2one(default=lambda self: self.env.user)

I've tried different syntaxes but at best it returns "1"  (since I'm the first user as administrator) but it should return "Administrator".

Thank you in advance for any help.

아바타
취소
베스트 답변

Hi Mehdi, why do you need to add create_uid field.Its default odoo field which will save with the id of the current logged in user when the record has been created.Just you need to add theis field to your views to see it.

Eventhough, if you want to add another field for some purpose which should work like create_uid,you can implement it like,

create_uid=fields.Many2one('res.users',default=lambda self: self.env.user and self.env.user.id or False)

I will advice you to take different name for the field other than create_uid.

아바타
취소
작성자

Hi Raaj thank you for your answer but what I'm trying to do is to override the field create_uid so that when displayed in form view; the user can't choose another user in the Many2one widget. If I do this with readonly attribute, neither the widget nor the user name is displayed.

If possible can you pls post the screenshot.

One more thing, at you overridden field definition, you have missed to pass the object name i.e., res.users, which i have corrected and included in my answer.

작성자

Sorry I don't succeed in posting pictures on the forum but you can access it between url tags. I've tried your sample but I don't understand why you use "and" & "or" and I can't compile your code.