Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
3671 Prikazi

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
Opusti
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
Opusti
Avtor

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 Odgovori Prikazi Aktivnost
1
maj 24
3632
1
apr. 24
27803
1
nov. 22
3060
2
jul. 22
3798
2
jul. 22
3583