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 origin_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemdistribution %s ORDER BY origin_id, item_id, location_id, priority desc ''' % filter_where) curoriginname = None curitemname = None for i in cursor: cnt += 1 try: if i[0] != curoriginname: curoriginname = i[0] curorigin = frepple.location(name=curoriginname) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemdistribution = frepple.itemdistribution( origin=curorigin, 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]: curitemdistribution.destination = frepple.location(name=i[2]) if i[3]: curitemdistribution.size_minimum = i[3] if i[4]: curitemdistribution.size_multiple = i[4] if i[5]: curitemdistribution.cost = i[5] if i[6]: curitemdistribution.priority = i[6] if i[7]: curitemdistribution.effective_start = i[7] if i[8]: curitemdistribution.effective_end = i[8] if i[11]: curitemdistribution.resource = frepple.resource(name=i[11]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d item distributions in %.2f seconds' % (cnt, time() - starttime))
def loadItemDistributions(self): print('Importing item distributions...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT origin_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemdistribution %s ORDER BY origin_id, item_id, location_id, priority desc ''' % self.filter_where) curoriginname = None curitemname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[0] != curoriginname: curoriginname = i[0] curorigin = frepple.location(name=curoriginname) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemdistribution = frepple.itemdistribution( origin=curorigin, 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]: curitemdistribution.destination = frepple.location( name=i[2]) if i[3]: curitemdistribution.size_minimum = i[3] if i[4]: curitemdistribution.size_multiple = i[4] if i[5]: curitemdistribution.cost = i[5] if i[6]: curitemdistribution.priority = i[6] if i[7]: curitemdistribution.effective_start = i[7] if i[8]: curitemdistribution.effective_end = i[8] if i[11]: curitemdistribution.resource = frepple.resource(name=i[11]) except Exception as e: print("Error:", e) print('Loaded %d item itemdistributions in %.2f seconds' % (cnt, time() - starttime))
def loadItemDistributions(self): print('Importing item distributions...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT origin_id, item_id, location_id, sizeminimum, sizemultiple, cost, priority, effective_start, effective_end, source, leadtime, resource_id, resource_qty, fence FROM itemdistribution %s ORDER BY origin_id, item_id, location_id, priority desc ''' % self.filter_where) curoriginname = None curitemname = None for i in self.cursor.fetchall(): cnt += 1 try: if i[0] != curoriginname: curoriginname = i[0] curorigin = frepple.location(name=curoriginname) if i[1] != curitemname: curitemname = i[1] curitem = frepple.item(name=curitemname) curitemdistribution = frepple.itemdistribution( origin=curorigin, 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]: curitemdistribution.destination = frepple.location(name=i[2]) if i[3]: curitemdistribution.size_minimum = i[3] if i[4]: curitemdistribution.size_multiple = i[4] if i[5]: curitemdistribution.cost = i[5] if i[6]: curitemdistribution.priority = i[6] if i[7]: curitemdistribution.effective_start = i[7] if i[8]: curitemdistribution.effective_end = i[8] if i[11]: curitemdistribution.resource = frepple.resource(name=i[11]) except Exception as e: print("Error:", e) print('Loaded %d item itemdistributions in %.2f seconds' % (cnt, time() - starttime))