Exemple #1
0
def exportOperationplans():
    print("Exporting operationplans...")
    starttime = time()
    writer = csv.writer(open("operations.csv",
                             "w",
                             newline="",
                             encoding="utf-8"),
                        quoting=csv.QUOTE_ALL)
    writer.writerow((
        "#reference",
        "operation",
        "quantity",
        "start date",
        "end date",
        "status",
        "unavailable",
        "owner",
    ))
    for i in frepple.operationplans():
        writer.writerow((
            i.reference,
            i.operation.name,
            i.quantity,
            i.start,
            i.end,
            i.status,
            i.unavailable,
            i.owner and i.owner.id or None,
        ))
    print("Exported operationplans in %.2f seconds" % (time() - starttime))
Exemple #2
0
 def publishPlan(cls):
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="webtoken"\r'
   yield '\r'
   yield '%s\r' % jwt.encode({
     'exp': round(time.time()) + 600,
     'user': odoo_user,
     },
     settings.DATABASES[database].get('SECRET_WEBTOKEN_KEY', settings.SECRET_KEY),
     algorithm='HS256').decode('ascii')
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     if i.ordertype == 'PO':
       if not i.item or not i.item.source or not i.item.source.startswith('odoo') or i.status not in ('proposed', 'approved'):
         continue
       cls.exported.append(i)
       yield '<operationplan id="%s" ordertype="PO" item=%s location=%s supplier=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d"/>' % (
         i.id, quoteattr(i.item.name), quoteattr(i.location.name),
         quoteattr(i.supplier.name), i.start, i.end, i.quantity,
         quoteattr(i.location.subcategory), quoteattr(i.item.subcategory),
         int(i.criticality)
         )
     elif i.ordertype == "MO":
       if not i.operation or not i.operation.source \
         or not i.operation.item \
         or not i.operation.source.startswith('odoo') \
         or i.status not in ('proposed', 'approved'):
           continue
       cls.exported.append(i)
       yield '<operationplan id="%s" ordertype="MO" item=%s location=%s operation=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d"/>' % (
         i.id, quoteattr(i.operation.item.name), quoteattr(i.operation.location.name),
         quoteattr(i.operation.name), i.start, i.end, i.quantity,
         quoteattr(i.operation.location.subcategory), quoteattr(i.operation.item.subcategory),
         int(i.criticality)
         )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #3
0
 def publishPlan(cls):
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="webtoken"\r'
   yield '\r'
   yield '%s\r' % jwt.encode({
     'exp': round(time.time()) + 600,
     'user': odoo_user,
     },
     settings.DATABASES[database].get('SECRET_WEBTOKEN_KEY', settings.SECRET_KEY),
     algorithm='HS256').decode('ascii')
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     if i.ordertype == 'PO':
       if not i.item or not i.item.source or not i.item.source.startswith('odoo') or i.status not in ('proposed', 'approved'):
         continue
       cls.exported.append(i)
       yield '<operationplan id="%s" ordertype="PO" item=%s location=%s supplier=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d"/>' % (
         i.id, quoteattr(i.item.name), quoteattr(i.location.name),
         quoteattr(i.supplier.name), i.start, i.end, i.quantity,
         quoteattr(i.location.subcategory), quoteattr(i.item.subcategory),
         int(i.criticality)
         )
     elif i.ordertype == "MO":
       if not i.operation or not i.operation.source or not i.operation.source.startswith('odoo') or i.status not in ('proposed', 'approved'):
         continue
       cls.exported.append(i)
       yield '<operationplan id="%s" ordertype="MO" item=%s location=%s operation=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d"/>' % (
         i.id, quoteattr(i.operation.item.name), quoteattr(i.operation.location.name),
         quoteattr(i.operation.name), i.start, i.end, i.quantity,
         quoteattr(i.operation.location.subcategory), quoteattr(i.operation.item.subcategory),
         int(i.criticality)
         )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #4
