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

I am trying to store the currently logged user into a many2one field using compute method. It's working fine if i define the Mnay2one field without the store="True" parameter. Actually, i need to save it. 

Here is the code:

    

      
       def get_logged_user(self):
              for rec in self:
                    print('inside get_logged_user---------------',rec.env.user.name)
                    rec.logged_user_id = rec.env.user.id

       logged_user_id = fields.Many2one('res.users',string="Logged user",store=True,compute="get_logged_user")

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

Hi Kabeer,

Actually, you are using wrong attribute. Use lambda. For more you can also check base modules for your reference.

logged_user_id = fields.Many2one('res.users',string="Logged user", default=lambda self: self.env.user.id, readonly=True)

Thanks & Regards,

Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

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

I think your solution only work when a new record creates. i need to update the logged_user_id field whenever refresh the page. Ex: after creating a new record, if two users log in the same time and access the same form view, the value of the should be different.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 24
3632
1
thg 4 24
27805
1
thg 11 22
3062
2
thg 7 22
3798
2
thg 7 22
3584