Skip to Content
Menu
This question has been flagged
2 Replies
12680 Views

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

Avatar
Discard
Best Answer

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?

Avatar
Discard
Best Answer

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)])
Avatar
Discard
Related Posts Replies Views Activity
5
May 23
11332
1
Feb 16
3818
1
Mar 15
4092
1
Mar 15
6497
1
Mar 15
3526