Getting ready

We will add some logging statements to the following method, which saves the stock levels of products to a file:

from os.path import join 
from odoo import models, api, exceptions 
EXPORTS_DIR = '/srv/exports' 
 
class ProductProduct(models.Model): 
    _inherit = 'product.product' 
    @api.model 
    def export_stock_level(self, stock_location): 
        products = self.with_context( 
            location=stock_location.id 
        ).search([]) 
        products = products.filtered('qty_available') 
        fname = join(EXPORTS_DIR, 'stock_level.txt') 
        try: 
            with open(fname, 'w') as fobj: 
                for prod in products: 
                    fobj.write('%s	%f
' % (prod.name, 
                                             prod.qty_available)) 
        except IOError: 
            raise exceptions.UserError('unable to save file') 
..................Content has been hidden....................

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