0
 def exportOperationPlans(self, cursor):
   '''
   Only locked operationplans are exported. That because we assume that
   all of those were given as input.
   '''
   with transaction.atomic(using=self.database, savepoint=False):
     print("Exporting operationplans...")
     starttime = time()
     cursor.execute("SELECT id FROM operationplan")
     primary_keys = set([ i[0] for i in cursor.fetchall() ])
     cursor.executemany(
       '''insert into operationplan
       (id,operation_id,quantity,startdate,enddate,status,source,lastmodified)
       values(%s,%s,%s,%s,%s,%s,%s,%s)''',
       [
        (
          i.id, i.operation.name, round(i.quantity, settings.DECIMAL_PLACES),
          str(i.start), str(i.end), i.status, i.source, self.timestamp
        )
        for i in frepple.operationplans()
        if i.locked and not i.operation.hidden and i.id not in primary_keys and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       '''update operationplan
        set operation_id=%s, quantity=%s, startdate=%s, enddate=%s, status=%s, source=%s, lastmodified=%s
        where id=%s''',
       [
        (
          i.operation.name, round(i.quantity, settings.DECIMAL_PLACES),
          str(i.start), str(i.end), i.status, i.source, self.timestamp, i.id
        )
        for i in frepple.operationplans()
        if i.locked and not i.operation.hidden and i.id in primary_keys and (not self.source or self.source == i.source)
       ])
     cursor.executemany(
       "update operationplan set owner_id=%s where id=%s",
       [
         (i.owner.id, i.id)
         for i in frepple.operationplans()
         if i.owner and not i.operation.hidden and i.locked and (not self.source or self.source == i.source)
       ])
     print('Exported operationplans in %.2f seconds' % (time() - starttime))
Exemple #5
0
def exportOperationplans():
  print("Exporting operationplans...")
  starttime = time()
  writer = csv.writer(open("operations.csv", "wb"), quoting=csv.QUOTE_ALL)
  writer.writerow(('#id','operation','quantity','start date','end date','locked'))
  for i in frepple.operationplans():
    writer.writerow((
       i.id, i.operation.name.encode(encoding,"ignore"), i.quantity, i.start, i.end,
       i.locked, i.unavailable, i.owner and i.owner.id or None
     ))
  print('Exported operationplans in %.2f seconds' % (time() - starttime))
Exemple #6
0
  def publishPlan():
    yield '--%s\r' % boundary
    yield 'Content-Disposition: form-data; name="database"\r'
    yield '\r'
    yield '%s\r' % odoo_db
    yield '--%s\r' % boundary
    yield 'Content-Disposition: form-data; name="language"\r'
    yield '\r'
    yield '%s\r' % odoo_language
    yield '--%s\r' % boundary
    yield 'Content-Disposition: form-data; name="company"\r'
    yield '\r'
    yield '%s\r' % odoo_company
    yield '--%s\r' % boundary
    yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
    yield 'Content-Type: application/xml\r'
    yield '\r'
    yield '<?xml version="1.0" encoding="UTF-8" ?>'
    yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
    # Export relevant operationplans
    yield '<operationplans>'
    for i in frepple.operationplans():
      b = None
      for j in i.flowplans:
        if j.quantity > 0:
          b = j.flow.buffer
      if not b or not b.source or not b.source.startswith('odoo') or i.locked:
        continue

      # Evaluate filter expressions
      if i.operation.name.startswith('Purchase'):
        if filter_export_purchase_order:
          if not eval(filter_export_purchase_order, {}, {'operationplan': i, 'buffer': b}):
            continue
      elif isinstance(i.operation, frepple.operation_itemdistribution):
        if filter_export_distribution_order:
          if not eval(filter_export_distribution_order, {}, {'operationplan': i, 'buffer': b}):
            continue
      else:
        if filter_export_manufacturing_order:
          if not eval(filter_export_manufacturing_order, {}, {'operationplan': i, 'buffer': b}):
            continue

      yield '<operationplan id="%s" operation=%s start="%s" end="%s" quantity="%s" location=%s item=%s criticality="%d"/>' % (
        i.id, quoteattr(i.operation.name),
        i.start, i.end, i.quantity,
        quoteattr(b.location.subcategory), quoteattr(b.item.subcategory),
        int(i.criticality)
        )
    yield '</operationplans>'
    yield '</plan>'
    yield '--%s--\r' % boundary
    yield '\r'
def exportOperationplans():
    print("Exporting operationplans...")
    starttime = time()
    writer = csv.writer(open("operations.csv", "wb"), quoting=csv.QUOTE_ALL)
    writer.writerow(
        ('#id', 'operation', 'quantity', 'start date', 'end date', 'locked'))
    for i in frepple.operationplans():
        writer.writerow(
            (i.id, i.operation.name.encode(encoding,
                                           "ignore"), i.quantity, i.start,
             i.end, i.locked, i.unavailable, i.owner and i.owner.id or None))
    print('Exported operationplans in %.2f seconds' % (time() - starttime))
Exemple #8
0
def exportOperationplans():
  print("Exporting operationplans...")
  starttime = time()
  writer = csv.writer(open("operations.csv", "w", newline="", encoding="utf-8"), quoting=csv.QUOTE_ALL)
  writer.writerow((
    '#reference', 'operation', 'quantity', 'start date', 'end date', 'status', 'unavailable', 'owner'
    ))
  for i in frepple.operationplans():
    writer.writerow((
       i.reference, i.operation.name, i.quantity, i.start, i.end,
       i.status, i.unavailable, i.owner and i.owner.id or None
     ))
  print('Exported operationplans in %.2f seconds' % (time() - starttime))
Exemple #9
0
def exportOperationplans():
    print("Exporting operationplans...")
    starttime = time()
    writer = csv.writer(open("operations.csv",
                             "w",
                             newline="",
                             encoding="utf-8"),
                        quoting=csv.QUOTE_ALL)
    writer.writerow(('#reference', 'operation', 'quantity', 'start date',
                     'end date', 'status', 'unavailable', 'owner'))
    for i in frepple.operationplans():
        writer.writerow(
            (i.reference, i.operation.name, i.quantity, i.start, i.end,
             i.status, i.unavailable, i.owner and i.owner.id or None))
    print('Exported operationplans in %.2f seconds' % (time() - starttime))
Exemple #10
0
 def publishPlan():
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="webtoken"\r'
   yield '\r'
   yield '%s\r' % jwt.encode({
     'exp': round(time.time()) + 600,
     'user': odoo_user,
     },
     settings.DATABASES[database].get('SECRET_WEBTOKEN_KEY', settings.SECRET_KEY),
     algorithm='HS256').decode('ascii')
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     b = None
     for j in i.flowplans:
       if j.quantity > 0:
         b = j.flow.buffer
     if not b or not b.source or not b.source.startswith('odoo') or i.locked:
       continue
     yield '<operationplan id="%s" operation=%s start="%s" end="%s" quantity="%s" location=%s item=%s criticality="%d"/>' % (
       i.id, quoteattr(i.operation.name),
       i.start, i.end, i.quantity,
       quoteattr(b.location.subcategory), quoteattr(b.item.subcategory),
       int(i.criticality)
       )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #11
0
 def publishPlan():
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="webtoken"\r'
   yield '\r'
   yield '%s\r' % jwt.encode({
     'exp': round(time.time()) + 600,
     'user': odoo_user,
     },
     settings.DATABASES[database].get('SECRET_WEBTOKEN_KEY', settings.SECRET_KEY),
     algorithm='HS256').decode('ascii')
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     b = None
     for j in i.flowplans:
       if j.quantity > 0:
         b = j.flow.buffer
     if not b or not b.source or not b.source.startswith('odoo') or i.locked:
       continue
     yield '<operationplan id="%s" operation=%s start="%s" end="%s" quantity="%s" location=%s item=%s criticality="%d"/>' % (
       i.id, quoteattr(i.operation.name),
       i.start, i.end, i.quantity,
       quoteattr(b.location.subcategory), quoteattr(b.item.subcategory),
       int(i.criticality)
       )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #12
0
 def publishPlan():
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     b = None
     for j in i.flowplans:
       if j.quantity > 0:
         b = j.flow.buffer
     if not b or b.source != 'odoo' or i.locked:
       continue
     yield '<operationplan id="%s" operation=%s start="%s" end="%s" quantity="%s" location=%s item=%s criticality="%d"/>' % (
       i.id, quoteattr(i.operation.name),
       i.start, i.end, i.quantity,
       quoteattr(b.location.subcategory), quoteattr(b.item.subcategory),
       int(i.criticality)
       )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #13
0
 def publishPlan():
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="database"\r'
   yield '\r'
   yield '%s\r' % odoo_db
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="language"\r'
   yield '\r'
   yield '%s\r' % odoo_language
   yield '--%s\r' % boundary
   yield 'Content-Disposition: form-data; name="company"\r'
   yield '\r'
   yield '%s\r' % odoo_company
   yield '--%s\r' % boundary
   yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
   yield 'Content-Type: application/xml\r'
   yield '\r'
   yield '<?xml version="1.0" encoding="UTF-8" ?>'
   yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
   # Export relevant operationplans
   yield '<operationplans>'
   for i in frepple.operationplans():
     b = None
     for j in i.flowplans:
       if j.quantity > 0:
         b = j.flow.buffer
     if not b or b.source != 'odoo' or i.locked:
       continue
     yield '<operationplan id="%s" operation=%s start="%s" end="%s" quantity="%s" location=%s item=%s criticality="%d"/>' % (
       i.id, quoteattr(i.operation.name),
       i.start, i.end, i.quantity,
       quoteattr(b.location.subcategory), quoteattr(b.item.subcategory),
       int(i.criticality)
       )
   yield '</operationplans>'
   yield '</plan>'
   yield '--%s--\r' % boundary
   yield '\r'
Exemple #14
0
def printModel(filename):
  '''
  A function that prints out all models to a file.
  '''

  # Open the output file
  output = open(filename,"wt")

  # Global settings
  print("Echoing global settings", file=output)
  print("Plan name:", frepple.settings.name, file=output)
  print("Plan description:", frepple.settings.description.encode('utf-8'), file=output)
  print("Plan current:", frepple.settings.current, file=output)

  # Solvers
  print("\nEchoing solvers:", file=output)
  for b in frepple.solvers():
    print("  Solver:", b.name, b.loglevel, getattr(b,'constraints',None), file=output)

  # Calendars
  print("\nEchoing calendars:", file=output)
  for b in frepple.calendars():
    print("  Calendar:", b.name, getattr(b,'default',None), file=output)
    for j in b.buckets:
      print("    Bucket:", getattr(j,'value',None), j.start, j.end, j.priority, file=output)

  # Customers
  print("\nEchoing customers:", file=output)
  for b in frepple.customers():
    print("  Customer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)

  # Locations
  print("\nEchoing locations:", file=output)
  for b in frepple.locations():
    print("  Location:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)

  # Items
  print("\nEchoing items:", file=output)
  for b in frepple.items():
    print("  Item:", b.name, b.description, b.category, b.subcategory, b.owner, b.operation, file=output)

  # Resources
  print("\nEchoing resources:", file=output)
  for b in frepple.resources():
    print("  Resource:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)
    for l in b.loads:
      print("    Load:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.loadplans:
      print("    Loadplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.startdate, l.enddate, file=output)

  # Buffers
  print("\nEchoing buffers:", file=output)
  for b in frepple.buffers():
    print("  Buffer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output)
    for l in b.flows:
      print("    Flow:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.flowplans:
      print("    Flowplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.date, file=output)

  # Operations
  print("\nEchoing operations:", file=output)
  for b in frepple.operations():
    print("  Operation:", b.name, b.description, b.category, b.subcategory, file=output)
    for l in b.loads:
      print("    Load:", l.resource.name, l.quantity, l.effective_start, l.effective_end, file=output)
    for l in b.flows:
      print("    Flow:", l.buffer.name, l.quantity, l.effective_start, l.effective_end, file=output)
    if isinstance(b, frepple.operation_alternate):
      for l in b.alternates:
        print("    Alternate:", l.name, file=output)
    if isinstance(b, frepple.operation_routing):
      for l in b.steps:
        print("    Step:", l.name, file=output)

  # Demands
  print("\nEchoing demands:", file=output)
  for b in frepple.demands():
    print("  Demand:", b.name, b.due, b.item.name, b.quantity, file=output)
    for i in b.operationplans:
      print("    Operationplan:", i.id, i.operation.name, i.quantity, i.end, file=output)

  # Operationplans
  print("\nEchoing operationplans:", file=output)
  for b in frepple.operationplans():
    print("  Operationplan:", b.operation.name, b.quantity, b.start, b.end, file=output)
    for s in b.operationplans:
      print("       ", s.operation.name, s.quantity, s.start, s.end, file=output)

  # Problems
  print("\nPrinting problems", file=output)
  for i in frepple.problems():
    print("  Problem:", i.entity, i.name, i.description, i.start, i.end, i.weight, file=output)
Exemple #15
0
 def publishPlan(cls):
     yield "--%s\r" % boundary
     yield 'Content-Disposition: form-data; name="webtoken"\r'
     yield "\r"
     yield "%s\r" % jwt.encode(
         {
             "exp": round(time.time()) + 600,
             "user": odoo_user
         },
         settings.DATABASES[database].get("SECRET_WEBTOKEN_KEY",
                                          settings.SECRET_KEY),
         algorithm="HS256",
     ).decode("ascii")
     yield "--%s\r" % boundary
     yield 'Content-Disposition: form-data; name="database"\r'
     yield "\r"
     yield "%s\r" % odoo_db
     yield "--%s\r" % boundary
     yield 'Content-Disposition: form-data; name="language"\r'
     yield "\r"
     yield "%s\r" % odoo_language
     yield "--%s\r" % boundary
     yield 'Content-Disposition: form-data; name="company"\r'
     yield "\r"
     yield "%s\r" % odoo_company
     yield "--%s\r" % boundary
     yield 'Content-Disposition: file; name="frePPLe plan"; filename="frepple_plan.xml"\r'
     yield "Content-Type: application/xml\r"
     yield "\r"
     yield '<?xml version="1.0" encoding="UTF-8" ?>'
     yield '<plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
     # Export relevant operationplans
     yield "<operationplans>"
     for i in frepple.operationplans():
         if i.ordertype == "PO":
             if (i.status not in ("proposed", "approved") or not i.item
                     or not i.item.source or not i.item.subcategory
                     or not i.location.subcategory
                     or not i.item.source.startswith("odoo")):
                 continue
             cls.exported.append(i)
             yield '<operationplan reference="%s" ordertype="PO" item=%s location=%s supplier=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d"/>' % (
                 i.reference,
                 quoteattr(i.item.name),
                 quoteattr(i.location.name),
                 quoteattr(i.supplier.name),
                 i.start,
                 i.end,
                 i.quantity,
                 quoteattr(i.location.subcategory),
                 quoteattr(i.item.subcategory),
                 int(i.criticality),
             )
         elif i.ordertype == "DO":
             if (i.status not in ("proposed", "approved") or not i.item
                     or not i.item.source or not i.item.subcategory
                     or not i.operation.origin.location.subcategory
                     or not i.operation.destination.location.subcategory
                     or not i.item.source.startswith("odoo")):
                 continue
             cls.exported.append(i)
             yield '<operationplan status="%s" reference="%s" ordertype="DO" item=%s origin=%s destination=%s start="%s" end="%s" quantity="%s" origin_id=%s destination_id=%s item_id=%s criticality="%d"/>' % (
                 i.status,
                 i.reference,
                 quoteattr(i.operation.destination.item.name),
                 quoteattr(i.operation.origin.location.name),
                 quoteattr(i.operation.destination.location.name),
                 i.start,
                 i.end,
                 i.quantity,
                 quoteattr(i.operation.origin.location.subcategory),
                 quoteattr(
                     i.operation.destination.location.subcategory),
                 quoteattr(i.operation.destination.item.subcategory),
                 int(i.criticality),
             )
         elif i.ordertype == "MO":
             if (i.status not in ("proposed", "approved")
                     or not i.operation or not i.operation.source
                     or not i.operation.item
                     or not i.operation.source.startswith("odoo")
                     or not i.operation.item.subcategory
                     or not i.operation.location.subcategory):
                 continue
             cls.exported.append(i)
             res = set()
             try:
                 for j in i.loadplans:
                     res.add(j.resource.name)
             except Exception:
                 pass
             demand = {}
             demand_str = ""
             for d in i.pegging_demand:
                 demand[d.demand] = d.quantity
                 demand_str += "%s:%s, " % (d.demand, d.quantity)
             if demand_str:
                 demand_str = demand_str[:-2]
             yield '<operationplan reference="%s" ordertype="MO" item=%s location=%s operation=%s start="%s" end="%s" quantity="%s" location_id=%s item_id=%s criticality="%d" resource=%s demand=%s/>' % (
                 i.reference,
                 quoteattr(i.operation.item.name),
                 quoteattr(i.operation.location.name),
                 quoteattr(i.operation.name),
                 i.start,
                 i.end,
                 i.quantity,
                 quoteattr(i.operation.location.subcategory),
                 quoteattr(i.operation.item.subcategory),
                 int(i.criticality),
                 quoteattr(",".join(res)),
                 quoteattr(demand_str),
             )
     yield "</operationplans>"
     yield "</plan>"
     yield "--%s--\r" % boundary
     yield "\r"
Exemple #16
0
def printModel(filename):
    '''
  A function that prints out all models to a file.
  '''
    # Open the output file
    with open(filename, "wt", encoding='utf-8') as output:

        # Global settings
        print("Echoing global settings", file=output)
        print("Plan name:", frepple.settings.name, file=output)
        print("Plan description:", frepple.settings.description, file=output)
        print("Plan current:", frepple.settings.current, file=output)

        # Solvers
        print("\nEchoing solvers:", file=output)
        for b in frepple.solvers():
            print("  Solver:",
                  b.name,
                  b.loglevel,
                  getattr(b, 'constraints', None),
                  file=output)

        # Calendars
        print("\nEchoing calendars:", file=output)
        for b in frepple.calendars():
            print("  Calendar:",
                  b.name,
                  getattr(b, 'default', None),
                  file=output)
            for j in b.buckets:
                print("    Bucket:",
                      getattr(j, 'value', None),
                      j.start,
                      j.end,
                      j.priority,
                      file=output)

        # Customers
        print("\nEchoing customers:", file=output)
        for b in frepple.customers():
            print("  Customer:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)

        # Locations
        print("\nEchoing locations:", file=output)
        for b in frepple.locations():
            print("  Location:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)

        # Items
        print("\nEchoing items:", file=output)
        for b in frepple.items():
            print("  Item:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  b.operation,
                  file=output)

        # Resources
        print("\nEchoing resources:", file=output)
        for b in frepple.resources():
            print("  Resource:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)
            for l in b.loads:
                print("    Load:",
                      l.operation.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.loadplans:
                print("    Loadplan:",
                      l.operationplan.id,
                      l.operationplan.operation.name,
                      l.quantity,
                      l.startdate,
                      l.enddate,
                      file=output)

        # Buffers
        print("\nEchoing buffers:", file=output)
        for b in frepple.buffers():
            print("  Buffer:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  b.owner,
                  file=output)
            for l in b.flows:
                print("    Flow:",
                      l.operation.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.flowplans:
                print("    Flowplan:",
                      l.operationplan.id,
                      l.operationplan.operation.name,
                      l.quantity,
                      l.date,
                      file=output)

        # Operations
        print("\nEchoing operations:", file=output)
        for b in frepple.operations():
            print("  Operation:",
                  b.name,
                  b.description,
                  b.category,
                  b.subcategory,
                  file=output)
            for l in b.loads:
                print("    Load:",
                      l.resource.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            for l in b.flows:
                print("    Flow:",
                      l.buffer.name,
                      l.quantity,
                      l.effective_start,
                      l.effective_end,
                      file=output)
            if isinstance(b, frepple.operation_alternate):
                for l in b.alternates:
                    print("    Alternate:",
                          l[0].name,
                          l[1],
                          l[2],
                          l[3],
                          file=output)
            if isinstance(b, frepple.operation_routing):
                for l in b.steps:
                    print("    Step:", l.name, file=output)

        # Demands
        print("\nEchoing demands:", file=output)
        for b in frepple.demands():
            print("  Demand:",
                  b.name,
                  b.due,
                  b.item.name,
                  b.quantity,
                  file=output)
            for i in b.operationplans:
                print("    Operationplan:",
                      i.id,
                      i.operation.name,
                      i.quantity,
                      i.end,
                      file=output)

        # Operationplans
        print("\nEchoing operationplans:", file=output)
        for b in frepple.operationplans():
            print("  Operationplan:",
                  b.operation.name,
                  b.quantity,
                  b.start,
                  b.end,
                  file=output)
            for s in b.operationplans:
                print("       ",
                      s.operation.name,
                      s.quantity,
                      s.start,
                      s.end,
                      file=output)

        # Problems
        print("\nPrinting problems", file=output)
        for i in frepple.problems():
            print("  Problem:",
                  i.entity,
                  i.name,
                  i.description,
                  i.start,
                  i.end,
                  i.weight,
                  file=output)