Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3676 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
ผู้เขียน

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 ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 24
3632
1
เม.ย. 24
27805
1
พ.ย. 22
3062
2
ก.ค. 22
3798
2
ก.ค. 22
3584