コード例 #1
0
ファイル: commands.py プロジェクト: suribes/frepple
  def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
    import frepple

    # Create a solver where the plan type are defined by an environment variable
    try:
      plantype = int(os.environ['FREPPLE_PLANTYPE'])
    except:
      plantype = 1  # Default is a constrained plan
    try:
      constraint = int(os.environ['FREPPLE_CONSTRAINT'])
    except:
      constraint = 15  # Default is with all constraints enabled
    cls.solver = frepple.solver_mrp(
      constraints=constraint,
      plantype=plantype,
      loglevel=int(Parameter.getValue('plan.loglevel', database, 0)),
      lazydelay=int(Parameter.getValue('lazydelay', database, '86400')),
      allowsplits=(Parameter.getValue('allowsplits', database, 'true').lower() == "true"),
      rotateresources=(Parameter.getValue('plan.rotateResources', database, 'true').lower() == "true"),
      plansafetystockfirst=(Parameter.getValue('plan.planSafetyStockFirst', database, 'false').lower() != "false"),
      iterationmax=int(Parameter.getValue('plan.iterationmax', database, '0'))
      )
    if hasattr(cls, 'debugResource'):
      cls.solver.userexit_resource = cls.debugResource
    if hasattr(cls, 'debugDemand'):
      cls.solver.userexit_demand = cls.debugDemand
    if hasattr(cls, 'debugOperation'):
      cls.solver.userexit_operation = cls.debugOperation
    print("Plan type: ", plantype)
    print("Constraints: ", constraint)
    cls.solver.solve()
    frepple.printsize()
コード例 #2
0
    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)
        odoo_url = Parameter.getValue("odoo.url", database)
        odoo_company = Parameter.getValue("odoo.company", database)
        ok = True
        if not odoo_user:
            logger.error("Missing or invalid parameter odoo.user")
            ok = False
        if not odoo_password:
            logger.error("Missing or invalid parameter odoo.password")
            ok = False
        if not odoo_db:
            logger.error("Missing or invalid parameter odoo.db")
            ok = False
        if not odoo_url:
            logger.error("Missing or invalid parameter odoo.url")
            ok = False
        if not odoo_company:
            logger.error("Missing or invalid parameter odoo.company")
            ok = False
        odoo_language = Parameter.getValue("odoo.language", database, 'en_US')
        if not ok:
            raise Exception("Odoo connector not configured correctly")

        # Connect to the odoo URL to GET data
        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)
        frepple.printsize()
