From 10fe147b5909b27ab0ce20be6597d179c67f84a2 Mon Sep 17 00:00:00 2001 From: Christian Anetzberger Date: Sat, 14 Nov 2026 16:21:20 +0100 Subject: [PATCH] Exoorted fixtures --- README.md | 2 +- manufacturing_utilities/fixtures/custom_field.json | 6 ++++++ manufacturing_utilities/fixtures/custom_html_block.json | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7b3a973..f709d31 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Pre-commit is configured to use the following tools for checking and formatting - eslint - prettier - pyupgrade + ### CI This app can use GitHub Actions for CI. The following workflows are configured: @@ -34,7 +35,6 @@ This app can use GitHub Actions for CI. The following workflows are configured: - CI: Installs this app and runs unit tests on every push to `develop` branch. - Linters: Runs [Frappe Semgrep Rules](https://github.com/frappe/semgrep-rules) and [pip-audit](https://pypi.org/project/pip-audit/) on every pull request. - ### License gpl-3.0 diff --git a/manufacturing_utilities/fixtures/custom_field.json b/manufacturing_utilities/fixtures/custom_field.json index eaca020..4c66592 100644 --- a/manufacturing_utilities/fixtures/custom_field.json +++ b/manufacturing_utilities/fixtures/custom_field.json @@ -26,6 +26,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, + "in_import_template": 0, "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, @@ -51,6 +52,7 @@ "print_width": null, "read_only": 0, "read_only_depends_on": null, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -88,6 +90,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, + "in_import_template": 0, "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, @@ -113,6 +116,7 @@ "print_width": null, "read_only": 0, "read_only_depends_on": null, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -150,6 +154,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, + "in_import_template": 0, "in_list_view": 0, "in_preview": 0, "in_standard_filter": 0, @@ -175,6 +180,7 @@ "print_width": null, "read_only": 0, "read_only_depends_on": null, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, diff --git a/manufacturing_utilities/fixtures/custom_html_block.json b/manufacturing_utilities/fixtures/custom_html_block.json index 6b7d074..257d16a 100644 --- a/manufacturing_utilities/fixtures/custom_html_block.json +++ b/manufacturing_utilities/fixtures/custom_html_block.json @@ -3,11 +3,11 @@ "docstatus": 0, "doctype": "Custom HTML Block", "html": "
\n
\n Loading...\n
\n
", - "modified": "2026-10-24 15:30:08.275864", + "modified": "2026-11-14 15:25:05.113077", "name": "Manufacturing Overview", "private": 0, "roles": [], - "script": "const OVERVIEW_METHOD =\n \"manufacturing_utilities.manufacturing_overview.api.get_manufacturing_overview\";\n\nconst REALTIME_EVENT = \"manufacturing_overview_updated\";\nconst REFRESH_INTERVAL = 60 * 1000;\n\nconst container = root_element.querySelector(\n \".manufacturing-overview-list\"\n);\n\nlet isLoading = false;\n\n\n/*\n * --------------------------------------------------------------------------\n * Helpers\n * --------------------------------------------------------------------------\n */\n\nfunction formatQty(value) {\n const number = Number(value || 0);\n\n return Number.isInteger(number)\n ? number.toString()\n : number.toLocaleString(undefined, {\n maximumFractionDigits: 3,\n });\n}\n\n\nfunction formatDate(value) {\n if (!value) {\n return \"\";\n }\n\n return frappe.datetime.str_to_user(value);\n}\n\n\nfunction getDeliveryDateClass(value) {\n if (!value) {\n return \"\";\n }\n\n const deliveryDate =\n frappe.datetime.str_to_obj(value);\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n deliveryDate.setHours(0, 0, 0, 0);\n today.setHours(0, 0, 0, 0);\n\n if (deliveryDate < today) {\n return \"mo-date-overdue\";\n }\n\n if (\n deliveryDate.getTime() ===\n today.getTime()\n ) {\n return \"mo-date-today\";\n }\n\n return \"\";\n}\n\n\nfunction getDateGroup(value) {\n if (!value) {\n return \"upcoming\";\n }\n\n const deliveryDate =\n frappe.datetime.str_to_obj(value);\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n deliveryDate.setHours(0, 0, 0, 0);\n today.setHours(0, 0, 0, 0);\n\n if (deliveryDate < today) {\n return \"behind_schedule\";\n }\n\n if (\n deliveryDate.getTime() ===\n today.getTime()\n ) {\n return \"today\";\n }\n\n return \"upcoming\";\n}\n\n\nfunction escape(value) {\n return frappe.utils.escape_html(\n value == null ? \"\" : String(value)\n );\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Manufacturing card\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingCard(item) {\n const status =\n item.status || \"unknown\";\n\n const statusLabels = {\n partially_delivered:\n \"Partially Delivered\",\n in_warehouse:\n \"In Warehouse\",\n to_produce:\n \"To Produce\",\n no_work_order:\n \"No Work Order\",\n };\n\n let statusLabel =\n statusLabels[status] || status;\n\n if (\n status ===\n \"partially_delivered\"\n ) {\n statusLabel +=\n ` (${formatQty(item.delivered_qty)}/${formatQty(item.qty)})`;\n }\n\n const salesOrder =\n escape(item.sales_order);\n\n const workOrder =\n escape(item.work_order);\n\n const itemCode =\n escape(item.item_code);\n\n const itemName =\n escape(item.item_name);\n\n const customer =\n escape(item.customer);\n\n const deliveryDate =\n escape(\n formatDate(\n item.delivery_date\n )\n );\n\n const deliveryDateClass =\n getDeliveryDateClass(\n item.delivery_date\n );\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(item.remaining_qty)} ×\n \n\n \n ${itemName}\n \n\n
\n\n \n ${deliveryDate}\n
\n\n
\n\n
\n\n \n ${customer}\n \n\n \n •\n \n\n \n ${itemCode}\n \n\n
\n\n
\n\n \n ${salesOrder}\n \n\n \n ${escape(statusLabel)}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Subcontracting card\n * --------------------------------------------------------------------------\n */\n\nfunction renderSubcontractingCard(\n subcontracting\n) {\n const purchaseOrder =\n escape(\n subcontracting.purchase_order\n );\n\n const supplier =\n escape(\n subcontracting.supplier\n );\n\n const process =\n escape(\n subcontracting.process\n );\n\n const status =\n escape(\n subcontracting.status\n );\n\n const deliveryDate =\n escape(\n formatDate(\n subcontracting.delivery_date\n )\n );\n\n const deliveryDateClass =\n getDeliveryDateClass(\n subcontracting.delivery_date\n );\n\n const targetDoctype =\n subcontracting.subcontracting_order\n ? \"Subcontracting Order\"\n : \"Purchase Order\";\n\n const targetName =\n subcontracting.subcontracting_order\n || subcontracting.purchase_order\n || \"\";\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(subcontracting.qty)} ×\n \n\n \n ${process}\n \n\n
\n\n \n ${deliveryDate}\n
\n\n
\n\n
\n\n \n ${supplier}\n \n\n
\n\n
\n\n \n ${purchaseOrder}\n \n\n \n ${status}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * One complete manufacturing row\n * --------------------------------------------------------------------------\n */\n\nfunction renderOverviewEntry(item) {\n const subcontracting =\n item.subcontracting || [];\n\n const subcontractingCards =\n subcontracting.length\n ? `\n
\n ${subcontracting\n .map(\n renderSubcontractingCard\n )\n .join(\"\")}\n
\n `\n : \"\";\n\n return `\n
\n\n
\n ${renderManufacturingCard(item)}\n
\n\n
\n ${subcontractingCards}\n
\n\n
\n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Complete overview\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingOverview(\n items\n) {\n if (!container) {\n console.error(\n \"Manufacturing Overview container not found.\"\n );\n\n return;\n }\n\n if (!items.length) {\n container.innerHTML = `\n
\n No manufacturing items found.\n
\n `;\n\n return;\n }\n\n const groups = {\n behind_schedule: [],\n today: [],\n upcoming: [],\n };\n\n items.forEach((item) => {\n const group =\n getDateGroup(\n item.delivery_date\n );\n\n groups[group].push(item);\n });\n\n const sectionOrder = [\n \"behind_schedule\",\n \"today\",\n \"upcoming\",\n ];\n\n const sectionLabels = {\n behind_schedule:\n \"Behind schedule\",\n today:\n \"Today\",\n upcoming:\n \"Upcoming\",\n };\n\n container.innerHTML =\n sectionOrder\n .filter(\n (key) =>\n groups[key].length\n )\n .map((key) => `\n
\n\n
\n ${sectionLabels[key]}\n
\n\n
\n ${groups[key]\n .map(\n renderOverviewEntry\n )\n .join(\"\")}\n
\n\n
\n `)\n .join(\"\");\n\n bindCardNavigation();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Navigation\n * --------------------------------------------------------------------------\n */\n\nfunction bindCardNavigation() {\n\n /*\n * Manufacturing card\n * → Work Order\n */\n container\n .querySelectorAll(\n \".mo-manufacturing-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\"a\")\n ) {\n return;\n }\n\n const workOrder =\n row.dataset.workOrder;\n\n if (!workOrder) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n \"Work Order\",\n workOrder\n );\n }\n );\n });\n\n\n /*\n * Subcontracting card\n */\n container\n .querySelectorAll(\n \".mo-subcontracting-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\"a\")\n ) {\n return;\n }\n\n const doctype =\n row.dataset.targetDoctype;\n\n const name =\n row.dataset.targetName;\n\n if (\n !doctype ||\n !name\n ) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n doctype,\n name\n );\n }\n );\n });\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Data loading\n * --------------------------------------------------------------------------\n */\n\nasync function loadManufacturingOverview() {\n if (isLoading) {\n return;\n }\n\n isLoading = true;\n\n try {\n\n const response =\n await frappe.call({\n method:\n OVERVIEW_METHOD,\n type:\n \"GET\",\n });\n\n renderManufacturingOverview(\n response.message?.items || []\n );\n\n } catch (error) {\n\n console.error(\n \"Failed to load Manufacturing Overview:\",\n error\n );\n\n if (container) {\n container.innerHTML = `\n
\n Failed to load Manufacturing Overview.\n
\n `;\n }\n\n } finally {\n isLoading = false;\n }\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup old block instance\n * --------------------------------------------------------------------------\n */\n\nif (\n root_element\n ._manufacturingOverviewCleanup\n) {\n root_element\n ._manufacturingOverviewCleanup();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Realtime refresh\n * --------------------------------------------------------------------------\n */\n\nconst realtimeHandler = () => {\n loadManufacturingOverview();\n};\n\nfrappe.realtime.on(\n REALTIME_EVENT,\n realtimeHandler\n);\n\n\n/*\n * --------------------------------------------------------------------------\n * Safety refresh\n * --------------------------------------------------------------------------\n */\n\nconst refreshTimer =\n setInterval(\n loadManufacturingOverview,\n REFRESH_INTERVAL\n );\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup\n * --------------------------------------------------------------------------\n */\n\nroot_element\n ._manufacturingOverviewCleanup =\n () => {\n\n clearInterval(\n refreshTimer\n );\n\n if (\n frappe.realtime.off\n ) {\n frappe.realtime.off(\n REALTIME_EVENT,\n realtimeHandler\n );\n }\n };\n\n\n/*\n * --------------------------------------------------------------------------\n * Initial load\n * --------------------------------------------------------------------------\n */\n\nloadManufacturingOverview();", - "style": ".manufacturing-overview {\n width: 100%;\n}\n\n.manufacturing-overview-list {\n display: flex;\n flex-direction: column;\n}\n\n\n/* -------------------------------------------------------------------------\n * Sections\n * ---------------------------------------------------------------------- */\n\n.mo-section {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.mo-section + .mo-section {\n margin-top: 28px;\n}\n\n.mo-section-header {\n padding:\n 0 2px 6px;\n\n font-size:\n var(--text-sm);\n\n font-weight: 600;\n\n color:\n var(--text-muted);\n\n border-bottom:\n 1px solid\n var(--border-color);\n}\n\n.mo-section-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Two-column overview layout\n * ---------------------------------------------------------------------- */\n\n.mo-overview-entry {\n display: grid;\n\n grid-template-columns:\n minmax(0, 1fr)\n minmax(0, 1fr);\n\n gap: 10px;\n\n align-items: start;\n}\n\n.mo-manufacturing-column,\n.mo-subcontracting-column {\n min-width: 0;\n}\n\n.mo-subcontracting-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Base card\n * ---------------------------------------------------------------------- */\n\n.mo-row {\n display: flex;\n gap: 12px;\n\n padding:\n 12px 14px;\n\n border:\n 1px solid\n var(--border-color);\n\n border-radius:\n 12px;\n\n background:\n var(--card-bg);\n\n box-shadow:\n none;\n\n transition:\n background 0.15s ease,\n border-color 0.15s ease,\n box-shadow 0.15s ease,\n transform 0.15s ease;\n}\n\n.mo-row-clickable {\n cursor: pointer;\n}\n\n.mo-row-clickable:hover {\n background:\n var(--control-bg);\n\n border-color:\n var(--gray-300);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.06),\n 0 3px 8px\n rgba(0, 0, 0, 0.05);\n}\n\n.mo-row-clickable:active {\n transform:\n translateY(1px);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.08);\n}\n\n\n/* -------------------------------------------------------------------------\n * Status bars\n * ---------------------------------------------------------------------- */\n\n.mo-status {\n width: 6px;\n min-width: 6px;\n\n border-radius:\n 999px;\n\n background:\n var(--gray-400);\n}\n\n.mo-status-in_warehouse {\n background:\n var(--green-500);\n}\n\n.mo-status-to_produce {\n background:\n var(--yellow-500);\n}\n\n.mo-status-no_work_order {\n background:\n var(--red-500);\n}\n\n.mo-status-partially_delivered {\n background:\n var(--blue-500);\n}\n\n.mo-status-subcontracting {\n background:\n var(--purple-500);\n}\n\n\n/* -------------------------------------------------------------------------\n * Card content\n * ---------------------------------------------------------------------- */\n\n.mo-main {\n flex: 1;\n min-width: 0;\n}\n\n.mo-title-row {\n display: flex;\n\n justify-content:\n space-between;\n\n align-items:\n flex-start;\n\n gap: 16px;\n}\n\n.mo-title {\n min-width: 0;\n\n font-size:\n var(--text-base);\n\n font-weight: 600;\n\n color:\n var(--text-color);\n}\n\n.mo-qty {\n margin-right:\n 4px;\n\n color:\n var(--text-muted);\n}\n\n.mo-item-link {\n font-weight: 600;\n}\n\n\n/* -------------------------------------------------------------------------\n * Delivery date\n * ---------------------------------------------------------------------- */\n\n.mo-date {\n white-space: nowrap;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-date-today {\n font-weight: 700;\n\n color:\n var(--text-color);\n}\n\n.mo-date-overdue {\n font-weight: 700;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Meta / footer\n * ---------------------------------------------------------------------- */\n\n.mo-meta,\n.mo-footer {\n display: flex;\n\n align-items: center;\n\n gap: 6px;\n\n margin-top: 4px;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-footer {\n justify-content:\n space-between;\n}\n\n.mo-separator {\n opacity: 0.5;\n}\n\n.mo-status-label {\n font-size:\n var(--text-xs);\n\n font-weight: 500;\n}\n\n\n/* -------------------------------------------------------------------------\n * Links\n * ---------------------------------------------------------------------- */\n\n.mo-link {\n color: inherit;\n\n text-decoration: none;\n}\n\n.mo-link:hover {\n color:\n var(--text-color);\n\n text-decoration:\n underline;\n}\n\n\n/* -------------------------------------------------------------------------\n * Subcontracting card\n * ---------------------------------------------------------------------- */\n\n.mo-subcontracting-card {\n position: relative;\n}\n\n.mo-subcontracting-card:hover {\n background:\n var(--control-bg);\n}\n\n\n/* -------------------------------------------------------------------------\n * Empty / error states\n * ---------------------------------------------------------------------- */\n\n.mo-empty {\n padding: 24px;\n\n text-align: center;\n}\n\n.mo-error {\n padding: 16px;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Responsive\n * ---------------------------------------------------------------------- */\n\n@media (max-width: 900px) {\n\n .mo-overview-entry {\n grid-template-columns:\n minmax(0, 1fr);\n }\n\n}" + "script": "const OVERVIEW_METHOD =\n \"manufacturing_utilities.manufacturing_overview.api.get_manufacturing_overview\";\n\nconst REALTIME_EVENT =\n \"manufacturing_overview_updated\";\n\nconst REFRESH_INTERVAL =\n 60 * 1000;\n\nconst container =\n root_element.querySelector(\n \".manufacturing-overview-list\"\n );\n\nlet isLoading = false;\n\n\n/*\n * --------------------------------------------------------------------------\n * Helpers\n * --------------------------------------------------------------------------\n */\n\nfunction formatQty(value) {\n const number =\n Number(value || 0);\n\n return Number.isInteger(number)\n ? number.toString()\n : number.toLocaleString(\n undefined,\n {\n maximumFractionDigits: 3,\n }\n );\n}\n\n\nfunction formatDate(value) {\n if (!value) {\n return \"\";\n }\n\n return frappe.datetime.str_to_user(\n value\n );\n}\n\n\nfunction formatDateOnly(value) {\n if (!value) {\n return \"\";\n }\n\n const datePart =\n String(value).split(/[ T]/)[0];\n\n return frappe.datetime.str_to_user(\n datePart\n );\n}\n\n\nfunction getDeliveryDateClass(value) {\n if (!value) {\n return \"\";\n }\n\n const date =\n frappe.datetime.str_to_obj(\n value\n );\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n date.setHours(\n 0,\n 0,\n 0,\n 0\n );\n\n today.setHours(\n 0,\n 0,\n 0,\n 0\n );\n\n if (date < today) {\n return \"mo-date-overdue\";\n }\n\n if (\n date.getTime()\n === today.getTime()\n ) {\n return \"mo-date-today\";\n }\n\n return \"\";\n}\n\n\nfunction getDateGroup(value) {\n if (!value) {\n return \"upcoming\";\n }\n\n const date =\n frappe.datetime.str_to_obj(\n value\n );\n\n const today =\n frappe.datetime.str_to_obj(\n frappe.datetime.get_today()\n );\n\n date.setHours(\n 0,\n 0,\n 0,\n 0\n );\n\n today.setHours(\n 0,\n 0,\n 0,\n 0\n );\n\n if (date < today) {\n return \"behind_schedule\";\n }\n\n if (\n date.getTime()\n === today.getTime()\n ) {\n return \"today\";\n }\n\n return \"upcoming\";\n}\n\n\nfunction escape(value) {\n return frappe.utils.escape_html(\n value == null\n ? \"\"\n : String(value)\n );\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Translation maps\n * --------------------------------------------------------------------------\n */\n\nconst manufacturingStatusLabels = {\n partially_delivered:\n __(\"Partially Delivered\"),\n\n in_warehouse:\n __(\"In Warehouse\"),\n\n to_produce:\n __(\"To Produce\"),\n\n no_work_order:\n __(\"No Work Order\"),\n};\n\n\nconst subcontractingStatusLabels = {\n \"Draft\":\n __(\"Draft\"),\n\n \"To Transfer\":\n __(\"To Transfer\"),\n\n \"Material Transferred\":\n __(\"Material Transferred\"),\n\n \"Partial Material Transferred\":\n __(\"Partial Material Transferred\"),\n\n \"Partially Received\":\n __(\"Partially Received\"),\n\n \"Completed\":\n __(\"Completed\"),\n\n \"No Purchase Order\":\n __(\"No Purchase Order\"),\n\n \"Planned\":\n __(\"Planned\"),\n};\n\n\n/*\n * --------------------------------------------------------------------------\n * Manufacturing card\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingCard(item) {\n const status =\n item.status || \"unknown\";\n\n let statusLabel =\n manufacturingStatusLabels[status]\n || status;\n\n if (\n status\n === \"partially_delivered\"\n ) {\n statusLabel +=\n ` (${formatQty(item.delivered_qty)}/${formatQty(item.qty)})`;\n }\n\n const salesOrder =\n escape(\n item.sales_order\n );\n\n const workOrder =\n escape(\n item.work_order\n );\n\n const itemCode =\n escape(\n item.item_code\n );\n\n const itemName =\n escape(\n item.item_name\n );\n\n const customer =\n escape(\n item.customer\n );\n\n const deliveryDate =\n escape(\n formatDate(\n item.delivery_date\n )\n );\n\n const deliveryDateClass =\n getDeliveryDateClass(\n item.delivery_date\n );\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(item.remaining_qty)} ×\n \n\n \n ${itemName}\n \n\n
\n\n \n ${deliveryDate}\n
\n\n
\n\n
\n\n \n ${customer}\n \n\n \n •\n \n\n \n ${itemCode}\n \n\n
\n\n
\n\n
\n\n \n ${salesOrder}\n \n\n ${\n item.work_order\n ? `\n \n •\n \n\n \n ${workOrder}\n \n `\n : \"\"\n }\n\n
\n\n \n ${escape(statusLabel)}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Subcontracting card\n * --------------------------------------------------------------------------\n */\n\nfunction renderSubcontractingCard(\n subcontracting,\n plannedEndDate,\n workOrder\n) {\n const source =\n subcontracting.source || \"\";\n\n const isPlanning =\n source === \"planning\";\n\n const purchaseOrder =\n escape(\n subcontracting.purchase_order\n );\n\n const supplier =\n escape(\n subcontracting.supplier\n );\n\n const process =\n escape(\n subcontracting.process\n || __(\"Subcontracting\")\n );\n\n const rawStatus =\n subcontracting.status || \"\";\n\n const translatedStatus =\n subcontractingStatusLabels[\n rawStatus\n ] || rawStatus;\n\n const status =\n escape(\n translatedStatus\n );\n\n const displayedDate =\n escape(\n formatDateOnly(\n plannedEndDate\n )\n );\n\n const dateClass =\n subcontracting.material_transferred\n ? \"\"\n : getDeliveryDateClass(\n plannedEndDate\n );\n\n let targetDoctype = \"\";\n let targetName = \"\";\n\n if (isPlanning) {\n if (workOrder) {\n targetDoctype =\n \"Work Order\";\n\n targetName =\n workOrder;\n }\n\n } else if (\n subcontracting.subcontracting_order\n ) {\n targetDoctype =\n \"Subcontracting Order\";\n\n targetName =\n subcontracting.subcontracting_order;\n\n } else if (\n subcontracting.purchase_order\n ) {\n targetDoctype =\n \"Purchase Order\";\n\n targetName =\n subcontracting.purchase_order;\n }\n\n let footerDocument = \"\";\n\n if (purchaseOrder) {\n footerDocument = `\n \n ${purchaseOrder}\n \n `;\n\n } else {\n footerDocument = `\n \n ${__(\"No Purchase Order\")}\n \n `;\n }\n\n let meta = \"\";\n\n if (supplier) {\n meta = `\n
\n \n ${supplier}\n \n
\n `;\n\n } else {\n meta = `\n
\n \n ${__(\"Planned subcontracting\")}\n \n
\n `;\n }\n\n return `\n \n \n\n
\n\n
\n\n
\n\n \n ${formatQty(subcontracting.qty)} ×\n \n\n \n ${process}\n \n\n
\n\n \n ${displayedDate}\n
\n\n
\n\n ${meta}\n\n
\n\n ${footerDocument}\n\n \n ${status}\n \n\n
\n\n \n \n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * One overview entry\n * --------------------------------------------------------------------------\n */\n\nfunction renderOverviewEntry(item) {\n const subcontracting =\n item.subcontracting || [];\n\n const plannedEndDate =\n item.work_order_planned_end_date;\n\n const subcontractingCards =\n subcontracting.length\n ? `\n
\n ${\n subcontracting\n .map(\n (entry) =>\n renderSubcontractingCard(\n entry,\n plannedEndDate,\n item.work_order\n )\n )\n .join(\"\")\n }\n
\n `\n : \"\";\n\n return `\n
\n\n
\n ${renderManufacturingCard(item)}\n
\n\n
\n ${subcontractingCards}\n
\n\n
\n `;\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Complete overview\n * --------------------------------------------------------------------------\n */\n\nfunction renderManufacturingOverview(\n items\n) {\n if (!container) {\n console.error(\n \"Manufacturing Overview container not found.\"\n );\n\n return;\n }\n\n if (!items.length) {\n container.innerHTML = `\n
\n ${__(\"No manufacturing items found.\")}\n
\n `;\n\n return;\n }\n\n const groups = {\n behind_schedule: [],\n today: [],\n upcoming: [],\n };\n\n items.forEach((item) => {\n const group =\n getDateGroup(\n item.effective_sort_date\n || item.delivery_date\n );\n\n groups[group].push(\n item\n );\n });\n\n const sectionOrder = [\n \"behind_schedule\",\n \"today\",\n \"upcoming\",\n ];\n\n const sectionLabels = {\n behind_schedule:\n __(\"Behind schedule\"),\n\n today:\n __(\"Today\"),\n\n upcoming:\n __(\"Upcoming\"),\n };\n\n const columnHeadings = `\n
\n\n
\n ${__(\"Manufacturing\")}\n
\n\n
\n ${__(\"Subcontracting\")}\n
\n\n
\n `;\n\n const sections =\n sectionOrder\n .filter(\n (key) =>\n groups[key].length\n )\n .map(\n (key) => `\n
\n\n
\n ${sectionLabels[key]}\n
\n\n
\n ${\n groups[key]\n .map(\n renderOverviewEntry\n )\n .join(\"\")\n }\n
\n\n
\n `\n )\n .join(\"\");\n\n container.innerHTML =\n columnHeadings\n + sections;\n\n bindCardNavigation();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Navigation\n * --------------------------------------------------------------------------\n */\n\nfunction bindCardNavigation() {\n container\n .querySelectorAll(\n \".mo-manufacturing-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\n \"a\"\n )\n ) {\n return;\n }\n\n const workOrder =\n row.dataset.workOrder;\n\n if (!workOrder) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n \"Work Order\",\n workOrder\n );\n }\n );\n });\n\n\n container\n .querySelectorAll(\n \".mo-subcontracting-card.mo-row-clickable\"\n )\n .forEach((row) => {\n\n row.addEventListener(\n \"click\",\n (event) => {\n\n if (\n event.target.closest(\n \"a\"\n )\n ) {\n return;\n }\n\n const doctype =\n row.dataset\n .targetDoctype;\n\n const name =\n row.dataset\n .targetName;\n\n if (\n !doctype\n || !name\n ) {\n return;\n }\n\n frappe.set_route(\n \"Form\",\n doctype,\n name\n );\n }\n );\n });\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Loading\n * --------------------------------------------------------------------------\n */\n\nasync function loadManufacturingOverview() {\n if (isLoading) {\n return;\n }\n\n isLoading = true;\n\n try {\n const response =\n await frappe.call({\n method:\n OVERVIEW_METHOD,\n\n type:\n \"GET\",\n });\n\n renderManufacturingOverview(\n response.message?.items\n || []\n );\n\n } catch (error) {\n\n console.error(\n \"Failed to load Manufacturing Overview:\",\n error\n );\n\n if (container) {\n container.innerHTML = `\n
\n ${__(\"Failed to load Manufacturing Overview.\")}\n
\n `;\n }\n\n } finally {\n isLoading = false;\n }\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup previous instance\n * --------------------------------------------------------------------------\n */\n\nif (\n root_element\n ._manufacturingOverviewCleanup\n) {\n root_element\n ._manufacturingOverviewCleanup();\n}\n\n\n/*\n * --------------------------------------------------------------------------\n * Realtime\n * --------------------------------------------------------------------------\n */\n\nconst realtimeHandler = () => {\n loadManufacturingOverview();\n};\n\nfrappe.realtime.on(\n REALTIME_EVENT,\n realtimeHandler\n);\n\n\n/*\n * --------------------------------------------------------------------------\n * Safety refresh\n * --------------------------------------------------------------------------\n */\n\nconst refreshTimer =\n setInterval(\n loadManufacturingOverview,\n REFRESH_INTERVAL\n );\n\n\n/*\n * --------------------------------------------------------------------------\n * Cleanup\n * --------------------------------------------------------------------------\n */\n\nroot_element\n ._manufacturingOverviewCleanup =\n () => {\n\n clearInterval(\n refreshTimer\n );\n\n if (\n frappe.realtime.off\n ) {\n frappe.realtime.off(\n REALTIME_EVENT,\n realtimeHandler\n );\n }\n };\n\n\n/*\n * --------------------------------------------------------------------------\n * Initial load\n * --------------------------------------------------------------------------\n */\n\nloadManufacturingOverview();", + "style": ".manufacturing-overview {\n width: 100%;\n}\n\n.manufacturing-overview-list {\n display: flex;\n flex-direction: column;\n}\n\n\n/* -------------------------------------------------------------------------\n * Column headings\n * ---------------------------------------------------------------------- */\n\n.mo-column-headings {\n display: grid;\n\n grid-template-columns:\n minmax(0, 1fr)\n minmax(0, 1fr);\n\n gap: 10px;\n\n margin-bottom: 18px;\n}\n\n.mo-column-heading {\n padding:\n 0 2px 7px;\n\n font-size:\n var(--text-base);\n\n font-weight: 600;\n\n color:\n var(--text-color);\n\n border-bottom:\n 1px solid\n var(--border-color);\n}\n\n\n/* -------------------------------------------------------------------------\n * Sections\n * ---------------------------------------------------------------------- */\n\n.mo-section {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.mo-section + .mo-section {\n margin-top: 28px;\n}\n\n.mo-section-header {\n padding:\n 0 2px 6px;\n\n font-size:\n var(--text-sm);\n\n font-weight: 600;\n\n color:\n var(--text-muted);\n\n border-bottom:\n 1px solid\n var(--border-color);\n}\n\n.mo-section-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Two-column overview layout\n * ---------------------------------------------------------------------- */\n\n.mo-overview-entry {\n display: grid;\n\n grid-template-columns:\n minmax(0, 1fr)\n minmax(0, 1fr);\n\n gap: 10px;\n\n align-items: start;\n}\n\n.mo-manufacturing-column,\n.mo-subcontracting-column {\n min-width: 0;\n}\n\n.mo-subcontracting-list {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n\n/* -------------------------------------------------------------------------\n * Base card\n * ---------------------------------------------------------------------- */\n\n.mo-row {\n display: flex;\n gap: 12px;\n\n padding:\n 12px 14px;\n\n border:\n 1px solid\n var(--border-color);\n\n border-radius:\n 12px;\n\n background:\n var(--card-bg);\n\n box-shadow:\n none;\n\n transition:\n background 0.15s ease,\n border-color 0.15s ease,\n box-shadow 0.15s ease,\n transform 0.15s ease;\n}\n\n.mo-row-clickable {\n cursor: pointer;\n}\n\n.mo-row-clickable:hover {\n background:\n var(--control-bg);\n\n border-color:\n var(--gray-300);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.06),\n 0 3px 8px\n rgba(0, 0, 0, 0.05);\n}\n\n.mo-row-clickable:active {\n transform:\n translateY(1px);\n\n box-shadow:\n 0 1px 2px\n rgba(0, 0, 0, 0.08);\n}\n\n\n/* -------------------------------------------------------------------------\n * Status bars\n * ---------------------------------------------------------------------- */\n\n.mo-status {\n width: 6px;\n min-width: 6px;\n\n border-radius:\n 999px;\n\n background:\n var(--gray-400);\n}\n\n.mo-status-in_warehouse {\n background:\n var(--green-500);\n}\n\n.mo-status-to_produce {\n background:\n var(--yellow-500);\n}\n\n.mo-status-no_work_order {\n background:\n var(--red-500);\n}\n\n.mo-status-partially_delivered {\n background:\n var(--blue-500);\n}\n\n.mo-status-subcontracting {\n background:\n var(--purple-500);\n}\n\n\n/* -------------------------------------------------------------------------\n * Card content\n * ---------------------------------------------------------------------- */\n\n.mo-main {\n flex: 1;\n min-width: 0;\n}\n\n.mo-title-row {\n display: flex;\n\n justify-content:\n space-between;\n\n align-items:\n flex-start;\n\n gap: 16px;\n}\n\n.mo-title {\n min-width: 0;\n\n font-size:\n var(--text-base);\n\n font-weight: 600;\n\n color:\n var(--text-color);\n}\n\n.mo-qty {\n margin-right:\n 4px;\n\n color:\n var(--text-muted);\n}\n\n.mo-item-link {\n font-weight: 600;\n}\n\n\n/* -------------------------------------------------------------------------\n * Dates\n * ---------------------------------------------------------------------- */\n\n.mo-date {\n white-space: nowrap;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-date-today {\n font-weight: 700;\n\n color:\n var(--text-color);\n}\n\n.mo-date-overdue {\n font-weight: 700;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Meta / footer\n * ---------------------------------------------------------------------- */\n\n.mo-meta,\n.mo-footer {\n display: flex;\n\n align-items: center;\n\n gap: 6px;\n\n margin-top: 4px;\n\n font-size:\n var(--text-sm);\n\n color:\n var(--text-muted);\n}\n\n.mo-footer {\n justify-content:\n space-between;\n}\n\n.mo-document-links {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.mo-separator {\n opacity: 0.5;\n}\n\n.mo-status-label {\n font-size:\n var(--text-xs);\n\n font-weight: 500;\n}\n\n\n/* -------------------------------------------------------------------------\n * Links\n * ---------------------------------------------------------------------- */\n\n.mo-link {\n color: inherit;\n\n text-decoration: none;\n}\n\n.mo-link:hover {\n color:\n var(--text-color);\n\n text-decoration:\n underline;\n}\n\n\n/* -------------------------------------------------------------------------\n * Subcontracting\n * ---------------------------------------------------------------------- */\n\n.mo-subcontracting-card {\n position: relative;\n}\n\n.mo-subcontracting-card:hover {\n background:\n var(--control-bg);\n}\n\n\n/* -------------------------------------------------------------------------\n * Empty / error\n * ---------------------------------------------------------------------- */\n\n.mo-empty {\n padding: 24px;\n\n text-align: center;\n}\n\n.mo-error {\n padding: 16px;\n\n color:\n var(--red-600);\n}\n\n\n/* -------------------------------------------------------------------------\n * Responsive\n * ---------------------------------------------------------------------- */\n\n@media (max-width: 900px) {\n\n .mo-column-headings,\n .mo-overview-entry {\n grid-template-columns:\n minmax(0, 1fr);\n }\n\n .mo-column-headings {\n display: none;\n }\n\n}" } ] \ No newline at end of file