Changing the user that performs an action
When writing business logic code, you may have to perform some actions with a different security context. A typical case is performing an action with superuser rights, bypassing security checks. Such a requirement arises when business requirements necessitate operating on records for which users do not have security access rights.
This recipe will show you how to allow normal users to modify the rent status of a book by using sudo()
. Put simply, we will allow users to rent books by themselves even if they do not have the right to create a rent record.
Getting ready
For easier understanding, we will add a new model to manage the book rantings. We will add a new model called library.book.rent
. You can refer to the following definition to add this model:
class LibraryBookRent(models.Model): _name = 'library.book.rent' book_id = fields.Many2one('library.book', &apos...