コード例 #3
0
  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)

    if settings.ODOO_PASSWORDS.get(database) == '':
      odoo_password = Parameter.getValue("odoo.password", database)
    else:
      odoo_password = settings.ODOO_PASSWORDS.get(database)

    odoo_db = Parameter.getValue("odoo.db", database)
    odoo_url = Parameter.getValue("odoo.url", database)
    odoo_company = Parameter.getValue("odoo.company", database)
    ok = True
    if not odoo_user:
      print("Missing or invalid parameter odoo.user")
      ok = False
    if not odoo_password:
      print("Missing or invalid parameter odoo.password")
      ok = False
    if not odoo_db:
      print("Missing or invalid parameter odoo.db")
      ok = False
    if not odoo_url:
      print("Missing or invalid parameter odoo.url")
      ok = False
    if not odoo_company:
      print("Missing or invalid parameter odoo.company")
      ok = False
    odoo_language = Parameter.getValue("odoo.language", database, 'en_US')
    if not ok:
      raise Exception("Odoo connector not configured correctly")

    # Connect to the odoo URL to GET data
    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:
      print("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)
    frepple.printsize()
コード例 #4
0
 def run(database=DEFAULT_DB_ALIAS, **kwargs):
   '''
   It is important that all data is loaded at this point. We build out
   all buffers and their supply paths at this point.
   If new replenishment methods are added later on, they will not be used.
   '''
   import frepple
   frepple.printsize()
コード例 #5
0
ファイル: commands.py プロジェクト: jimsdog/frepple
    def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
        import frepple

        # Determine log level
        loglevel = int(Parameter.getValue("plan.loglevel", database, 0))
        if cls.task and cls.task.user:
            maxloglevel = cls.task.user.getMaxLoglevel(database)
            if loglevel > maxloglevel:
                loglevel = maxloglevel

        # Create a solver where the plan type are defined by an environment variable
        try:
            plantype = int(os.environ["FREPPLE_PLANTYPE"])
        except:
            plantype = 1  # Default is a constrained plan
        try:
            constraint = int(os.environ["FREPPLE_CONSTRAINT"])
        except:
            constraint = 15  # Default is with all constraints enabled
        cls.solver = frepple.solver_mrp(
            constraints=constraint,
            plantype=plantype,
            loglevel=loglevel,
            lazydelay=int(Parameter.getValue("lazydelay", database, "86400")),
            allowsplits=(Parameter.getValue("allowsplits", database,
                                            "true").lower() == "true"),
            minimumdelay=int(
                Parameter.getValue("plan.minimumdelay", database, "3600")),
            rotateresources=(Parameter.getValue("plan.rotateResources",
                                                database,
                                                "true").lower() == "true"),
            plansafetystockfirst=(Parameter.getValue(
                "plan.planSafetyStockFirst", database, "false").lower() !=
                                  "false"),
            iterationmax=int(
                Parameter.getValue("plan.iterationmax", database, "0")),
            resourceiterationmax=int(
                Parameter.getValue("plan.resourceiterationmax", database,
                                   "500")),
            administrativeleadtime=86400 * float(
                Parameter.getValue("plan.administrativeLeadtime", database,
                                   "0")),
            autofence=86400 * float(
                Parameter.getValue("plan.autoFenceOperations", database, "0")),
        )
        if hasattr(cls, "debugResource"):
            cls.solver.userexit_resource = cls.debugResource
        if hasattr(cls, "debugDemand"):
            cls.solver.userexit_demand = cls.debugDemand
        if hasattr(cls, "debugOperation"):
            cls.solver.userexit_operation = cls.debugOperation
        logger.info("Plan type: %s" % plantype)
        logger.info("Constraints: %s" % constraint)
        cls.solver.solve()
        frepple.printsize()
コード例 #6
0
ファイル: commands.py プロジェクト: apik-pci/frePPLe
    def run(database=DEFAULT_DB_ALIAS, **kwargs):
        import frepple

        # Auxiliary functions for debugging
        def debugResource(res, mode):
            # if res.name != 'my favorite resource': return
            print("=> Situation on resource", res.name)
            for j in res.loadplans:
                print("=>  ", j.quantity, j.onhand, j.startdate, j.enddate,
                      j.operation.name, j.operationplan.quantity, j.setup)

        def debugDemand(dem, mode):
            if dem.name == 'my favorite demand':
                print("=> Starting to plan demand ", dem.name)
                solver.loglevel = 2
            else:
                solver.loglevel = 0

        # Create a solver where the plan type are defined by an environment variable
        try:
            plantype = int(os.environ['FREPPLE_PLANTYPE'])
        except:
            plantype = 1  # Default is a constrained plan
        try:
            constraint = int(os.environ['FREPPLE_CONSTRAINT'])
        except:
            constraint = 15  # Default is with all constraints enabled
        solver = frepple.solver_mrp(
            constraints=constraint,
            plantype=plantype,
            loglevel=int(Parameter.getValue('plan.loglevel', database, 0)),
            lazydelay=int(Parameter.getValue('lazydelay', database, '86400')),
            allowsplits=(Parameter.getValue('allowsplits', database,
                                            'true').lower() == "true"),
            rotateresources=(Parameter.getValue('plan.rotateResources',
                                                database,
                                                'true').lower() == "true"),
            plansafetystockfirst=(Parameter.getValue(
                'plan.planSafetyStockFirst', database, 'false').lower() !=
                                  "false"),
            iterationmax=int(
                Parameter.getValue('plan.iterationmax', database, '0'))
            #userexit_resource=debugResource,
            #userexit_demand=debugDemand
        )
        print("Plan type: ", plantype)
        print("Constraints: ", constraint)
        solver.solve()
        frepple.printsize()
コード例 #7
0
ファイル: commands.py プロジェクト: frePPLe/frePPLe
  def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
    import frepple

    # Determine log level
    loglevel = int(Parameter.getValue('plan.loglevel', database, 0))
    if cls.task and cls.task.user:
      maxloglevel = cls.task.user.getMaxLoglevel(database)
      if loglevel > maxloglevel:
        loglevel = maxloglevel

    # Create a solver where the plan type are defined by an environment variable
    try:
      plantype = int(os.environ['FREPPLE_PLANTYPE'])
    except:
      plantype = 1  # Default is a constrained plan
    try:
      constraint = int(os.environ['FREPPLE_CONSTRAINT'])
    except:
      constraint = 15  # Default is with all constraints enabled
    cls.solver = frepple.solver_mrp(
      constraints=constraint,
      plantype=plantype,
      loglevel=loglevel,
      lazydelay=int(Parameter.getValue('lazydelay', database, '86400')),
      allowsplits=(Parameter.getValue('allowsplits', database, 'true').lower() == "true"),
      minimumdelay=int(Parameter.getValue('plan.minimumdelay', database, '0')),
      rotateresources=(Parameter.getValue('plan.rotateResources', database, 'true').lower() == "true"),
      plansafetystockfirst=(Parameter.getValue('plan.planSafetyStockFirst', database, 'false').lower() != "false"),
      iterationmax=int(Parameter.getValue('plan.iterationmax', database, '0')),
      resourceiterationmax=int(Parameter.getValue('plan.resourceiterationmax', database, '500')),
      administrativeleadtime=86400 * float(Parameter.getValue('plan.administrativeLeadtime', database, '0')),
      autofence=86400 * float(Parameter.getValue("plan.autoFenceOperations", database, '0'))
      )
    if hasattr(cls, 'debugResource'):
      cls.solver.userexit_resource = cls.debugResource
    if hasattr(cls, 'debugDemand'):
      cls.solver.userexit_demand = cls.debugDemand
    if hasattr(cls, 'debugOperation'):
      cls.solver.userexit_operation = cls.debugOperation
    logger.info("Plan type: %s" % plantype)
    logger.info("Constraints: %s" % constraint)
    cls.solver.solve()
    frepple.printsize()
コード例 #8
0
  def run(database=DEFAULT_DB_ALIAS, **kwargs):
    import frepple
    # Auxiliary functions for debugging
    def debugResource(res, mode):
      # if res.name != 'my favorite resource': return
      print("=> Situation on resource", res.name)
      for j in res.loadplans:
        print("=>  ", j.quantity, j.onhand, j.startdate, j.enddate, j.operation.name, j.operationplan.quantity, j.setup)

    def debugDemand(dem, mode):
      if dem.name == 'my favorite demand':
        print("=> Starting to plan demand ", dem.name)
        solver.loglevel = 2
      else:
        solver.loglevel = 0

    # Create a solver where the plan type are defined by an environment variable
    try:
      plantype = int(os.environ['FREPPLE_PLANTYPE'])
    except:
      plantype = 1  # Default is a constrained plan
    try:
      constraint = int(os.environ['FREPPLE_CONSTRAINT'])
    except:
      constraint = 15  # Default is with all constraints enabled
    solver = frepple.solver_mrp(
      constraints=constraint,
      plantype=plantype,
      loglevel=int(Parameter.getValue('plan.loglevel', database, 0)),
      lazydelay=int(Parameter.getValue('lazydelay', database, '86400')),
      allowsplits=(Parameter.getValue('allowsplits', database, 'true').lower() == "true"),
      rotateresources=(Parameter.getValue('plan.rotateResources', database, 'true').lower() == "true"),
      plansafetystockfirst=(Parameter.getValue('plan.planSafetyStockFirst', database, 'false').lower() != "false"),
      iterationmax=int(Parameter.getValue('plan.iterationmax', database, '0'))
      #userexit_resource=debugResource,
      #userexit_demand=debugDemand
      )
    print("Plan type: ", plantype)
    print("Constraints: ", constraint)
    solver.solve()
    frepple.printsize()
コード例 #9
0
ファイル: python_3.py プロジェクト: albertca/frePPLe
print(mycustomer.toXML())
print(locA.toXML())
print(opplan.toXML())
print(item.toXML())
print(order1.toXML())
print(buf1.toXML())
print(makeoper.toXML())
for i in frepple.problems():
  print(i.toXML())

###
print("\nPrinting some models in XML format to a file")
with open("output.3.xml","wt") as output:
  mycustomer.toXML('P',output)
  locA.toXML('P',output)
  opplan.toXML('P',output)
  item.toXML('P',output)
  order1.toXML('P',output)
  buf1.toXML('P',output)
  makeoper.toXML('P',output)
  for i in frepple.problems():
    i.toXML('P',output)

###
print("\nDocumenting all available Python entities defined by frePPLe:")
printExtensions()

###
print("\nPrinting memory consumption estimate:")
frepple.printsize()
コード例 #10
0
 def run(database=DEFAULT_DB_ALIAS, **kwargs):
     import frepple
     frepple.erase(True)
     frepple.printsize()
コード例 #11
0

if __name__ == "__main__":
    # Select database
    try:
        db = os.environ['FREPPLE_DATABASE'] or DEFAULT_DB_ALIAS
    except:
        db = DEFAULT_DB_ALIAS

    # Use the test database if we are running the test suite
    if 'FREPPLE_TEST' in os.environ:
        settings.DATABASES[db]['NAME'] = settings.DATABASES[db]['TEST']['NAME']

    printWelcome(database=db)
    logProgress(1, db)
    frepple.printsize()
    print("\nStart loading data from the database at",
          datetime.now().strftime("%H:%M:%S"))
    from freppledb.execute.load import loadData
    loadData(database=db, filter=None).run()
    frepple.printsize()
    logProgress(33, db)
    print("\nStart plan generation at", datetime.now().strftime("%H:%M:%S"))
    createPlan(db)
    frepple.printsize()
    logProgress(66, db)

    #print("\nStart exporting static model to the database at", datetime.now().strftime("%H:%M:%S"))
    #from freppledb.execute.export_database_static import exportStaticModel
    #exportStaticModel(database=db, source=None).run()
コード例 #12
0
ファイル: commands.py プロジェクト: qq470647251/frePPLe
 def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
     import frepple
     from freppledb.execute.load import loadData
     loadData(database=database, filter=cls.filter).runDynamic()
     frepple.printsize()
コード例 #13
0
 def run(cls, database=DEFAULT_DB_ALIAS, **kwargs):
   import frepple
   from freppledb.execute.load import loadData
   loadData(database=database, filter=cls.filter).runDynamic()
   frepple.printsize()
コード例 #14
0
 def run(database=DEFAULT_DB_ALIAS, **kwargs):
   import frepple
   frepple.erase(True)
   frepple.printsize()