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

hello, i wanted to know how in my many2one field to get the logged user i have found a lot of solution by putting in default value lambda self,cr,uid, context: self.pool.get('res.users').browse(cr, uid, uid, context).id, something like this but in fact it's not what i want to.

for example if the user X has create a record it will be by defaut X in my many2one but i want that if another user Y click on that record(-that X have created) my many2one field will change with Y that means i want the current user no the user when the record has been created 

thanks a lot

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

Hi brami,

You can using compute field:

ex:

@api.multi

def _get_current_user(self):

     self.user_id = self.env.uid

user_id = fields.Many2one('res.users', 'Current User', compute='_get_current_user')


But I don't understand why do you do it?

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

Use domain if you don't want it to be computed.

Example:

user_id = fields.Many2one(
'res.users', 'Responsible',
domain=lambda self: [('res_id', 'in', self.env.user.id)])
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
5
พ.ค. 23
13171
1
ก.พ. 16
4911
1
มี.ค. 15
5551
1
มี.ค. 15
8027
1
มี.ค. 15
4950