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

Using the Python debugger to trace method execution


Sometimes, application logs are not enough to figure out what is going wrong. Fortunately, we have the Python debugger available to us. This recipe shows how to insert a break point in a method and trace the execution by hand.

Getting ready

We will be reusing the export_stock_level() method shown in the two previous recipes. Be sure to have a copy at hand.

How to do it…

In order to trace the execution of export_stock_level() with pdb, follow the following steps:

  1. Edit the code of the method, and insert the line highlighted here:

    def export_stock_level(self, stock_location):
        import pdb; pdb.set_trace()
        products = self.with_context(
            location=stock_location.id
        ).search([])
        fname = join(EXPORTS_DIR, 'stock_level.txt')
        try:
            with open(fname, 'w') as fobj:
                for prod in products.filtered('qty_available'):
                    fobj.write('%s\t%f\n' % (prod.name, prod.qty_available))
        except IOError:
           ...