[Umfuhrplanung] Add all products with external resources
This commit is contained in:
parent
1a1271c7e0
commit
f546255099
@ -6,8 +6,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from spielbergerscripts.spielbergerscripts.storageunit import Product, Bundle, NVE\n",
|
||||
"from spielbergerscripts.spielbergerscripts.connector import IBMConnector"
|
||||
"from spielbergerscripts.connector import IBMConnector\n",
|
||||
"from spielbergerscripts.primitives.batch import Batch\n",
|
||||
"from spielbergerscripts.primitives.nve import NVE\n",
|
||||
"from spielbergerscripts.primitives.product import Product, Bundle\n",
|
||||
"from spielbergerscripts.helpers.functions import spiel_prefix\n",
|
||||
"\n",
|
||||
"from dataclasses import dataclass"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -18,7 +23,8 @@
|
||||
"source": [
|
||||
"ibmconnect = IBMConnector(True)\n",
|
||||
"nveDict = ibmconnect.getNVETable()\n",
|
||||
"prodDict = ibmconnect.getProductsTable()"
|
||||
"prodDict = ibmconnect.getProductsTable()\n",
|
||||
"batchDict = ibmconnect.getBatchData()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -27,35 +33,78 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"extResource = dict()\n",
|
||||
"@dataclass\n",
|
||||
"class ProductArea:\n",
|
||||
" prod_nr: str\n",
|
||||
" area: str\n",
|
||||
" amount: int\n",
|
||||
" batches: list()\n",
|
||||
"\n",
|
||||
"for nve in nveDict.values():\n",
|
||||
" prod = prodDict.get(nve.article)\n",
|
||||
" def from_batch(batch):\n",
|
||||
" return ProductArea(\n",
|
||||
" batch.art_nr, batch.area, 0, list()\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" if not prod is None:\n",
|
||||
" if nve.area != '01' and nve.area != '02' and nve.area != prod.pickArea:\n",
|
||||
" extResource[(nve.article, nve.area, nve.vq)] = (prod.name, prod.bundle, extResource.get((nve.article, nve.area, nve.vq), ('', '', 0))[2] + nve.amount)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ART_WU = set()\n",
|
||||
" def add_batch(self, batch):\n",
|
||||
" assert(batch.area == batch.area)\n",
|
||||
"\n",
|
||||
"for (pNr, area, vq), (pName, bundle, amount) in extResource.items():\n",
|
||||
" if area != '36' or bundle.strip() == \"25 KG\" or bundle.strip() == \"BIG-BAG\" or bundle.strip() == \"1000 ST\":\n",
|
||||
" self.amount += batch.amount\n",
|
||||
" self.batches.append(batch)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class ProductAreas:\n",
|
||||
" prod_nr: str\n",
|
||||
" areas: dict()\n",
|
||||
"\n",
|
||||
" def addBatch(self, batch):\n",
|
||||
" parea = self.areas.get(batch.area, ProductArea.from_batch(batch))\n",
|
||||
" parea.add_batch(batch)\n",
|
||||
"\n",
|
||||
" self.areas[batch.area] = parea\n",
|
||||
"\n",
|
||||
"prod_areas = dict()\n",
|
||||
"for prod_nr, batches in batchDict.items():\n",
|
||||
" prod = prodDict.get(prod_nr, None)\n",
|
||||
" if prod is None:\n",
|
||||
" # print(f\"Error on batch {batch}\")\n",
|
||||
" continue\n",
|
||||
" print(f\"Lager {area}\\t{amount}x {pName.strip()} (#{pNr} / VQ{vq}) {bundle} auf Vorrat\")\n",
|
||||
" ART_WU.add(pNr)\n",
|
||||
"\n",
|
||||
"# zusätzlich\n",
|
||||
"ART_WU = ART_WU.union({\"062346\", \"062356\", \"062306\", \"062349\", \"062308\", \"062358\", \"062416\", \"104405\", \"104406\", \"104407\", \"104409\"})\n",
|
||||
" pa = ProductAreas(prod_nr, dict())\n",
|
||||
" for batch in batches:\n",
|
||||
" if batch.amount > 0 and (int(batch.vq) < 30 or int(batch.vq) == 39):\n",
|
||||
" pa.addBatch(batch)\n",
|
||||
"\n",
|
||||
"ART_WU = list(ART_WU)\n",
|
||||
"ART_WU.sort()"
|
||||
" prod_areas[pa.prod_nr] = pa"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ART_EXT = dict()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for prodarea in prod_areas.values():\n",
|
||||
" prod = prodDict[prodarea.prod_nr]\n",
|
||||
" if prod.bundle.strip() == \"25 KG\" or prod.bundle.strip() == \"20 KG\" or prod.bundle.strip() == \"BIG-BAG\" or prod.bundle.strip() == \"1000 ST\" or prod.bundle.strip() == \"LOSE\":\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" ext_res = []\n",
|
||||
" for aid, area in prodarea.areas.items():\n",
|
||||
" if aid == prod.pickArea or (aid != \"00\" and aid != \"33\" and aid != \"36\"):\n",
|
||||
" continue\n",
|
||||
" if area.amount > 0:\n",
|
||||
" ext_res.append((aid, area))\n",
|
||||
" print(f\"Lager {aid}\\t{area.amount}x {prod.name.strip()} (#{prodarea.prod_nr}) {prod.bundle} auf Vorrat\")\n",
|
||||
"\n",
|
||||
" if ext_res:\n",
|
||||
" ART_EXT[prodarea.prod_nr] = ext_res\n",
|
||||
"\n",
|
||||
"L_ART_EXT = list(ART_EXT.keys())\n",
|
||||
"L_ART_EXT.sort()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -78,6 +127,8 @@
|
||||
"from dataclasses import dataclass\n",
|
||||
"from datetime import date, datetime, timedelta\n",
|
||||
"\n",
|
||||
"from spielbergerscripts.helpers.functions import spiel_prefix\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class Request:\n",
|
||||
" ordernr: str\n",
|
||||
@ -107,7 +158,7 @@
|
||||
" ordernr=str(t[0]),\n",
|
||||
" cust_name=str(t[1]).strip(),\n",
|
||||
" delivdate=date.fromisoformat(szd),\n",
|
||||
" artnr=str(t[3]),\n",
|
||||
" artnr=spiel_prefix(str(t[3]), True),\n",
|
||||
" artname=str(t[4]),\n",
|
||||
" bundle=str(t[5]),\n",
|
||||
" stock=int(t[6]),\n",
|
||||
@ -158,21 +209,29 @@
|
||||
"\n",
|
||||
"vorlage = load_workbook(\"Umfuhrplanung_Vorlage.xlsx\")\n",
|
||||
"\n",
|
||||
"for prodNr in ART_WU:\n",
|
||||
"for prodNr in L_ART_EXT:\n",
|
||||
" aufbes_filt = [t for t in aufbes if t.artnr == prodNr]\n",
|
||||
"\n",
|
||||
" if len(aufbes_filt) > 0:\n",
|
||||
" prod = prodDict.get(prodNr)\n",
|
||||
" pareas = prod_areas.get(prodNr, None)\n",
|
||||
" if pareas is None:\n",
|
||||
" print(f\"Produktareas nicht gefunden: {prodNr}\")\n",
|
||||
"\n",
|
||||
" sheet = vorlage.copy_worksheet(vorlage[\"Vorlage\"])\n",
|
||||
" sheet.title = prodNr\n",
|
||||
" sheet['A1'] = f\"{prod.name.strip()} (#{prodNr})\"\n",
|
||||
" sheet['F1'] = f\"Kommiort {prod.pickArea}\"\n",
|
||||
" sheet['N1'] = f\"vom {FROM} bis inklussive {TO}\\n\\n\"\n",
|
||||
"\n",
|
||||
" first = aufbes_filt[0]\n",
|
||||
" bestand_00 = first.stock00\n",
|
||||
" bestand_01 = first.stock01\n",
|
||||
" bestand_33 = first.stock33\n",
|
||||
" bestand_36 = first.stock36\n",
|
||||
" verbleibend = {\n",
|
||||
" \"00\": pareas.areas.get(\"00\").amount if \"00\" in pareas.areas else 0,\n",
|
||||
" \"01\": pareas.areas.get(\"01\").amount if \"01\" in pareas.areas else 0,\n",
|
||||
" \"05\": pareas.areas.get(\"05\").amount if \"05\" in pareas.areas else 0,\n",
|
||||
" \"33\": pareas.areas.get(\"33\").amount if \"33\" in pareas.areas else 0,\n",
|
||||
" \"36\": pareas.areas.get(\"36\").amount if \"36\" in pareas.areas else 0,\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" we = first.upcoming\n",
|
||||
@ -180,13 +239,13 @@
|
||||
" we_area = first.upc_area\n",
|
||||
" we_done = False\n",
|
||||
"\n",
|
||||
" sheet['C2'] = bestand_00\n",
|
||||
" sheet['E2'] = bestand_33\n",
|
||||
" sheet['G2'] = bestand_36\n",
|
||||
" sheet['C2'] = verbleibend[\"00\"]\n",
|
||||
" sheet['E2'] = verbleibend[\"33\"]\n",
|
||||
" sheet['G2'] = verbleibend[\"36\"]\n",
|
||||
" sheet['B3'] = we\n",
|
||||
" sheet['D3'] = we_dat\n",
|
||||
"\n",
|
||||
" verbleibend = bestand_00\n",
|
||||
" verbleibendL = verbleibend\n",
|
||||
" bedarf_am = \"\"\n",
|
||||
" bedarf_durch = \"\"\n",
|
||||
" bedarf_auftrag = \"\"\n",
|
||||
@ -196,28 +255,38 @@
|
||||
" auftr_dennree = 0\n",
|
||||
" for t in aufbes_filt:\n",
|
||||
" if we > 0 and t.delivdate > we_dat:\n",
|
||||
" if we_area == \"00\":\n",
|
||||
" verbleibend += we\n",
|
||||
" if not we_area in {\"00\", \"05\", \"33\", \"36\"}:\n",
|
||||
" print(f\"Unable to handle we of {prod_nr} in area {we_area}\")\n",
|
||||
" if we_area != \"05\":\n",
|
||||
" verbleibendL[we_area] += we\n",
|
||||
" else:\n",
|
||||
" verbleibendL[prod.pickArea] += we\n",
|
||||
" \n",
|
||||
" sheet.append([\"\", \"Produktion\", we_dat, t.artnr, t.artname, t.bundle, \"\", f\"+{we}\", verbleibend, t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" sheet.append([\"\", \"Produktion\", we_dat, t.artnr, t.artname, t.bundle, \"\", f\"+{we}\", verbleibendL[\"00\"], verbleibendL[\"01\"], verbleibendL[\"33\"], verbleibendL[\"36\"], t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" we = 0\n",
|
||||
" if t.cust_name.strip() == \"dennree GmbH\":\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, t.ord_rem, verbleibend, t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, t.ord_rem, verbleibendL[\"00\"], verbleibendL[\"01\"], verbleibendL[\"33\"], verbleibendL[\"36\"], t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" for row in sheet.iter_cols(min_col=1, max_col=16, min_row=sheet.max_row, max_row=sheet.max_row):\n",
|
||||
" for cell in row:\n",
|
||||
" cell.fill = PatternFill(fgColor=RED, fill_type = 'solid')\n",
|
||||
" elif t.cust_name.strip() == \"Interne Umlagerung\":\n",
|
||||
" verbleibend += t.ordered\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, f\"+{t.ordered}\", verbleibend, t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" #verbleibend += t.ordered\n",
|
||||
" verbleibendL[\"00\"] += t.ordered\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, f\"+{t.ordered}\", verbleibendL[\"00\"], verbleibendL[\"01\"], verbleibendL[\"33\"], verbleibendL[\"36\"], t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" else:\n",
|
||||
" verbleibend -= t.ord_rem\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, t.ord_rem, verbleibend, t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" #verbleibend -= t.ord_rem\n",
|
||||
" verbleibendL[t.comm_area] -= t.ord_rem\n",
|
||||
" sheet.append([t.ordernr, t.cust_name, t.delivdate, t.artnr, t.artname, t.bundle, t.ordered, t.ord_rem, verbleibendL[\"00\"], verbleibendL[\"01\"], verbleibendL[\"33\"], verbleibendL[\"36\"], t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" \n",
|
||||
" if we > 0:\n",
|
||||
" if we_area == \"00\":\n",
|
||||
" verbleibend += we\n",
|
||||
" if not we_area in {\"00\", \"05\", \"33\", \"36\"}:\n",
|
||||
" print(f\"Unable to handle we of {prod_nr} in area {we_area}\")\n",
|
||||
" if we_area != \"05\":\n",
|
||||
" verbleibendL[we_area] += we\n",
|
||||
" else:\n",
|
||||
" verbleibendL[prod.pickArea] += we\n",
|
||||
" \n",
|
||||
" sheet.append([\"\", \"Produktion\", we_dat, t.artnr, t.artname, t.bundle, \"\", f\"+{we}\", verbleibend, t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
" sheet.append([\"\", \"Produktion\", we_dat, t.artnr, t.artname, t.bundle, \"\", f\"+{we}\", *verbleibendL.values(), t.upcoming, t.upc_date, t.upc_area, t.stock00, t.stock01, t.stock33, t.stock36])\n",
|
||||
"\n",
|
||||
"vorlage.save(f\"Umfuhrplanung_{FROM}.xlsx\")"
|
||||
]
|
||||
@ -248,7 +317,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.0"
|
||||
"version": "3.10.1"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user