def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple if cls.filter: filter_and = "and %s " % cls.filter filter_where = "where %s " % cls.filter else: filter_and = "" filter_where = "" with connections[database].chunked_cursor() as cursor: cnt = 0 starttime = time() cursor.execute(''' SELECT supplier_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemsupplier %s ORDER BY supplier_id, item_id, location_id, priority desc ''' % filter_where) cursuppliername = None curitemname = None for i in cursor: cnt += 1 try: if i[0] != cursuppliername: cursuppliername = i[0] cursupplier = frepple.supplier(name=cursuppliername) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemsupplier = frepple.itemsupplier( supplier=cursupplier, item=curitem, source=i[9], leadtime=i[10].total_seconds() if i[10] else 0, fence=i[13].total_seconds() if i[13] else 0, resource_qty=i[12] ) if i[2]: curitemsupplier.location = frepple.location(name=i[2]) if i[3]: curitemsupplier.size_minimum = i[3] if i[4]: curitemsupplier.size_multiple = i[4] if i[5]: curitemsupplier.cost = i[5] if i[6]: curitemsupplier.priority = i[6] if i[7]: curitemsupplier.effective_start = i[7] if i[8]: curitemsupplier.effective_end = i[8] if i[11]: curitemsupplier.resource = frepple.resource(name=i[11]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d item suppliers in %.2f seconds' % (cnt, time() - starttime))
def loadItemSuppliers(self): print('Importing item suppliers...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT supplier_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemsupplier %s ORDER BY supplier_id, item_id, location_id, priority desc ''' % self.filter_where) cursuppliername = None curitemname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[0] != cursuppliername: cursuppliername = i[0] cursupplier = frepple.supplier(name=cursuppliername) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemsupplier = frepple.itemsupplier( supplier=cursupplier, item=curitem, source=i[9], leadtime=i[10].total_seconds() if i[10] else 0, fence=i[13].total_seconds() if i[13] else 0, resource_qty=i[12]) if i[2]: curitemsupplier.location = frepple.location(name=i[2]) if i[3]: curitemsupplier.size_minimum = i[3] if i[4]: curitemsupplier.size_multiple = i[4] if i[5]: curitemsupplier.cost = i[5] if i[6]: curitemsupplier.priority = i[6] if i[7]: curitemsupplier.effective_start = i[7] if i[8]: curitemsupplier.effective_end = i[8] if i[11]: curitemsupplier.resource = frepple.resource(name=i[11]) except Exception as e: print("Error:", e) print('Loaded %d item suppliers in %.2f seconds' % (cnt, time() - starttime))
def loadItemSuppliers(self): print('Importing item suppliers...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT supplier_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemsupplier %s ORDER BY supplier_id, item_id, location_id, priority desc ''' % self.filter_where) cursuppliername = None curitemname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[0] != cursuppliername: cursuppliername = i[0] cursupplier = frepple.supplier(name=cursuppliername) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemsupplier = frepple.itemsupplier( supplier=cursupplier, item=curitem, source=i[9], leadtime=i[10].total_seconds() if i[10] else 0, fence=i[13].total_seconds() if i[13] else 0, resource_qty=i[12] ) if i[2]: curitemsupplier.location = frepple.location(name=i[2]) if i[3]: curitemsupplier.size_minimum = i[3] if i[4]: curitemsupplier.size_multiple = i[4] if i[5]: curitemsupplier.cost = i[5] if i[6]: curitemsupplier.priority = i[6] if i[7]: curitemsupplier.effective_start = i[7] if i[8]: curitemsupplier.effective_end = i[8] if i[11]: curitemsupplier.resource = frepple.resource(name=i[11]) except Exception as e: print("Error:", e) print('Loaded %d item suppliers in %.2f seconds' % (cnt, time() - starttime))