Book Image

Odoo Development Cookbook

By : Holger Brunn, Alexandre Fayolle, Daniel Reis
Book Image

Odoo Development Cookbook

By: Holger Brunn, Alexandre Fayolle, Daniel Reis

Overview of this book

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source is also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. The book starts by covering Odoo installation and administration, and provides a gentle introduction to application development. It then dives deep into several of the areas that an experienced developer will need to use. You’ll learn implement business logic, adapt the UI, and extend existing features.
Table of Contents (23 chapters)
Odoo Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 the following steps:

  1. Define a model extending the res.company model:

    class ResCompany(models.Model):
        _inherit = 'res.company'
  2. Add a method called update_phone_number():

        @api.multi
        def update_phone_number(self, new_number):
  3. In the method...