Hello everyone,
I'm trying to fill in a form field with the reference of the user connected to the site.
Part 1 :
I've created a "car" data model with a "owner_id" many2one field inside.
When the logged-in user complete the form to have a new car (with name, price, etc.), I'd like to fill his "ref_user" automatically in a field of the form.
Part 2 :
I've add the following code line in parameters-> technical -> Models -> my car model -> the owner_id field -> advanced properties -> compute
"owner_id = fields.Many2one('res.users', default=lambda self: self.env.user)"
Part 3
I have this error :
: "name 'fields' is not defined" while evaluating "owner_id= fields.Many2one('res.users', default=lambda self: self.env.user)"
It's like the compute don't authorize the fields object...
I try to just do "owner_id = self.env.user" but it doesn't seems to work and i can't have a "console.log" of the owner_id.
How can i fix this error ?
Answer :
In the compute field, the code needed is :
for record in self:
record ['x_studio_owner_id'] = record.env.user
Thanks for your help.