Get current logged In user id in Odoo/openERP model
Get current logged in user id in field:
current_user = fields.Many2one('res.users','Current User', default=lambda self: self.env.user.id)
We can also get current user id or logged in user id using "self.env.uid"
current_user = fields.Many2one('res.users','Current User', default=lambda self: self.env.uid)
We can also get current user id by defining default value of a field. Default value will be a function that returns the current user's id which can be accessed with self.env.uid. By using default function we can set any value to a field.
def get_user_id(self):
return self.env.uid
current_user = fields.Many2one('res.users','Current User', default=_get_user_id)
Get current user or logged in user id in odoo controller
Inside a web controller we can get the current user id by following codes.request.uid
or
request.session.uid
or
http.request.env.context.get('uid')