Reputation:
Relatively new to Odoo. Was trying to put a relation whereby 1 email is sent by 1 user but 1 user can send many email. I created a Many2one field in the email class as shown
user_id = fields.Many2one('res.users', string='user id', default=lambda self: self.env.user)
When i submit from the form, it always stores "1" which is the ID of the admin even if i log in as another user (John doe with id=6).
To check whether the relation is good, i just displayed the user_id field in my form, and I see a dropdown is populated with all the users in the database as shown in the codes below
<div class="hff hff_dropbox form-group" data-form-type="dropbox" data-field-id="4">
<label class="control-label" for="user_id">User id</label>
<select class="form-control" name="user_id">
<option value="">Select Option</option>
<option value="1">Administrator</option>
<option value="6">John Doe</option>
</select>
</div>
Upvotes: 2
Views: 916
Reputation: 1675
if you are in odoo backend uid, user is the orm fields which will store the logged in user in default. If you need to get it from code, try
self.env.user.id or request.session.uid or self.env.context.get('uid')
Upvotes: 1