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

Updating values of recordset records


Business logic often means updating records by changing the values of some of their fields. This recipe shows how to add a contact for a partner and modify the date field of the partner as we go.

Getting ready

This recipe will be using the same simplified res.partner definition as the Creating new records recipe previously. You may refer to this simplified definition to know the fields.

The date field of res.partner has no defined meaning in Odoo. In order to illustrate our purpose, we will use this to record an activity date on the partner, so creating a new contact should update the date of the partner.

How to do it…

To update a partner, you can write a new method called add_contact() defined like this:

    @api.model
    def add_contacts(self, partner, contacts):
        partner.ensure_one()
        if contacts:
            partner.date = fields.Date.context_today()
            partner.child_ids |= contacts

How it works…

The method starts by checking whether...