Skip to Content
Menu
This question has been flagged
1 Atsakyti
3674 Rodiniai

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

Portretas
Atmesti
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

Portretas
Atmesti
Autorius

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 Rodiniai Veikla
1
geg. 24
3632
1
bal. 24
27805
1
lapkr. 22
3062
2
liep. 22
3798
2
liep. 22
3584