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 name, description, owner_id, category, subcategory, source FROM customer %s ''' % filter_where) for i in cursor: cnt += 1 try: x = frepple.customer(name=i[0], description=i[1], category=i[3], subcategory=i[4], source=i[5]) if i[2]: x.owner = frepple.customer(name=i[2]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d customers in %.2f seconds' % (cnt, time() - starttime))
def loadCustomers(cursor): print('Importing customers...') cnt = 0 starttime = time() cursor.execute("SELECT name, description, owner_id, category, subcategory FROM customer") for i, j, k, l, m in cursor.fetchall(): cnt += 1 try: x = frepple.customer(name=i, description=j, category=l, subcategory=m) if k: x.owner = frepple.customer(name=k) except Exception as e: print("Error:", e) print('Loaded %d customers in %.2f seconds' % (cnt, time() - starttime))
def loadDemand(self): print('Importing demands...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, due, quantity, priority, item_id, operation_id, customer_id, owner_id, minshipment, maxlateness, category, subcategory, source, location_id, status FROM demand WHERE (status IS NULL OR status ='open' OR status = 'quote') %s ''' % self.filter_and) for i in self.cursor.fetchall(): cnt += 1 try: x = frepple.demand( name=i[0], due=i[1], quantity=i[2], priority=i[3], status=i[14], item=frepple.item(name=i[4]), category=i[10], subcategory=i[11], source=i[12] ) if i[5]: x.operation = frepple.operation(name=i[5]) if i[6]: x.customer = frepple.customer(name=i[6]) if i[7]: x.owner = frepple.demand(name=i[7]) if i[8]: x.minshipment = i[8] if i[9] is not None: x.maxlateness = i[9].total_seconds() if i[13]: x.location = frepple.location(name=i[13]) except Exception as e: print("Error:", e) print('Loaded %d demands in %.2f seconds' % (cnt, time() - starttime))
def loadDemand(self): print('Importing demands...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, due, quantity, priority, item_id, operation_id, customer_id, owner_id, minshipment, maxlateness, category, subcategory, source, location_id, status FROM demand WHERE (status IS NULL OR status ='open' OR status = 'quote') %s ''' % self.filter_and) for i in self.cursor.fetchall(): cnt += 1 try: x = frepple.demand( name=i[0], due=i[1], quantity=i[2], priority=i[3], status=i[14], item=frepple.item(name=i[4]), category=i[10], subcategory=i[11], source=i[12] ) if i[5]: x.operation = frepple.operation(name=i[5]) if i[6]: x.customer = frepple.customer(name=i[6]) if i[7]: x.owner = frepple.demand(name=i[7]) if i[8]: x.minshipment = i[8] if i[9] is not None: x.maxlateness = i[9] if i[13]: x.location = frepple.location(name=i[13]) except Exception as e: print("Error:", e) print('Loaded %d demands in %.2f seconds' % (cnt, time() - starttime))
def loadDemand(cursor): print('Importing demands...') cnt = 0 starttime = time() cursor.execute('''SELECT name, due, quantity, priority, item_id, operation_id, customer_id, owner_id, minshipment, maxlateness, category, subcategory FROM demand where status is null or status ='open' or status = 'quote' ''') for i, j, k, l, m, n, o, p, q, r, s, t in cursor.fetchall(): cnt += 1 try: x = frepple.demand(name=i, due=j, quantity=k, priority=l, item=frepple.item(name=m), category=s, subcategory=t) if n: x.operation = frepple.operation(name=n) if o: x.customer = frepple.customer(name=o) if p: x.owner = frepple.demand(name=p) if q: x.minshipment = q if r != None: x.maxlateness = r except Exception as e: print("Error:", e) print('Loaded %d demands in %.2f seconds' % (cnt, time() - starttime))
def loadCustomers(self): print('Importing customers...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT name, description, owner_id, category, subcategory, source FROM customer %s ''' % self.filter_where) for i in self.cursor.fetchall(): cnt += 1 try: x = frepple.customer(name=i[0], description=i[1], category=i[3], subcategory=i[4], source=i[5]) if i[2]: x.owner = frepple.customer(name=i[2]) except Exception as e: print("Error:", e) print('Loaded %d customers in %.2f seconds' % (cnt, time() - starttime))
def loadCustomers(cursor): print('Importing customers...') cnt = 0 starttime = time() cursor.execute( "SELECT name, description, owner_id, category, subcategory FROM customer" ) for i, j, k, l, m in cursor.fetchall(): cnt += 1 try: x = frepple.customer(name=i, description=j, category=l, subcategory=m) if k: x.owner = frepple.customer(name=k) except Exception as e: print("Error:", e) print('Loaded %d customers in %.2f seconds' % (cnt, time() - starttime))
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 name, due, quantity, priority, item_id, operation_id, customer_id, owner_id, minshipment, maxlateness, category, subcategory, source, location_id, status FROM demand WHERE (status IS NULL OR status ='open' OR status = 'quote') %s ''' % filter_and) for i in cursor: cnt += 1 try: x = frepple.demand( name=i[0], due=i[1], quantity=i[2], priority=i[3], status=i[14], item=frepple.item(name=i[4]), category=i[10], subcategory=i[11], source=i[12] ) if i[5]: x.operation = frepple.operation(name=i[5]) if i[6]: x.customer = frepple.customer(name=i[6]) if i[7]: x.owner = frepple.demand(name=i[7]) if i[8] is not None: x.minshipment = i[8] if i[9] is not None: x.maxlateness = i[9].total_seconds() if i[13]: x.location = frepple.location(name=i[13]) except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d demands in %.2f seconds' % (cnt, time() - starttime))
def loadDemand(cursor): print('Importing demands...') cnt = 0 starttime = time() cursor.execute('''SELECT name, due, quantity, priority, item_id, operation_id, customer_id, owner_id, minshipment, maxlateness, category, subcategory FROM demand where status is null or status ='open' ''') for i,j,k,l,m,n,o,p,q,r,s,t in cursor.fetchall(): cnt += 1 try: x = frepple.demand( name=i, due=j, quantity=k, priority=l, item=frepple.item(name=m),category=s,subcategory=t) if n: x.operation = frepple.operation(name=n) if o: x.customer = frepple.customer(name=o) if p: x.owner = frepple.demand(name=p) if q: x.minshipment = q if r != None: x.maxlateness = r except Exception as e: print("Error:", e) print('Loaded %d demands in %.2f seconds' % (cnt, time() - starttime))
print("shipoper < makeoper", shipoper < makeoper) print("shipoper != makeoper", shipoper != makeoper) print("shipoper == makeoper", shipoper == makeoper) print("shipoper == shipoper", shipoper == shipoper) try: print("makeoper == item", makeoper == item) except Exception as e: print("Catching exception %s: %s" % (e.__class__.__name__, e)) ### print("\nCreating a resource") frepple.resource(name="machine", maximum_calendar=frepple.calendar(name="Cal2")) ### print("\nCreating customers") mycustomer = frepple.customer(name="client") ### print("\nCreating locations") locA = frepple.location(name="locA") locB = frepple.location(name="locB") ### print("\nCreating some buffers") buf = frepple.buffer(name="end item", producing=choice, item=item) buf1 = frepple.buffer_procure(name="buffer1", description="My description", category="My category", location=locA,
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple # Uncomment the following lines to bypass the connection to odoo and use # a XML flat file alternative. This can be useful for debugging. # with open("my_path/my_data_file.xml", 'rb') as f: # frepple.readXMLdata(f.read().decode('utf-8'), False, False) # frepple.printsize() # return odoo_user = Parameter.getValue("odoo.user", database) odoo_password = settings.ODOO_PASSWORDS.get(database, None) if not settings.ODOO_PASSWORDS.get(database): odoo_password = Parameter.getValue("odoo.password", database) odoo_db = Parameter.getValue("odoo.db", database, None) odoo_url = Parameter.getValue("odoo.url", database, "").strip() if not odoo_url.endswith("/"): odoo_url = odoo_url + "/" odoo_company = Parameter.getValue("odoo.company", database, None) ok = True # Set debugFile=PathToXmlFile if you want frePPLe to read that file # rather than the data at url # else leave it to False debugFile = False # "c:/temp/frepple_data.xml" if not odoo_user and not debugFile: logger.error("Missing or invalid parameter odoo.user") ok = False if not odoo_password and not debugFile: logger.error("Missing or invalid parameter odoo.password") ok = False if not odoo_db and not debugFile: logger.error("Missing or invalid parameter odoo.db") ok = False if not odoo_url and not debugFile: logger.error("Missing or invalid parameter odoo.url") ok = False if not odoo_company and not debugFile: logger.error("Missing or invalid parameter odoo.company") ok = False odoo_language = Parameter.getValue("odoo.language", database, "en_US") if not ok and not debugFile: raise Exception("Odoo connector not configured correctly") # Connect to the odoo URL to GET data try: loglevel = int(Parameter.getValue("odoo.loglevel", database, "0")) except Exception: loglevel = 0 if not debugFile: url = "%sfrepple/xml?%s" % ( odoo_url, urlencode({ "database": odoo_db, "language": odoo_language, "company": odoo_company, "mode": cls.mode, }), ) try: request = Request(url) encoded = base64.encodestring( ("%s:%s" % (odoo_user, odoo_password)).encode("utf-8"))[:-1] request.add_header("Authorization", "Basic %s" % encoded.decode("ascii")) except HTTPError as e: logger.error("Error connecting to odoo at %s: %s" % (url, e)) raise e # Download and parse XML data with urlopen(request) as f: frepple.readXMLdata(f.read().decode("utf-8"), False, False, loglevel) else: # Download and parse XML data with open(debugFile, encoding="utf-8") as f: frepple.readXMLdata(f.read(), False, False, loglevel) # Hierarchy correction: Count how many items/locations/customers have no owner # If we find 2+ then we use All items/All customers/All locations as root # otherwise we assume that the hierarchy is correct rootItem = None for r in frepple.items(): if r.owner is None: if not rootItem: rootItem = r else: rootItem = None break rootLocation = None for r in frepple.locations(): if r.owner is None: if not rootLocation: rootLocation = r else: rootLocation = None break rootCustomer = None for r in frepple.customers(): if r.owner is None: if not rootCustomer: rootCustomer = r else: rootCustomer = None break if not rootItem: rootItem = frepple.item_mts(name="All items", source="odoo_%s" % cls.mode) for r in frepple.items(): if r.owner is None and r != rootItem: r.owner = rootItem if not rootLocation: rootLocation = frepple.location(name="All locations", source="odoo_%s" % cls.mode) for r in frepple.locations(): if r.owner is None and r != rootLocation: r.owner = rootLocation if not rootCustomer: rootCustomer = frepple.customer(name="All customers", source="odoo_%s" % cls.mode) for r in frepple.customers(): if r.owner is None and r != rootCustomer: r.owner = rootCustomer
print("shipoper != makeoper", shipoper != makeoper) print("shipoper == makeoper", shipoper == makeoper) print("shipoper == shipoper", shipoper == shipoper) try: print("makeoper == item", makeoper == item) except Exception as e: print("Catching exception %s: %s" % (e.__class__.__name__, e)) ### print("\nCreating a resource") frepple.resource(name="machine", maximum_calendar=frepple.calendar(name="Cal2")) ### print("\nCreating customers") mycustomer = frepple.customer(name="client") ### print("\nCreating locations") locA = frepple.location(name="locA") locB = frepple.location(name="locB") ### print("\nCreating some buffers") buf = frepple.buffer(name="end item", producing=choice, item=item) buf1 = frepple.buffer_procure(name="buffer1", description="My description", category="My category", location=locA,