There's more...

In the recipe, we inserted a pdb.set_trace() statement to break into pdb for debugging. We can also start pdb directly from within the Odoo shell, which is very useful when you cannot easily modify the code of the project using pdb.runcall(). This function takes a method as the first argument and the arguments to pass to the function as the next arguments. So, inside the Odoo shell, you do this:

>>> import pdb
>>> product = env['product.product']
>>> location_stock = env.ref('stock.stock_location_stock')
>>> pdb.runcall(product.export_stock_level, location_stock)
> /home/cookbook/stock_level/models.py(16)export_stock_level()
-> products = self.with_context(
(Pdb)

In this recipe, we focused on the Python debugger from the Python standard library, pdb. It is very useful to know about this tool because it is guaranteed to be available on any Python distribution. There are other Python debuggers available, such as ipdb (https://pypi.python.org/pypi/ipdb) and pudb (https://pypi.python.org/pypi/pudb), which can be used as drop-in replacements for pdb. They share the same API, and most of the commands that you saw in this recipe were unchanged. Also, of course, if you develop for Odoo using a Python IDE, you will have access to a debugger that was integrated with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset