Skip to Content
मेन्यू
This question has been flagged
1 Reply
5866 Views

Hello, 

public_user = self.env.ref('base.public_user')
public_book = self.env['library.book'].with_user(public_user)
public_book.search([('name', 'ilike', 'cookbook')])

i want to ask that why we use with_user() and public_user what is the advantage of using this. can someone please explain . thanks

Avatar
Discard
Best Answer

Hi, 

with_user(user) function return a new version of this record set attached to the given user,
in non-superuser mode, unless `user` is the superuser (by convention, the superuser is always in superuser mode.

In your code,

public_user = self.env.ref('base.public_user')
public_book = self.env['library.book'].with_user(public_user)
It means environment of the model "library.book" will be opened with the user permission as of a public user.

Regards

Avatar
Discard
Related Posts Replies Views Activity
1
मई 24
2406
2
जून 23
2648
1
जुल॰ 24
1909
3
मई 24
3912
2
अप्रैल 24
3836