From 7f88e9a232229bf6b9893114880fedecffa4a91d Mon Sep 17 00:00:00 2001 From: Filip Krumpe Date: Mon, 11 Oct 2021 13:34:00 +0200 Subject: [PATCH] BugFix --- Umfuhrplanung_direct.ipynb | 398 ++++++++++++++++++------------------- 1 file changed, 199 insertions(+), 199 deletions(-) diff --git a/Umfuhrplanung_direct.ipynb b/Umfuhrplanung_direct.ipynb index e19ba07..1a3e13c 100644 --- a/Umfuhrplanung_direct.ipynb +++ b/Umfuhrplanung_direct.ipynb @@ -3,246 +3,246 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "from spielbergerscripts.spielbergerscripts.storageunit import Product, Bundle, NVE\r\n", + "from spielbergerscripts.spielbergerscripts.storageunit import Product, Bundle, NVE\n", "from spielbergerscripts.spielbergerscripts.connector import IBMConnector" - ], - "outputs": [], - "metadata": {} + ] }, { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "ibmconnect = IBMConnector(True)\r\n", - "nveDict = ibmconnect.getNVETable()\r\n", + "ibmconnect = IBMConnector(True)\n", + "nveDict = ibmconnect.getNVETable()\n", "prodDict = ibmconnect.getProductsTable()" - ], - "outputs": [], - "metadata": {} + ] }, { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "extResource = dict()\r\n", - "\r\n", - "for nve in nveDict.values():\r\n", - " prod = prodDict.get(nve.article)\r\n", - "\r\n", - " if not prod is None:\r\n", - " if nve.area != '01' and nve.area != '02' and nve.area != prod.pickArea:\r\n", + "extResource = dict()\n", + "\n", + "for nve in nveDict.values():\n", + " prod = prodDict.get(nve.article)\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)" - ], - "outputs": [], - "metadata": {} + ] }, { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "ART_WU = set()\r\n", - "\r\n", - "for (pNr, area, vq), (pName, bundle, amount) in extResource.items():\r\n", - " if area != '36' or bundle.strip() == \"25 KG\" or bundle.strip() == \"BIG-BAG\" or bundle.strip() == \"1000 ST\":\r\n", - " continue\r\n", - " print(f\"Lager {area}\\t{amount}x {pName.strip()} (#{pNr} / VQ{vq}) {bundle} auf Vorrat\")\r\n", - " ART_WU.add(pNr)\r\n", - "\r\n", - "# zusätzlich\r\n", - "ART_WU.union({\"062346\", \"062356\", \"062306\", \"062416\", \"104406\", \"104409\"})\r\n", - "\r\n", - "ART_WU = list(ART_WU)\r\n", + "ART_WU = set()\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", + " 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\", \"062416\", \"104406\", \"104409\"})\n", + "\n", + "ART_WU = list(ART_WU)\n", "ART_WU.sort()" - ], - "outputs": [], - "metadata": {} + ] }, { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "\r\n", - "from openpyxl import load_workbook\r\n", - "from openpyxl.styles import Color, PatternFill\r\n", - "\r\n", - "from dataclasses import dataclass\r\n", - "from datetime import date, datetime, timedelta\r\n", - "\r\n", - "@dataclass\r\n", - "class Request:\r\n", - " ordernr: str\r\n", - " cust_name: str\r\n", - " delivdate: date\r\n", - " artnr: str\r\n", - " artname: str\r\n", - " bundle: str\r\n", - " stock: int\r\n", - " ordered: int\r\n", - " ord_rem: int\r\n", - " available: int\r\n", - " avail_wo_36:int\r\n", - " upcoming: int\r\n", - " upc_date: str\r\n", - " upc_area: str\r\n", - " stock00: int\r\n", - " stock01: int\r\n", - " stock33: int\r\n", - " stock36: int\r\n", - "\r\n", - " def from_tuple(t):\r\n", - " d = str(t[2])\r\n", - " szd = f\"20{d[-2:]}-{d[-4:-2]}-{int(d[:-4]):02d}\"\r\n", - " return Request(\r\n", - " ordernr=str(t[0]),\r\n", - " cust_name=str(t[1]).strip(),\r\n", - " delivdate=date.fromisoformat(szd),\r\n", - " artnr=str(t[3]),\r\n", - " artname=str(t[4]),\r\n", - " bundle=str(t[5]),\r\n", - " stock=int(t[6]),\r\n", - " ordered=int(t[7]),\r\n", - " ord_rem=int(t[23]),\r\n", - " available=int(t[9]),\r\n", - " avail_wo_36=int(t[28]),\r\n", - " upcoming=int(t[10]),\r\n", - " upc_date=date.fromisoformat(f\"20{str(t[11])[-2:]}-{str(t[11])[-4:-2]}-{int(str(t[11])[:-4]):02d}\") if int(t[10]) > 0 else None,\r\n", - " upc_area=str(t[12]),\r\n", - " stock00=int(t[24]),\r\n", - " stock01=int(t[25]),\r\n", - " stock33=int(t[26]),\r\n", - " stock36=int(t[27]),\r\n", - " )\r\n", - "\r\n", - "\r\n", - "RED = Color(rgb='E6B8B7')\r\n", - "\r\n", - "FROM = datetime.now().date()\r\n", - "TO = FROM + timedelta(days=14)\r\n", - "\r\n", - "if FROM.month == TO.month and FROM.year == TO.year:\r\n", - " aufbes = list(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(FROM.day, TO.day, FROM.month, FROM.year)))\r\n", - "else:\r\n", - " temp_to = FROM + timedelta(days = 31 if FROM.day >= 15 else 20)\r\n", - " temp_to = temp_to.replace(day = 1)\r\n", - " print(f\"Temp to = {temp_to}\")\r\n", - " temp_to = temp_to - timedelta(days=1)\r\n", - " print(f\"Temp to = {temp_to}\")\r\n", - " aufbes = list(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(FROM.day, temp_to.day, FROM.month, FROM.year)))\r\n", - " temp_from = temp_to + timedelta(days=1)\r\n", - " print(f\"Temp from = {temp_from}\")\r\n", - " while temp_from.month < TO.month:\r\n", - " temp_to = FROM + timedelta(days = 31 if FROM.day >= 15 else 20)\r\n", - " temp_to = temp_to.replace(day=1)\r\n", - " temp_to = temp_to - timedelta(days=1)\r\n", - " aufbes.extend(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(temp_from.day, temp_to.day, temp_from.month, temp_from.year)))\r\n", - " temp_from = temp_to + timedelta(days=1)\r\n", - " \r\n", - " # last month. temp_from is the current TO month\r\n", - " aufbes.extend(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(temp_from.day, TO.day, temp_from.month, temp_from.year)))\r\n", - " \r\n", - "\r\n", - "\r\n", - "aufbes.sort(key = lambda a: a.delivdate)\r\n", - "\r\n", - "vorlage = load_workbook(\"Umfuhrplanung_Vorlage.xlsx\")\r\n", - "\r\n", - "for prodNr in ART_WU:\r\n", - " aufbes_filt = [t for t in aufbes if t.artnr == prodNr]\r\n", - "\r\n", - " if len(aufbes_filt) > 0:\r\n", - " prod = prodDict.get(prodNr)\r\n", - " sheet = vorlage.copy_worksheet(vorlage[\"Vorlage\"])\r\n", - " sheet.title = prodNr\r\n", - " sheet['A1'] = f\"{prod.name.strip()} (#{prodNr})\"\r\n", - " sheet['N1'] = f\"vom {FROM} bis inklussive {TO}\\n\\n\"\r\n", - "\r\n", - " first = aufbes_filt[0]\r\n", - " bestand_00 = first.stock00\r\n", - " bestand_01 = first.stock01\r\n", - " bestand_33 = first.stock33\r\n", - " bestand_36 = first.stock36\r\n", - " \r\n", - "\r\n", - " we = first.upcoming\r\n", - " we_dat = first.upc_date\r\n", - " we_area = first.upc_area\r\n", - " we_done = False\r\n", - "\r\n", - " sheet['C2'] = bestand_00\r\n", - " sheet['E2'] = bestand_33\r\n", - " sheet['G2'] = bestand_36\r\n", - " sheet['B3'] = we\r\n", - " sheet['D3'] = we_dat\r\n", - "\r\n", - " verbleibend = bestand_00\r\n", - " bedarf_am = \"\"\r\n", - " bedarf_durch = \"\"\r\n", - " bedarf_auftrag = \"\"\r\n", - " umfuhrmenge = 0\r\n", - " umfuhr_an = \"\"\r\n", - " auftrag = 0\r\n", - " auftr_dennree = 0\r\n", - " for t in aufbes_filt:\r\n", - " if we > 0 and t.delivdate > we_dat:\r\n", - " if we_area == \"00\":\r\n", - " verbleibend += we\r\n", - " \r\n", - " sheet.append([\"\", \"Produktion\", we_dat, t.delivdate, 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])\r\n", - " we = 0\r\n", - " if t.cust_name.strip() == \"dennree GmbH\":\r\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])\r\n", - " for row in sheet.iter_cols(min_col=1, max_col=16, min_row=sheet.max_row, max_row=sheet.max_row):\r\n", - " for cell in row:\r\n", - " cell.fill = PatternFill(fgColor=RED, fill_type = 'solid')\r\n", - " elif t.cust_name.strip() == \"Interne Umlagerung\":\r\n", - " verbleibend += t.ordered\r\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])\r\n", - " else:\r\n", - " verbleibend -= t.ord_rem\r\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])\r\n", - " \r\n", - " if we > 0:\r\n", - " if we_area == \"00\":\r\n", - " verbleibend += we\r\n", - " \r\n", - " sheet.append([\"\", \"Produktion\", we_dat, t.delivdate, 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])\r\n", - "\r\n", + "\n", + "from openpyxl import load_workbook\n", + "from openpyxl.styles import Color, PatternFill\n", + "\n", + "from dataclasses import dataclass\n", + "from datetime import date, datetime, timedelta\n", + "\n", + "@dataclass\n", + "class Request:\n", + " ordernr: str\n", + " cust_name: str\n", + " delivdate: date\n", + " artnr: str\n", + " artname: str\n", + " bundle: str\n", + " stock: int\n", + " ordered: int\n", + " ord_rem: int\n", + " available: int\n", + " avail_wo_36:int\n", + " upcoming: int\n", + " upc_date: str\n", + " upc_area: str\n", + " stock00: int\n", + " stock01: int\n", + " stock33: int\n", + " stock36: int\n", + "\n", + " def from_tuple(t):\n", + " d = str(t[2])\n", + " szd = f\"20{d[-2:]}-{d[-4:-2]}-{int(d[:-4]):02d}\"\n", + " return Request(\n", + " ordernr=str(t[0]),\n", + " cust_name=str(t[1]).strip(),\n", + " delivdate=date.fromisoformat(szd),\n", + " artnr=str(t[3]),\n", + " artname=str(t[4]),\n", + " bundle=str(t[5]),\n", + " stock=int(t[6]),\n", + " ordered=int(t[7]),\n", + " ord_rem=int(t[23]),\n", + " available=int(t[9]),\n", + " avail_wo_36=int(t[28]),\n", + " upcoming=int(t[10]),\n", + " upc_date=date.fromisoformat(f\"20{str(t[11])[-2:]}-{str(t[11])[-4:-2]}-{int(str(t[11])[:-4]):02d}\") if int(t[10]) > 0 else None,\n", + " upc_area=str(t[12]),\n", + " stock00=int(t[24]),\n", + " stock01=int(t[25]),\n", + " stock33=int(t[26]),\n", + " stock36=int(t[27]),\n", + " )\n", + "\n", + "\n", + "RED = Color(rgb='E6B8B7')\n", + "\n", + "FROM = datetime.now().date()\n", + "TO = FROM + timedelta(days=14)\n", + "\n", + "if FROM.month == TO.month and FROM.year == TO.year:\n", + " aufbes = list(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(FROM.day, TO.day, FROM.month, FROM.year)))\n", + "else:\n", + " temp_to = FROM + timedelta(days = 31 if FROM.day >= 15 else 20)\n", + " temp_to = temp_to.replace(day = 1)\n", + " print(f\"Temp to = {temp_to}\")\n", + " temp_to = temp_to - timedelta(days=1)\n", + " print(f\"Temp to = {temp_to}\")\n", + " aufbes = list(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(FROM.day, temp_to.day, FROM.month, FROM.year)))\n", + " temp_from = temp_to + timedelta(days=1)\n", + " print(f\"Temp from = {temp_from}\")\n", + " while temp_from.month < TO.month:\n", + " temp_to = FROM + timedelta(days = 31 if FROM.day >= 15 else 20)\n", + " temp_to = temp_to.replace(day=1)\n", + " temp_to = temp_to - timedelta(days=1)\n", + " aufbes.extend(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(temp_from.day, temp_to.day, temp_from.month, temp_from.year)))\n", + " temp_from = temp_to + timedelta(days=1)\n", + " \n", + " # last month. temp_from is the current TO month\n", + " aufbes.extend(map(lambda t: Request.from_tuple(t), ibmconnect.getNegAvail(temp_from.day, TO.day, temp_from.month, temp_from.year)))\n", + " \n", + "\n", + "\n", + "aufbes.sort(key = lambda a: a.delivdate)\n", + "\n", + "vorlage = load_workbook(\"Umfuhrplanung_Vorlage.xlsx\")\n", + "\n", + "for prodNr in ART_WU:\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", + " sheet = vorlage.copy_worksheet(vorlage[\"Vorlage\"])\n", + " sheet.title = prodNr\n", + " sheet['A1'] = f\"{prod.name.strip()} (#{prodNr})\"\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", + " \n", + "\n", + " we = first.upcoming\n", + " we_dat = first.upc_date\n", + " 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['B3'] = we\n", + " sheet['D3'] = we_dat\n", + "\n", + " verbleibend = bestand_00\n", + " bedarf_am = \"\"\n", + " bedarf_durch = \"\"\n", + " bedarf_auftrag = \"\"\n", + " umfuhrmenge = 0\n", + " umfuhr_an = \"\"\n", + " auftrag = 0\n", + " 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", + " \n", + " sheet.append([\"\", \"Produktion\", we_dat, t.delivdate, 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", + " 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", + " 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", + " 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", + " \n", + " if we > 0:\n", + " if we_area == \"00\":\n", + " verbleibend += we\n", + " \n", + " sheet.append([\"\", \"Produktion\", we_dat, t.delivdate, 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", + "\n", "vorlage.save(f\"Umfuhrplanung_{FROM}.xlsx\")" - ], - "outputs": [], - "metadata": {} + ] }, { "cell_type": "code", "execution_count": null, - "source": [], + "metadata": {}, "outputs": [], - "metadata": {} + "source": [] } ], "metadata": { - "orig_nbformat": 4, + "interpreter": { + "hash": "032eb40c1682b1e6109824d577ff4427b0bbc2f8ebe1487b7b1be524c4843266" + }, + "kernelspec": { + "display_name": "Python 3.9.7 64-bit", + "name": "python3" + }, "language_info": { - "name": "python", - "version": "3.9.7", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.9.7" }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3.9.7 64-bit" - }, - "interpreter": { - "hash": "032eb40c1682b1e6109824d577ff4427b0bbc2f8ebe1487b7b1be524c4843266" - } + "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +}