Skip to Content
Menu
This question has been flagged
1 Reply
2953 Views

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")

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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.

Related Posts Replies Views Activity
1
May 24
1435
1
Apr 24
23291
1
Nov 22
1411
2
Jul 22
1809
2
Jul 22
1839