Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
14484 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
5
mei 23
12987
1
feb. 16
4804
1
mrt. 15
5421
1
mrt. 15
7920
1
mrt. 15
4803