Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
10 Trả lời
25472 Lượt xem

Hello Everyone,

I have to try to get current user login id in my filed.

My python code below :

user_id = fields.Many2one('res.users', string='My User',default=lambda self: self.env.user)

But i am facing a problem when i am change login user than it's not reflected into my field so what i can do any one suggest any solution.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I am solve this issue.. using this.

@api.one

def _get_current_login_user(self):

user_obj = self.env['res.users'].search([])

for user_login in user_obj:

current_login= self.env.user

if user_login == current_login:

self.processing_staff = current_login

return

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

The code you have given seems to be fine.   As per this when you open the form you will get the current user in the field named user_id .

Can i know what exactly the problem is ?

Suppose if the admin is logged in and when you open a new form of that model,  in it you are getting the admin in that field  right ? Then just log out the admin and login as other user, now you will get that user's name in that field in new form right ?

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Yes.. exactly.. @Niyas

the above explained is the expected behavior,

right now what you are getting

Tác giả

just only show admin login but when i am login with another user than it's not reflected.

Tác giả

Hello @Niyas,

I have done get current user id when form is draft state But my form is save than how to change current user id in my field.

Câu trả lời hay nhất

Why did you not do this using computed field. Crate a computed field with char type and assign the name of current user to that computed field.

Ảnh đại diện
Huỷ bỏ
you are welcome :)

On Wed, Feb 14, 2018 at 11:59 AM, Manish Bohra <manishbohra1994@gmail.com> wrote:

thanks.. but my issue is solve.

--
Manish Bohra


Sent by Odoo S.A. using Odoo.


Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 17
3080
0
thg 4 17
3322
2
thg 3 15
8231
0
thg 9 21
3272
0
thg 7 19
1128