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.
We will be reusing the export_stock_level()
method shown in the two previous recipes. Be sure to have a copy at hand.
In order to trace the execution of export_stock_level()
with pdb
, follow 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: 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: ...