Using the Python debugger to trace method execution
Sometimes, application logs are not enough to figure out what is going wrong. Fortunately, we also have the Python debugger. This recipe shows us how to insert a breakpoint in a method and trace the execution by hand.
Getting ready
We will reuse the export_stock_level()
method that was shown in the Using the Odoo shell to interactively call methods recipe of this chapter. Ensure that you have a copy to hand.
How to do it...
To trace the execution of export_stock_level()
with pdb
, perform the following steps:
- 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: Â Â Â Â Â Â Â &...