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

Call a method with a modified context


The context is part of the environment of a recordset. It is used to pass information such as the timezone or the language of the user from the user interface as well as contextual parameters specified in actions. A number of methods in the standard addons use the context to adapt their behavior to these values. It is sometimes necessary to modify the context on a recordset to get the desired results from a method call or the desired value for a computed field.

This recipe shows how to read the stock level for all product.product models in a given stock.location.

Getting ready

This recipe uses the stock and product addons. For our purposes, here is a simplified version of the product.product model:

class product.product(models.Model):
    _name = 'product.product'
    name = fields.Char('Name', required=True)
    qty_available = fields.Float('Quantity on Hand',
                                 compute='_product_available')
    def _product_available(self...