def loadOperations(self): print('Importing operations...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, fence, pretime, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source FROM operation %s ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: if not i[7] or i[7] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) if i[8]: x.duration = i[8] elif i[7] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) if i[8]: x.duration = i[8] if i[9]: x.duration_per = i[9] elif i[7] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) elif i[7] == "routing": x = frepple.operation_routing( name=i[0], description=i[13], category=i[14], subcategory=i[15], source=i[16] ) else: raise ValueError("Operation type '%s' not recognized" % i[7]) if i[1]: x.fence = i[1] if i[2]: x.pretime = i[2] if i[3]: x.posttime = i[3] if i[4]: x.size_minimum = i[4] if i[5]: x.size_multiple = i[5] if i[6]: x.size_maximum = i[6] if i[10]: x.location = frepple.location(name=i[10]) if i[11]: x.cost = i[11] if i[12]: x.search = i[12] except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
def loadOperations(cursor): print('Importing operations...') cnt = 0 starttime = time() cursor.execute(''' SELECT name, fence, pretime, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory FROM operation ''') for i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x in cursor.fetchall(): cnt += 1 try: if not p or p == "fixed_time": x = frepple.operation_fixed_time(name=i, description=v, category=w, subcategory=x) if q: x.duration = q elif p == "time_per": x = frepple.operation_time_per(name=i, description=v, category=w, subcategory=x) if q: x.duration = q if r: x.duration_per = r elif p == "alternate": x = frepple.operation_alternate(name=i, description=v, category=w, subcategory=x) elif p == "routing": x = frepple.operation_routing(name=i, description=v, category=w, subcategory=x) else: raise ValueError("Operation type '%s' not recognized" % p) if j: x.fence = j if k: x.pretime = k if l: x.posttime = l if m: x.size_minimum = m if n: x.size_multiple = n if o: x.size_maximum = o if s: x.location = frepple.location(name=s) if t: x.cost = t if u: x.search = u except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
def loadOperations(self): print('Importing operations...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, fence, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source, item_id, priority, effective_start, effective_end FROM operation %s ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: if not i[6] or i[6] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() elif i[6] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() if i[8]: x.duration_per = i[8].total_seconds() elif i[6] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "split": x = frepple.operation_split( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "routing": x = frepple.operation_routing( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) else: raise ValueError("Operation type '%s' not recognized" % i[6]) if i[1]: x.fence = i[1].total_seconds() if i[2]: x.posttime = i[2].total_seconds() if i[3] is not None: x.size_minimum = i[3] if i[4]: x.size_multiple = i[4] if i[5]: x.size_maximum = i[5] if i[9]: x.location = frepple.location(name=i[9]) if i[10]: x.cost = i[10] if i[11]: x.search = i[11] if i[16]: x.item = frepple.item(name=i[16]) if i[17] is not None: x.priority = i[17] if i[18]: x.effective_start = i[18] if i[19]: x.effective_end = i[19] except Exception as e: print("Error:", e) print('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
if not(not inspect.isclass(o) or issubclass(o,Exception) or hasattr(o,"__iter__")): continue if inspect.isroutine(o): continue if not(not inspect.isclass(o) or not issubclass(o,Exception)): continue if not(not inspect.isclass(o) or not hasattr(o,"__iter__")): continue print(" %s: %s" % (name, o)) ### print("\nUpdating global settings") frepple.settings.name = "demo model" frepple.settings.description = "unicode А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь" frepple.settings.current = datetime.datetime(2009,1,1) ### print("\nCreating operations") shipoper = frepple.operation_fixed_time(name="delivery end item", duration=86400) choice = frepple.operation_alternate(name="make or buy item") makeoper = frepple.operation_routing(name="make item") makeoper.addStep(frepple.operation_fixed_time(name="make item - step 1", duration=4*86400)) makeoper.addStep(frepple.operation_fixed_time(name="make item - step 2", duration=3*86400)) buyoper = frepple.operation_fixed_time(name="buy item", duration=86400) choice.addAlternate(operation=makeoper, priority=1) choice.addAlternate(operation=buyoper, priority=2) ### print("\nCreating calendars") c = frepple.calendar(name="Cal1", default=4.56) c.setValue(datetime.datetime(2009,1,1), datetime.datetime(2009,3,1), 1) c.setValue(datetime.datetime(2009,2,1), datetime.datetime(2009,5,1), 2) c.setValue(datetime.datetime(2009,2,1), datetime.datetime(2009,3,1), 3) frepple.calendar(name="Cal2", default=1.23)
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].cursor() as cursor: cnt = 0 starttime = time() # Preprocessing step # Make sure any routing has the produced item of its last step populated in the operation table cursor.execute(''' update operation set item_id = t.item_id from ( select operation.name operation_id, min(operationmaterial.item_id) item_id from operation inner join suboperation s1 on s1.operation_id = operation.name inner join operationmaterial on operationmaterial.operation_id = s1.suboperation_id and quantity > 0 where operation.type = 'routing' and not exists (select 1 from suboperation s2 where s1.operation_id = s2.operation_id and s1.priority < s2.priority) group by operation.name having count(operationmaterial.item_id) = 1 ) t where operation.type = 'routing' and operation.name = t.operation_id ''') # Preprocessing step # Make sure any regular operation (i.e. that has no suboperation and is not a suboperation) # has its item_id field populated # That should cover 90% of the cases cursor.execute(''' update operation set item_id = t.item_id from ( select operation.name operation_id, min(operationmaterial.item_id) item_id from operation inner join operationmaterial on operationmaterial.operation_id = operation.name and quantity > 0 where not exists (select 1 from suboperation where suboperation.operation_id = operation.name or suboperation.suboperation_id = operation.name) and operation.type not in ('routing', 'alternate', 'split') group by operation.name having count(operationmaterial.item_id) = 1 ) t where operation.type not in ('routing', 'alternate', 'split') and t.operation_id = operation.name ''') # Preprocessing step # Operations that are suboperation of a parent operation shouldn't have # the item field set. It is the parent operation that should have it set. cursor.execute(''' update operation set item_id = null from suboperation where operation.name = suboperation.suboperation_id and operation.item_id is not null ''') with connections[database].chunked_cursor() as cursor: cursor.execute(''' SELECT name, fence, posttime, sizeminimum, sizemultiple, sizemaximum, type, duration, duration_per, location_id, cost, search, description, category, subcategory, source, item_id, priority, effective_start, effective_end, available_id FROM operation %s ''' % filter_where) for i in cursor: cnt += 1 try: if not i[6] or i[6] == "fixed_time": x = frepple.operation_fixed_time( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() elif i[6] == "time_per": x = frepple.operation_time_per( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) if i[7]: x.duration = i[7].total_seconds() if i[8]: x.duration_per = i[8].total_seconds() elif i[6] == "alternate": x = frepple.operation_alternate( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "split": x = frepple.operation_split( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) elif i[6] == "routing": x = frepple.operation_routing( name=i[0], description=i[12], category=i[13], subcategory=i[14], source=i[15] ) else: raise ValueError("Operation type '%s' not recognized" % i[6]) if i[1]: x.fence = i[1].total_seconds() if i[2]: x.posttime = i[2].total_seconds() if i[3] is not None: x.size_minimum = i[3] if i[4]: x.size_multiple = i[4] if i[5]: x.size_maximum = i[5] if i[9]: x.location = frepple.location(name=i[9]) if i[10]: x.cost = i[10] if i[11]: x.search = i[11] if i[16]: x.item = frepple.item(name=i[16]) if i[17] is not None: x.priority = i[17] if i[18]: x.effective_start = i[18] if i[19]: x.effective_end = i[19] if i[20]: x.available = frepple.calendar(name=i[20]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d operations in %.2f seconds' % (cnt, time() - starttime))
if inspect.isroutine(o): continue if not (not inspect.isclass(o) or not issubclass(o, Exception)): continue if not (not inspect.isclass(o) or not hasattr(o, "__iter__")): continue print(" %s: %s" % (name, o)) ### print("\nUpdating global settings") frepple.settings.name = "demo model" frepple.settings.description = "unicode А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь" frepple.settings.current = datetime.datetime(2009, 1, 1) ### print("\nCreating operations") shipoper = frepple.operation_fixed_time(name="delivery end item", duration=86400) choice = frepple.operation_alternate(name="make or buy item") makeoper = frepple.operation_routing(name="make item") makeoper.addStep( frepple.operation_fixed_time(name="make item - step 1", duration=4 * 86400)) makeoper.addStep( frepple.operation_fixed_time(name="make item - step 2", duration=3 * 86400)) buyoper = frepple.operation_fixed_time(name="buy item", duration=86400) choice.addAlternate(operation=makeoper, priority=1) choice.addAlternate(operation=buyoper, priority=2) ### print("\nCreating calendars") c = frepple.calendar(name="Cal1", default=4.56)
if not(not inspect.isclass(o) or issubclass(o,Exception) or hasattr(o,"__iter__")): continue if inspect.isroutine(o): continue if not(not inspect.isclass(o) or not issubclass(o,Exception)): continue if not(not inspect.isclass(o) or not hasattr(o,"__iter__")): continue print(" %s: %s" % (name, o)) ### print("\nUpdating global settings") frepple.settings.name = "demo model" frepple.settings.description = "unicode А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь" frepple.settings.current = datetime.datetime(2009,1,1) ### print("\nCreating operations") shipoper = frepple.operation_fixed_time(name="delivery end item", duration=86400) choice = frepple.operation_alternate(name="make or buy item") makeoper = frepple.operation_routing(name="make item") frepple.suboperation( owner = makeoper, operation = frepple.operation_fixed_time(name="make item - step 1", duration=4*86400), priority = 1 ) frepple.suboperation( owner = makeoper, operation = frepple.operation_fixed_time(name="make item - step 2", duration=3*86400), priority = 2 ) buyoper = frepple.operation_fixed_time(name="buy item", duration=86400) frepple.suboperation( owner = choice,