Changeset dfadd3f in rattail


Ignore:
Timestamp:
07/19/2022 03:50:10 PM (7 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
f34703e
Parents:
f97c452
Message:

Make caching products optional, when creating vendor catalog batch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/vendorcatalog.py

    rf97c452 rdfadd3f  
    7171
    7272    def setup(self, batch, progress=None):
     73        model = self.model
     74
     75        # TODO: deprecate / remove this
    7376        self.vendor = batch.vendor
    74         self.products = {'upc': {}, 'vendor_code': {}}
    75         session = self.app.get_session(batch)
    76         products = session.query(model.Product)\
    77                           .options(orm.joinedload(model.Product.brand))\
    78                           .options(orm.joinedload(model.Product.costs))
    79 
    80         def cache(product, i):
    81             if product.upc:
    82                 self.products['upc'][product.upc] = product
    83             cost = product.cost_for_vendor(self.vendor)
    84             product.vendor_cost = cost
    85             if cost and cost.code:
    86                 self.products['vendor_code'][cost.code] = product
    87 
    88         assert self.progress_loop(cache, products.all(), progress,
    89                                   message="Caching products by UPC and vendor code")
     77
     78        # maybe pre-cache all products
     79        if batch.get_param('cache_products'):
     80
     81            self.products = {'upc': {}, 'vendor_code': {}}
     82            session = self.app.get_session(batch)
     83            products = session.query(model.Product)\
     84                              .options(orm.joinedload(model.Product.brand))\
     85                              .options(orm.joinedload(model.Product.costs))\
     86                              .all()
     87
     88            def cache(product, i):
     89                if product.upc:
     90                    self.products['upc'][product.upc] = product
     91                cost = product.cost_for_vendor(batch.vendor)
     92                product.vendor_cost = cost
     93                if cost and cost.code:
     94                    self.products['vendor_code'][cost.code] = product
     95
     96            self.progress_loop(cache, products, progress,
     97                               message="Caching products by UPC and vendor code")
    9098
    9199    setup_populate = setup
     
    205213                product = self.products['vendor_code'].get(row.vendor_code)
    206214            else:
    207                 product = products_handler.locate_product_for_entry(
    208                     session, row.vendor_code, product_key='ignore',
    209                     lookup_vendor_code=True, vendor=row.batch.vendor)
     215                product = products_handler.locate_product_for_vendor_code(
     216                    session, row.vendor_code, vendor=row.batch.vendor)
    210217
    211218        return product
Note: See TracChangeset for help on using the changeset viewer.