Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5907 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
mag 24
2439
2
giu 23
2686
1
lug 24
1927
3
mag 24
3977
2
apr 24
3896