Change the user performing 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 the rights of the Administrator, who bypasses security checks.

This recipe shows how to let normal users modify the phone number of a company by using sudo().

Getting ready

We will be working on records of the res.company model. By default, only members of the Administration/Access Rights user group can modify records of res.company, but in our case, we need to provide an access point to change only the phone number to users who are not necessarily members of that group.

How to do it…

In order to let normal users modify the phone number of a company, you need to perform ...

Get Odoo Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.