@tailor-platform/erp-kit 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/cli.mjs +139 -35
- package/package.json +1 -1
- package/skills/erp-kit-app-5-impl-backend/SKILL.md +10 -5
- package/skills/erp-kit-app-7-impl-review/SKILL.md +1 -1
- package/skills/erp-kit-module-6-impl-review/SKILL.md +39 -17
- package/src/commands/generate-doc.ts +1 -1
- package/src/commands/init-module.test.ts +17 -3
- package/src/commands/init-module.ts +0 -12
- package/src/commands/lib/discovery.test.ts +13 -3
- package/src/commands/lib/discovery.ts +10 -2
- package/src/commands/lib/paths.ts +4 -2
- package/src/commands/lib/sync-check-tests.test.ts +84 -6
- package/src/commands/lib/sync-check-tests.ts +63 -3
- package/src/commands/sync-check.ts +7 -3
- package/src/generator/generate-app-code.ts +51 -16
- package/src/generator/generate-code-boilerplate.test.ts +9 -1
- package/src/generator/generate-stubs.ts +4 -0
- package/src/generator/scaffold.ts +6 -2
- package/src/generator/stub-templates.test.ts +11 -0
- package/src/generator/stub-templates.ts +22 -1
- package/src/mdschema.ts +39 -3
- package/src/modules/inventory/docs/features/inventory-adjustment.md +2 -1
- package/src/modules/inventory/docs/features/scrap-management.md +39 -1
- package/src/modules/manufacturing/README.md +63 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.test.ts +166 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.ts +173 -0
- package/src/modules/manufacturing/command/activateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateRouting.test.ts +152 -0
- package/src/modules/manufacturing/command/activateRouting.ts +92 -0
- package/src/modules/manufacturing/command/activateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateWorkCenter.test.ts +135 -0
- package/src/modules/manufacturing/command/activateWorkCenter.ts +91 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.test.ts +151 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.ts +114 -0
- package/src/modules/manufacturing/command/closeProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/closeProductionOrder.test.ts +126 -0
- package/src/modules/manufacturing/command/closeProductionOrder.ts +87 -0
- package/src/modules/manufacturing/command/completeProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/completeProductionOrder.test.ts +132 -0
- package/src/modules/manufacturing/command/completeProductionOrder.ts +97 -0
- package/src/modules/manufacturing/command/completeWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/completeWorkOrder.test.ts +369 -0
- package/src/modules/manufacturing/command/completeWorkOrder.ts +212 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.test.ts +210 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.ts +176 -0
- package/src/modules/manufacturing/command/createProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/createProductionOrder.test.ts +160 -0
- package/src/modules/manufacturing/command/createProductionOrder.ts +129 -0
- package/src/modules/manufacturing/command/createRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/createRouting.test.ts +168 -0
- package/src/modules/manufacturing/command/createRouting.ts +128 -0
- package/src/modules/manufacturing/command/createWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/createWorkCenter.test.ts +148 -0
- package/src/modules/manufacturing/command/createWorkCenter.ts +131 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.test.ts +103 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.ts +78 -0
- package/src/modules/manufacturing/command/deactivateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateRouting.test.ts +112 -0
- package/src/modules/manufacturing/command/deactivateRouting.ts +76 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.test.ts +113 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.ts +85 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.test.ts +118 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.ts +82 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.generated.ts +6 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.test.ts +183 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.ts +139 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.generated.ts +6 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.test.ts +120 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.ts +110 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.test.ts +220 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.ts +450 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.test.ts +196 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.ts +98 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.generated.ts +6 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.test.ts +204 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.ts +129 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.test.ts +185 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.ts +95 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.test.ts +122 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.ts +94 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.generated.ts +6 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.test.ts +231 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.ts +137 -0
- package/src/modules/manufacturing/command/startWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/startWorkOrder.test.ts +118 -0
- package/src/modules/manufacturing/command/startWorkOrder.ts +126 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.test.ts +153 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.ts +106 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.test.ts +140 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.ts +131 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.test.ts +149 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.ts +174 -0
- package/src/modules/manufacturing/command/updateProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateProductionOrder.test.ts +112 -0
- package/src/modules/manufacturing/command/updateProductionOrder.ts +145 -0
- package/src/modules/manufacturing/command/updateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateRouting.test.ts +211 -0
- package/src/modules/manufacturing/command/updateRouting.ts +124 -0
- package/src/modules/manufacturing/command/updateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateWorkCenter.test.ts +152 -0
- package/src/modules/manufacturing/command/updateWorkCenter.ts +137 -0
- package/src/modules/manufacturing/db/.gitkeep +0 -0
- package/src/modules/manufacturing/db/billOfMaterial.ts +70 -0
- package/src/modules/manufacturing/db/billOfMaterialLine.ts +49 -0
- package/src/modules/manufacturing/db/costVarianceLine.ts +53 -0
- package/src/modules/manufacturing/db/manufacturingCostLine.ts +35 -0
- package/src/modules/manufacturing/db/manufacturingCostSettlementRecord.ts +39 -0
- package/src/modules/manufacturing/db/manufacturingCostSummary.ts +59 -0
- package/src/modules/manufacturing/db/productionOrder.ts +83 -0
- package/src/modules/manufacturing/db/productionOrderBomSnapshot.ts +44 -0
- package/src/modules/manufacturing/db/productionOrderCostBaseline.ts +44 -0
- package/src/modules/manufacturing/db/productionOrderMaterialRequirement.ts +57 -0
- package/src/modules/manufacturing/db/productionOrderRoutingSnapshot.ts +43 -0
- package/src/modules/manufacturing/db/routing.ts +63 -0
- package/src/modules/manufacturing/db/routingOperation.ts +57 -0
- package/src/modules/manufacturing/db/workCenter.ts +87 -0
- package/src/modules/manufacturing/db/workOrder.ts +65 -0
- package/src/modules/manufacturing/db/workOrderExecutionEvent.ts +54 -0
- package/src/modules/manufacturing/docs/commands/ActivateBillOfMaterial.md +50 -0
- package/src/modules/manufacturing/docs/commands/ActivateRouting.md +48 -0
- package/src/modules/manufacturing/docs/commands/ActivateWorkCenter.md +49 -0
- package/src/modules/manufacturing/docs/commands/CancelProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/CloseProductionOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/CompleteProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/CompleteWorkOrder.md +66 -0
- package/src/modules/manufacturing/docs/commands/CreateBillOfMaterial.md +54 -0
- package/src/modules/manufacturing/docs/commands/CreateProductionOrder.md +49 -0
- package/src/modules/manufacturing/docs/commands/CreateRouting.md +50 -0
- package/src/modules/manufacturing/docs/commands/CreateWorkCenter.md +51 -0
- package/src/modules/manufacturing/docs/commands/DeactivateBillOfMaterial.md +45 -0
- package/src/modules/manufacturing/docs/commands/DeactivateRouting.md +45 -0
- package/src/modules/manufacturing/docs/commands/DeactivateWorkCenter.md +45 -0
- package/src/modules/manufacturing/docs/commands/PauseWorkOrder.md +44 -0
- package/src/modules/manufacturing/docs/commands/RecordInventoryIssueOutcome.md +59 -0
- package/src/modules/manufacturing/docs/commands/RecordManufacturingCostSettlementAcknowledgment.md +49 -0
- package/src/modules/manufacturing/docs/commands/ReleaseProductionOrder.md +57 -0
- package/src/modules/manufacturing/docs/commands/ReopenProductionOrder.md +54 -0
- package/src/modules/manufacturing/docs/commands/ReportWorkOrderProgress.md +53 -0
- package/src/modules/manufacturing/docs/commands/RescheduleProductionOrder.md +45 -0
- package/src/modules/manufacturing/docs/commands/ResumeWorkOrder.md +44 -0
- package/src/modules/manufacturing/docs/commands/ReviewManufacturingCostSummary.md +52 -0
- package/src/modules/manufacturing/docs/commands/StartWorkOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/TechnicallyCompleteProductionOrder.md +51 -0
- package/src/modules/manufacturing/docs/commands/UnreleaseProductionOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/UpdateBillOfMaterial.md +48 -0
- package/src/modules/manufacturing/docs/commands/UpdateProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/UpdateRouting.md +52 -0
- package/src/modules/manufacturing/docs/commands/UpdateWorkCenter.md +48 -0
- package/src/modules/manufacturing/docs/features/bill-of-material-management.md +83 -0
- package/src/modules/manufacturing/docs/features/manufacturing-cost-and-variance.md +191 -0
- package/src/modules/manufacturing/docs/features/production-order-lifecycle.md +103 -0
- package/src/modules/manufacturing/docs/features/routing-and-work-center-definition.md +63 -0
- package/src/modules/manufacturing/docs/features/work-order-execution.md +115 -0
- package/src/modules/manufacturing/docs/models/BillOfMaterial.md +60 -0
- package/src/modules/manufacturing/docs/models/ManufacturingCostSummary.md +66 -0
- package/src/modules/manufacturing/docs/models/ProductionOrder.md +76 -0
- package/src/modules/manufacturing/docs/models/Routing.md +58 -0
- package/src/modules/manufacturing/docs/models/WorkCenter.md +56 -0
- package/src/modules/manufacturing/docs/models/WorkOrder.md +63 -0
- package/src/modules/manufacturing/docs/queries/DetectBillOfMaterialCircularReference.md +39 -0
- package/src/modules/manufacturing/docs/queries/ExplodeBillOfMaterial.md +56 -0
- package/src/modules/manufacturing/docs/queries/GetBillOfMaterial.md +37 -0
- package/src/modules/manufacturing/docs/queries/GetManufacturingCostSummary.md +39 -0
- package/src/modules/manufacturing/docs/queries/GetProductionOrder.md +37 -0
- package/src/modules/manufacturing/docs/queries/GetRouting.md +39 -0
- package/src/modules/manufacturing/docs/queries/GetWorkCenter.md +35 -0
- package/src/modules/manufacturing/docs/queries/GetWorkOrder.md +38 -0
- package/src/modules/manufacturing/docs/queries/ListBillOfMaterialsByItem.md +42 -0
- package/src/modules/manufacturing/docs/queries/ListManufacturingCostSummariesByStatus.md +41 -0
- package/src/modules/manufacturing/docs/queries/ListProductionOrdersByStatus.md +41 -0
- package/src/modules/manufacturing/docs/queries/ListRoutingsByItem.md +42 -0
- package/src/modules/manufacturing/docs/queries/ListWorkCentersBySite.md +38 -0
- package/src/modules/manufacturing/docs/queries/ListWorkOrdersByProductionOrder.md +39 -0
- package/src/modules/manufacturing/docs/queries/ListWorkOrdersByWorkCenter.md +43 -0
- package/src/modules/manufacturing/executor/.gitkeep +0 -0
- package/src/modules/manufacturing/generated/enums.ts +113 -0
- package/src/modules/manufacturing/generated/kysely-tailordb.ts +247 -0
- package/src/modules/manufacturing/index.ts +2 -0
- package/src/modules/manufacturing/lib/_db_deps.ts +22 -0
- package/src/modules/manufacturing/lib/errors.generated.ts +592 -0
- package/src/modules/manufacturing/lib/permissions.generated.ts +35 -0
- package/src/modules/manufacturing/lib/types.ts +111 -0
- package/src/modules/manufacturing/module.ts +226 -0
- package/src/modules/manufacturing/permissions.ts +3 -0
- package/src/modules/manufacturing/query/.gitkeep +0 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.generated.ts +5 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.test.ts +115 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.ts +79 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.generated.ts +5 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.test.ts +445 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.ts +306 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.generated.ts +5 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.test.ts +64 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.ts +27 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.generated.ts +5 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.test.ts +147 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.ts +46 -0
- package/src/modules/manufacturing/query/getProductionOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/getProductionOrder.test.ts +139 -0
- package/src/modules/manufacturing/query/getProductionOrder.ts +84 -0
- package/src/modules/manufacturing/query/getRouting.generated.ts +5 -0
- package/src/modules/manufacturing/query/getRouting.test.ts +71 -0
- package/src/modules/manufacturing/query/getRouting.ts +34 -0
- package/src/modules/manufacturing/query/getWorkCenter.generated.ts +5 -0
- package/src/modules/manufacturing/query/getWorkCenter.test.ts +37 -0
- package/src/modules/manufacturing/query/getWorkCenter.ts +21 -0
- package/src/modules/manufacturing/query/getWorkOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/getWorkOrder.test.ts +73 -0
- package/src/modules/manufacturing/query/getWorkOrder.ts +28 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.generated.ts +5 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.test.ts +107 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.ts +58 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.generated.ts +5 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.test.ts +96 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.ts +77 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.generated.ts +5 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.test.ts +121 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.ts +83 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.generated.ts +5 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.test.ts +110 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.ts +54 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.test.ts +81 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.ts +70 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.test.ts +102 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.ts +53 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.test.ts +143 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.ts +56 -0
- package/src/modules/manufacturing/seed/index.ts +19 -0
- package/src/modules/manufacturing/tailor.config.ts +13 -0
- package/src/modules/manufacturing/tailor.d.ts +13 -0
- package/src/modules/manufacturing/testing/commandTestUtils.ts +29 -0
- package/src/modules/manufacturing/testing/fixtures.ts +402 -0
- package/templates/scaffold/app/backend/package.json +9 -2
- package/templates/scaffold/app/backend/src/tests/utils/graphql-client.ts +66 -0
- package/templates/scaffold/app/backend/src/tests/utils/setup.ts +21 -0
- package/templates/scaffold/app/backend/tsconfig.json +9 -2
- package/templates/scaffold/app/backend/vitest.config.ts +35 -0
- package/templates/scaffold/app/frontend/package.json +2 -2
- package/templates/scaffold/module/__dot__gitignore +3 -0
- package/templates/scaffold/module/eslint.config.js +31 -0
- package/templates/scaffold/module/generated/kysely-tailordb.ts +3 -0
- package/templates/scaffold/module/lib/types.ts +1 -6
- package/templates/scaffold/module/package.json +26 -0
- package/templates/scaffold/module/tsconfig.json +16 -0
- /package/{templates/scaffold/module/generated → src/modules/manufacturing/command}/.gitkeep +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createMockDb } from "../../../testing/index";
|
|
3
|
+
import type { DB } from "../generated/kysely-tailordb";
|
|
4
|
+
import { expectOk, expectErr } from "../testing/commandTestUtils";
|
|
5
|
+
import {
|
|
6
|
+
BomReferenceRequiredError,
|
|
7
|
+
EffectivityDateRequiredError,
|
|
8
|
+
BomNotFoundError,
|
|
9
|
+
BomNotEffectiveOnDateError,
|
|
10
|
+
ChildBomNotResolvedError,
|
|
11
|
+
BomCircularReferenceDetectedError,
|
|
12
|
+
} from "../lib/errors.generated";
|
|
13
|
+
import { run } from "./explodeBillOfMaterial";
|
|
14
|
+
|
|
15
|
+
const effectivityDate = new Date("2024-06-01T00:00:00.000Z");
|
|
16
|
+
|
|
17
|
+
const rootBom = {
|
|
18
|
+
id: "bom-1",
|
|
19
|
+
parentItemId: "item-1",
|
|
20
|
+
companyId: "company-1",
|
|
21
|
+
siteId: null,
|
|
22
|
+
bomType: "MANUFACTURE",
|
|
23
|
+
effectivityStartDate: null,
|
|
24
|
+
effectivityEndDate: null,
|
|
25
|
+
defaultSelection: true,
|
|
26
|
+
revisionNumber: "V1",
|
|
27
|
+
status: "ACTIVE",
|
|
28
|
+
createdAt: new Date("2024-01-01T00:00:00.000Z"),
|
|
29
|
+
updatedAt: null,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("explodeBillOfMaterial", () => {
|
|
33
|
+
it("explodes a multi-level manufacture BOM into recursive component requirements", async () => {
|
|
34
|
+
const { db, spies } = createMockDb<DB>();
|
|
35
|
+
// root BOM
|
|
36
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
37
|
+
// root BOM lines
|
|
38
|
+
spies.select.mockReturnValueOnce([
|
|
39
|
+
{
|
|
40
|
+
itemId: "item-2",
|
|
41
|
+
requiredQuantity: 2,
|
|
42
|
+
unitOfMeasure: "EA",
|
|
43
|
+
isSubassembly: false,
|
|
44
|
+
billOfMaterialId: "bom-1",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
itemId: "item-3",
|
|
48
|
+
requiredQuantity: 1,
|
|
49
|
+
unitOfMeasure: "EA",
|
|
50
|
+
isSubassembly: true,
|
|
51
|
+
billOfMaterialId: "bom-1",
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
// active child BOMs for item-3
|
|
55
|
+
spies.select.mockReturnValueOnce([
|
|
56
|
+
{
|
|
57
|
+
id: "bom-child",
|
|
58
|
+
parentItemId: "item-3",
|
|
59
|
+
companyId: "company-1",
|
|
60
|
+
status: "ACTIVE",
|
|
61
|
+
bomType: "MANUFACTURE",
|
|
62
|
+
effectivityStartDate: null,
|
|
63
|
+
effectivityEndDate: null,
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
// child BOM lines
|
|
67
|
+
spies.select.mockReturnValueOnce([
|
|
68
|
+
{
|
|
69
|
+
itemId: "item-4",
|
|
70
|
+
requiredQuantity: 3,
|
|
71
|
+
unitOfMeasure: "EA",
|
|
72
|
+
isSubassembly: false,
|
|
73
|
+
billOfMaterialId: "bom-child",
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
78
|
+
const value = expectOk<{ components: unknown[] }>(result as never);
|
|
79
|
+
|
|
80
|
+
expect(value.components).toHaveLength(3);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("flattens phantom subassemblies into the nearest non-phantom parent path", async () => {
|
|
84
|
+
const { db, spies } = createMockDb<DB>();
|
|
85
|
+
// root BOM (MANUFACTURE type with a PHANTOM subassembly)
|
|
86
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
87
|
+
// root BOM lines - one subassembly that is phantom
|
|
88
|
+
spies.select.mockReturnValueOnce([
|
|
89
|
+
{
|
|
90
|
+
itemId: "item-phantom",
|
|
91
|
+
requiredQuantity: 2,
|
|
92
|
+
unitOfMeasure: "EA",
|
|
93
|
+
isSubassembly: true,
|
|
94
|
+
billOfMaterialId: "bom-1",
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
// Resolve child BOMs for item-phantom — it's a PHANTOM BOM
|
|
98
|
+
spies.select.mockReturnValueOnce([
|
|
99
|
+
{
|
|
100
|
+
id: "bom-phantom",
|
|
101
|
+
parentItemId: "item-phantom",
|
|
102
|
+
companyId: "company-1",
|
|
103
|
+
status: "ACTIVE",
|
|
104
|
+
bomType: "PHANTOM",
|
|
105
|
+
effectivityStartDate: null,
|
|
106
|
+
effectivityEndDate: null,
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
// PHANTOM BOM lines — these should be flattened
|
|
110
|
+
spies.select.mockReturnValueOnce([
|
|
111
|
+
{
|
|
112
|
+
itemId: "item-raw-1",
|
|
113
|
+
requiredQuantity: 3,
|
|
114
|
+
unitOfMeasure: "EA",
|
|
115
|
+
isSubassembly: false,
|
|
116
|
+
billOfMaterialId: "bom-phantom",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
itemId: "item-raw-2",
|
|
120
|
+
requiredQuantity: 5,
|
|
121
|
+
unitOfMeasure: "EA",
|
|
122
|
+
isSubassembly: false,
|
|
123
|
+
billOfMaterialId: "bom-phantom",
|
|
124
|
+
},
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
128
|
+
const value = expectOk<{
|
|
129
|
+
components: { itemId: string; requiredQuantity: number; depth: number }[];
|
|
130
|
+
}>(result as never);
|
|
131
|
+
|
|
132
|
+
// Phantom subassembly is NOT in the output — its children are flattened
|
|
133
|
+
expect(value.components).toHaveLength(2);
|
|
134
|
+
const raw1 = value.components.find((c) => c.itemId === "item-raw-1");
|
|
135
|
+
expect(raw1).toBeDefined();
|
|
136
|
+
expect(raw1!.requiredQuantity).toBe(6); // 2 * 3
|
|
137
|
+
expect(raw1!.depth).toBe(1); // flattened to parent depth
|
|
138
|
+
const raw2 = value.components.find((c) => c.itemId === "item-raw-2");
|
|
139
|
+
expect(raw2).toBeDefined();
|
|
140
|
+
expect(raw2!.requiredQuantity).toBe(10); // 2 * 5
|
|
141
|
+
expect(raw2!.depth).toBe(1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("expands a kit BOM into component issue requirements without work-order context for the kit parent", async () => {
|
|
145
|
+
const { db, spies } = createMockDb<DB>();
|
|
146
|
+
const kitBom = { ...rootBom, bomType: "KIT" };
|
|
147
|
+
// root BOM (kit type)
|
|
148
|
+
spies.select.mockReturnValueOnce(kitBom);
|
|
149
|
+
// kit BOM lines — includes one marked as subassembly
|
|
150
|
+
spies.select.mockReturnValueOnce([
|
|
151
|
+
{
|
|
152
|
+
itemId: "item-2",
|
|
153
|
+
requiredQuantity: 1,
|
|
154
|
+
unitOfMeasure: "EA",
|
|
155
|
+
isSubassembly: false,
|
|
156
|
+
billOfMaterialId: "bom-1",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
itemId: "item-3",
|
|
160
|
+
requiredQuantity: 2,
|
|
161
|
+
unitOfMeasure: "EA",
|
|
162
|
+
isSubassembly: true, // even subassemblies treated as issue-only
|
|
163
|
+
billOfMaterialId: "bom-1",
|
|
164
|
+
},
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
168
|
+
const value = expectOk<{
|
|
169
|
+
components: { itemId: string; isSubassembly: boolean }[];
|
|
170
|
+
}>(result as never);
|
|
171
|
+
|
|
172
|
+
expect(value.components).toHaveLength(2);
|
|
173
|
+
// All components are issue-only (isSubassembly = false)
|
|
174
|
+
expect(value.components.every((c) => c.isSubassembly === false)).toBe(true);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("resolves lower-level child BOM versions using the requested effectivity date", async () => {
|
|
178
|
+
const { db, spies } = createMockDb<DB>();
|
|
179
|
+
// root BOM
|
|
180
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
181
|
+
// root BOM lines - one subassembly
|
|
182
|
+
spies.select.mockReturnValueOnce([
|
|
183
|
+
{
|
|
184
|
+
itemId: "item-3",
|
|
185
|
+
requiredQuantity: 1,
|
|
186
|
+
unitOfMeasure: "EA",
|
|
187
|
+
isSubassembly: true,
|
|
188
|
+
billOfMaterialId: "bom-1",
|
|
189
|
+
},
|
|
190
|
+
]);
|
|
191
|
+
// active child BOMs for item-3 - two versions, only one effective on date
|
|
192
|
+
spies.select.mockReturnValueOnce([
|
|
193
|
+
{
|
|
194
|
+
id: "bom-child-old",
|
|
195
|
+
parentItemId: "item-3",
|
|
196
|
+
companyId: "company-1",
|
|
197
|
+
status: "ACTIVE",
|
|
198
|
+
bomType: "MANUFACTURE",
|
|
199
|
+
effectivityStartDate: null,
|
|
200
|
+
effectivityEndDate: "2024-01-01T00:00:00.000Z",
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "bom-child-new",
|
|
204
|
+
parentItemId: "item-3",
|
|
205
|
+
companyId: "company-1",
|
|
206
|
+
status: "ACTIVE",
|
|
207
|
+
bomType: "MANUFACTURE",
|
|
208
|
+
effectivityStartDate: "2024-02-01T00:00:00.000Z",
|
|
209
|
+
effectivityEndDate: null,
|
|
210
|
+
},
|
|
211
|
+
]);
|
|
212
|
+
// child BOM lines for the effective version
|
|
213
|
+
spies.select.mockReturnValueOnce([
|
|
214
|
+
{
|
|
215
|
+
itemId: "item-5",
|
|
216
|
+
requiredQuantity: 4,
|
|
217
|
+
unitOfMeasure: "EA",
|
|
218
|
+
isSubassembly: false,
|
|
219
|
+
billOfMaterialId: "bom-child-new",
|
|
220
|
+
},
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
224
|
+
const value = expectOk<{ components: unknown[] }>(result as never);
|
|
225
|
+
|
|
226
|
+
// subassembly line + its child component
|
|
227
|
+
expect(value.components).toHaveLength(2);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("resolves lower-level child BOMs using the applicable site scope", async () => {
|
|
231
|
+
const { db, spies } = createMockDb<DB>();
|
|
232
|
+
spies.select.mockReturnValueOnce({ ...rootBom, siteId: "site-1" });
|
|
233
|
+
spies.select.mockReturnValueOnce([
|
|
234
|
+
{
|
|
235
|
+
itemId: "item-3",
|
|
236
|
+
requiredQuantity: 1,
|
|
237
|
+
unitOfMeasure: "EA",
|
|
238
|
+
isSubassembly: true,
|
|
239
|
+
billOfMaterialId: "bom-1",
|
|
240
|
+
},
|
|
241
|
+
]);
|
|
242
|
+
spies.select.mockReturnValueOnce([
|
|
243
|
+
{
|
|
244
|
+
id: "bom-child-other-site",
|
|
245
|
+
parentItemId: "item-3",
|
|
246
|
+
companyId: "company-1",
|
|
247
|
+
siteId: "site-2",
|
|
248
|
+
status: "ACTIVE",
|
|
249
|
+
bomType: "MANUFACTURE",
|
|
250
|
+
effectivityStartDate: null,
|
|
251
|
+
effectivityEndDate: null,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "bom-child-site-1",
|
|
255
|
+
parentItemId: "item-3",
|
|
256
|
+
companyId: "company-1",
|
|
257
|
+
siteId: "site-1",
|
|
258
|
+
status: "ACTIVE",
|
|
259
|
+
bomType: "MANUFACTURE",
|
|
260
|
+
effectivityStartDate: null,
|
|
261
|
+
effectivityEndDate: null,
|
|
262
|
+
},
|
|
263
|
+
]);
|
|
264
|
+
spies.select.mockReturnValueOnce([
|
|
265
|
+
{
|
|
266
|
+
itemId: "item-5",
|
|
267
|
+
requiredQuantity: 4,
|
|
268
|
+
unitOfMeasure: "EA",
|
|
269
|
+
isSubassembly: false,
|
|
270
|
+
billOfMaterialId: "bom-child-site-1",
|
|
271
|
+
},
|
|
272
|
+
]);
|
|
273
|
+
|
|
274
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
275
|
+
const value = expectOk<{ components: { bomPath: string[] }[] }>(result as never);
|
|
276
|
+
|
|
277
|
+
expect(
|
|
278
|
+
value.components.some((component) => component.bomPath.includes("bom-child-site-1")),
|
|
279
|
+
).toBe(true);
|
|
280
|
+
expect(
|
|
281
|
+
value.components.some((component) => component.bomPath.includes("bom-child-other-site")),
|
|
282
|
+
).toBe(false);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("returns cumulative quantities and source BOM path metadata for exploded components", async () => {
|
|
286
|
+
const { db, spies } = createMockDb<DB>();
|
|
287
|
+
// root BOM
|
|
288
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
289
|
+
// root BOM lines - subassembly with quantity multiplier
|
|
290
|
+
spies.select.mockReturnValueOnce([
|
|
291
|
+
{
|
|
292
|
+
itemId: "item-3",
|
|
293
|
+
requiredQuantity: 2,
|
|
294
|
+
unitOfMeasure: "EA",
|
|
295
|
+
isSubassembly: true,
|
|
296
|
+
billOfMaterialId: "bom-1",
|
|
297
|
+
},
|
|
298
|
+
]);
|
|
299
|
+
// active child BOMs for item-3
|
|
300
|
+
spies.select.mockReturnValueOnce([
|
|
301
|
+
{
|
|
302
|
+
id: "bom-child",
|
|
303
|
+
parentItemId: "item-3",
|
|
304
|
+
companyId: "company-1",
|
|
305
|
+
status: "ACTIVE",
|
|
306
|
+
bomType: "MANUFACTURE",
|
|
307
|
+
effectivityStartDate: null,
|
|
308
|
+
effectivityEndDate: null,
|
|
309
|
+
},
|
|
310
|
+
]);
|
|
311
|
+
// child BOM lines
|
|
312
|
+
spies.select.mockReturnValueOnce([
|
|
313
|
+
{
|
|
314
|
+
itemId: "item-4",
|
|
315
|
+
requiredQuantity: 3,
|
|
316
|
+
unitOfMeasure: "EA",
|
|
317
|
+
isSubassembly: false,
|
|
318
|
+
billOfMaterialId: "bom-child",
|
|
319
|
+
},
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
323
|
+
const value = expectOk<{
|
|
324
|
+
components: {
|
|
325
|
+
itemId: string;
|
|
326
|
+
requiredQuantity: number;
|
|
327
|
+
depth: number;
|
|
328
|
+
bomPath: string[];
|
|
329
|
+
}[];
|
|
330
|
+
}>(result as never);
|
|
331
|
+
|
|
332
|
+
// item-3 subassembly: qty 2, depth 1
|
|
333
|
+
const subassembly = value.components.find((c) => c.itemId === "item-3");
|
|
334
|
+
expect(subassembly).toBeDefined();
|
|
335
|
+
expect(subassembly!.requiredQuantity).toBe(2);
|
|
336
|
+
expect(subassembly!.depth).toBe(1);
|
|
337
|
+
|
|
338
|
+
// item-4 leaf: qty 2 * 3 = 6, depth 2
|
|
339
|
+
const leaf = value.components.find((c) => c.itemId === "item-4");
|
|
340
|
+
expect(leaf).toBeDefined();
|
|
341
|
+
expect(leaf!.requiredQuantity).toBe(6);
|
|
342
|
+
expect(leaf!.depth).toBe(2);
|
|
343
|
+
expect(leaf!.bomPath).toContain("bom-1");
|
|
344
|
+
expect(leaf!.bomPath).toContain("bom-child");
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("returns error when the BOM reference is missing", async () => {
|
|
348
|
+
const { db } = createMockDb<DB>();
|
|
349
|
+
|
|
350
|
+
const result = await run(db, { bomId: "", effectivityDate });
|
|
351
|
+
expectErr(result as never, BomReferenceRequiredError);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("returns error when the effectivity date is missing", async () => {
|
|
355
|
+
const { db } = createMockDb<DB>();
|
|
356
|
+
|
|
357
|
+
const result = await run(db, {
|
|
358
|
+
bomId: "bom-1",
|
|
359
|
+
effectivityDate: undefined as unknown as Date,
|
|
360
|
+
});
|
|
361
|
+
expectErr(result as never, EffectivityDateRequiredError);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("returns error when the root BOM is not found", async () => {
|
|
365
|
+
const { db, spies } = createMockDb<DB>();
|
|
366
|
+
spies.select.mockReturnValueOnce(undefined);
|
|
367
|
+
|
|
368
|
+
const result = await run(db, { bomId: "nonexistent", effectivityDate });
|
|
369
|
+
expectErr(result as never, BomNotFoundError);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("returns error when the root BOM is not effective on the requested date", async () => {
|
|
373
|
+
const { db, spies } = createMockDb<DB>();
|
|
374
|
+
const expiredBom = {
|
|
375
|
+
...rootBom,
|
|
376
|
+
effectivityEndDate: "2023-01-01T00:00:00.000Z",
|
|
377
|
+
};
|
|
378
|
+
spies.select.mockReturnValueOnce(expiredBom);
|
|
379
|
+
|
|
380
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
381
|
+
expectErr(result as never, BomNotEffectiveOnDateError);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("returns error when a required lower-level child BOM cannot be resolved", async () => {
|
|
385
|
+
const { db, spies } = createMockDb<DB>();
|
|
386
|
+
// root BOM
|
|
387
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
388
|
+
// root BOM lines - one subassembly
|
|
389
|
+
spies.select.mockReturnValueOnce([
|
|
390
|
+
{
|
|
391
|
+
itemId: "item-3",
|
|
392
|
+
requiredQuantity: 1,
|
|
393
|
+
unitOfMeasure: "EA",
|
|
394
|
+
isSubassembly: true,
|
|
395
|
+
billOfMaterialId: "bom-1",
|
|
396
|
+
},
|
|
397
|
+
]);
|
|
398
|
+
// no active child BOMs for item-3
|
|
399
|
+
spies.select.mockReturnValueOnce([]);
|
|
400
|
+
|
|
401
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
402
|
+
expectErr(result as never, ChildBomNotResolvedError);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("returns error when the explosion detects a circular BOM reference", async () => {
|
|
406
|
+
const { db, spies } = createMockDb<DB>();
|
|
407
|
+
// root BOM
|
|
408
|
+
spies.select.mockReturnValueOnce(rootBom);
|
|
409
|
+
// root BOM lines - subassembly item-3
|
|
410
|
+
spies.select.mockReturnValueOnce([
|
|
411
|
+
{
|
|
412
|
+
itemId: "item-3",
|
|
413
|
+
requiredQuantity: 1,
|
|
414
|
+
unitOfMeasure: "EA",
|
|
415
|
+
isSubassembly: true,
|
|
416
|
+
billOfMaterialId: "bom-1",
|
|
417
|
+
},
|
|
418
|
+
]);
|
|
419
|
+
// active child BOMs for item-3
|
|
420
|
+
spies.select.mockReturnValueOnce([
|
|
421
|
+
{
|
|
422
|
+
id: "bom-child",
|
|
423
|
+
parentItemId: "item-3",
|
|
424
|
+
companyId: "company-1",
|
|
425
|
+
status: "ACTIVE",
|
|
426
|
+
bomType: "MANUFACTURE",
|
|
427
|
+
effectivityStartDate: null,
|
|
428
|
+
effectivityEndDate: null,
|
|
429
|
+
},
|
|
430
|
+
]);
|
|
431
|
+
// child BOM lines - subassembly pointing back to item-3 (circular!)
|
|
432
|
+
spies.select.mockReturnValueOnce([
|
|
433
|
+
{
|
|
434
|
+
itemId: "item-3",
|
|
435
|
+
requiredQuantity: 1,
|
|
436
|
+
unitOfMeasure: "EA",
|
|
437
|
+
isSubassembly: true,
|
|
438
|
+
billOfMaterialId: "bom-child",
|
|
439
|
+
},
|
|
440
|
+
]);
|
|
441
|
+
|
|
442
|
+
const result = await run(db, { bomId: "bom-1", effectivityDate });
|
|
443
|
+
expectErr(result as never, BomCircularReferenceDetectedError);
|
|
444
|
+
});
|
|
445
|
+
});
|