@open-mercato/core 0.10.1-develop.7709.1.046124599c → 0.10.1-develop.7714.1.9dbb8200d8
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/.turbo/turbo-build.log +2 -2
- package/dist/generated/entities/asn/index.js +19 -0
- package/dist/generated/entities/asn/index.js.map +7 -0
- package/dist/generated/entities/putaway_task/index.js +25 -0
- package/dist/generated/entities/putaway_task/index.js.map +7 -0
- package/dist/generated/entities/receiving_line/index.js +21 -0
- package/dist/generated/entities/receiving_line/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +4 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +34 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/communication_channels/lib/sanitize-channel-html.js +22 -3
- package/dist/modules/communication_channels/lib/sanitize-channel-html.js.map +2 -2
- package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js +40 -11
- package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js.map +2 -2
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js +13 -2
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js.map +2 -2
- package/dist/modules/wms/acl.js +2 -0
- package/dist/modules/wms/acl.js.map +2 -2
- package/dist/modules/wms/api/asns/[id]/complete/route.js +61 -0
- package/dist/modules/wms/api/asns/[id]/complete/route.js.map +7 -0
- package/dist/modules/wms/api/asns/[id]/receive/route.js +68 -0
- package/dist/modules/wms/api/asns/[id]/receive/route.js.map +7 -0
- package/dist/modules/wms/api/asns/route.js +197 -0
- package/dist/modules/wms/api/asns/route.js.map +7 -0
- package/dist/modules/wms/api/inventory/helpers.js +42 -34
- package/dist/modules/wms/api/inventory/helpers.js.map +2 -2
- package/dist/modules/wms/api/inventory/receive/route.js +1 -1
- package/dist/modules/wms/api/inventory/receive/route.js.map +2 -2
- package/dist/modules/wms/api/listEnrichers.js +23 -0
- package/dist/modules/wms/api/listEnrichers.js.map +2 -2
- package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js +65 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js +56 -0
- package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js +51 -0
- package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js.map +7 -0
- package/dist/modules/wms/api/putaway-tasks/route.js +192 -0
- package/dist/modules/wms/api/putaway-tasks/route.js.map +7 -0
- package/dist/modules/wms/api/receiving-lines/route.js +180 -0
- package/dist/modules/wms/api/receiving-lines/route.js.map +7 -0
- package/dist/modules/wms/api/scan/putaway/route.js +104 -0
- package/dist/modules/wms/api/scan/putaway/route.js.map +7 -0
- package/dist/modules/wms/api/scan/receive/route.js +109 -0
- package/dist/modules/wms/api/scan/receive/route.js.map +7 -0
- package/dist/modules/wms/api/scan/resolve-location/route.js +89 -0
- package/dist/modules/wms/api/scan/resolve-location/route.js.map +7 -0
- package/dist/modules/wms/api/scan/resolve-lot/route.js +89 -0
- package/dist/modules/wms/api/scan/resolve-lot/route.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.js +9 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/page.js +9 -0
- package/dist/modules/wms/backend/wms/asns/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/asns/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/asns/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/putaway/page.js +9 -0
- package/dist/modules/wms/backend/wms/putaway/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/putaway/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/putaway/page.meta.js.map +7 -0
- package/dist/modules/wms/backend/wms/receiving/page.js +8 -0
- package/dist/modules/wms/backend/wms/receiving/page.js.map +7 -0
- package/dist/modules/wms/backend/wms/receiving/page.meta.js +18 -0
- package/dist/modules/wms/backend/wms/receiving/page.meta.js.map +7 -0
- package/dist/modules/wms/ce.js +27 -0
- package/dist/modules/wms/ce.js.map +2 -2
- package/dist/modules/wms/commands/asn.js +1746 -0
- package/dist/modules/wms/commands/asn.js.map +7 -0
- package/dist/modules/wms/commands/index.js +2 -0
- package/dist/modules/wms/commands/index.js.map +2 -2
- package/dist/modules/wms/commands/inventory-actions.js +347 -243
- package/dist/modules/wms/commands/inventory-actions.js.map +2 -2
- package/dist/modules/wms/commands/putaway.js +945 -0
- package/dist/modules/wms/commands/putaway.js.map +7 -0
- package/dist/modules/wms/commands/shared.js +51 -0
- package/dist/modules/wms/commands/shared.js.map +2 -2
- package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js +278 -0
- package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js +327 -0
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/CreateAsnDialog.js +404 -0
- package/dist/modules/wms/components/backend/CreateAsnDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js +16 -3
- package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +2 -2
- package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js +476 -0
- package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js.map +7 -0
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +2 -2
- package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsAsnDetailPage.js +524 -0
- package/dist/modules/wms/components/backend/WmsAsnDetailPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsAsnsListPage.js +339 -0
- package/dist/modules/wms/components/backend/WmsAsnsListPage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +14 -10
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js +598 -0
- package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js.map +7 -0
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +5 -6
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js +32 -0
- package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js.map +7 -0
- package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js +36 -0
- package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js.map +7 -0
- package/dist/modules/wms/components/backend/inboundStatusUi.js +106 -0
- package/dist/modules/wms/components/backend/inboundStatusUi.js.map +7 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +17 -0
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +2 -2
- package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js +14 -0
- package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js.map +7 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +4 -0
- package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +2 -2
- package/dist/modules/wms/data/enrichers.js +117 -12
- package/dist/modules/wms/data/enrichers.js.map +2 -2
- package/dist/modules/wms/data/entities.js +150 -1
- package/dist/modules/wms/data/entities.js.map +2 -2
- package/dist/modules/wms/data/validators.js +214 -0
- package/dist/modules/wms/data/validators.js.map +2 -2
- package/dist/modules/wms/events.js +12 -1
- package/dist/modules/wms/events.js.map +2 -2
- package/dist/modules/wms/extension-points.js +3 -1
- package/dist/modules/wms/extension-points.js.map +2 -2
- package/dist/modules/wms/lib/asnReceiving.js +124 -0
- package/dist/modules/wms/lib/asnReceiving.js.map +7 -0
- package/dist/modules/wms/lib/asnVendor.js +52 -0
- package/dist/modules/wms/lib/asnVendor.js.map +7 -0
- package/dist/modules/wms/lib/flashMutationError.js +4 -0
- package/dist/modules/wms/lib/flashMutationError.js.map +2 -2
- package/dist/modules/wms/lib/inventoryDisplayUi.js +24 -0
- package/dist/modules/wms/lib/inventoryDisplayUi.js.map +2 -2
- package/dist/modules/wms/lib/inventoryPolicy.js +17 -0
- package/dist/modules/wms/lib/inventoryPolicy.js.map +2 -2
- package/dist/modules/wms/lib/loadOperationalDashboard.js +67 -1
- package/dist/modules/wms/lib/loadOperationalDashboard.js.map +2 -2
- package/dist/modules/wms/lib/putaway.js +141 -0
- package/dist/modules/wms/lib/putaway.js.map +7 -0
- package/dist/modules/wms/lib/roleFeatures.js +3 -1
- package/dist/modules/wms/lib/roleFeatures.js.map +2 -2
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +99 -1
- package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +2 -2
- package/dist/modules/wms/lib/scanResolve.js +147 -0
- package/dist/modules/wms/lib/scanResolve.js.map +7 -0
- package/dist/modules/wms/lib/wmsIntegrationToggles.js +1 -1
- package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +2 -2
- package/dist/modules/wms/migrations/Migration20260812120000.js +43 -0
- package/dist/modules/wms/migrations/Migration20260812120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260812130000.js +30 -0
- package/dist/modules/wms/migrations/Migration20260812130000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260822120000.js +17 -0
- package/dist/modules/wms/migrations/Migration20260822120000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20260822130000.js +17 -0
- package/dist/modules/wms/migrations/Migration20260822130000.js.map +7 -0
- package/dist/modules/wms/migrations/Migration20261029120000.js +13 -0
- package/dist/modules/wms/migrations/Migration20261029120000.js.map +7 -0
- package/dist/modules/wms/search.js +85 -0
- package/dist/modules/wms/search.js.map +2 -2
- package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js +14 -0
- package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js.map +7 -0
- package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js +12 -0
- package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js.map +7 -0
- package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js +163 -0
- package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js.map +7 -0
- package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js +14 -0
- package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js.map +7 -0
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +37 -8
- package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +2 -2
- package/generated/entities/asn/index.ts +8 -0
- package/generated/entities/putaway_task/index.ts +11 -0
- package/generated/entities/receiving_line/index.ts +9 -0
- package/generated/entities.ids.generated.ts +4 -1
- package/generated/entity-fields-registry.ts +34 -0
- package/package.json +7 -7
- package/src/modules/auth/i18n/de.json +2 -0
- package/src/modules/auth/i18n/en.json +2 -0
- package/src/modules/auth/i18n/es.json +2 -0
- package/src/modules/auth/i18n/ko.json +2 -0
- package/src/modules/auth/i18n/pl.json +2 -0
- package/src/modules/communication_channels/i18n/de.json +2 -0
- package/src/modules/communication_channels/i18n/en.json +2 -0
- package/src/modules/communication_channels/i18n/es.json +2 -0
- package/src/modules/communication_channels/i18n/ko.json +2 -0
- package/src/modules/communication_channels/i18n/pl.json +2 -0
- package/src/modules/communication_channels/lib/sanitize-channel-html.ts +23 -3
- package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.tsx +44 -12
- package/src/modules/customers/components/calendar/CalendarEventEditor.tsx +16 -2
- package/src/modules/wms/acl.ts +2 -0
- package/src/modules/wms/api/asns/[id]/complete/route.ts +62 -0
- package/src/modules/wms/api/asns/[id]/receive/route.ts +74 -0
- package/src/modules/wms/api/asns/route.ts +200 -0
- package/src/modules/wms/api/inventory/helpers.ts +57 -34
- package/src/modules/wms/api/inventory/receive/route.ts +2 -1
- package/src/modules/wms/api/listEnrichers.ts +38 -0
- package/src/modules/wms/api/putaway-tasks/[id]/assign/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/[id]/cancel/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/[id]/complete/route.ts +66 -0
- package/src/modules/wms/api/putaway-tasks/[id]/start/route.ts +56 -0
- package/src/modules/wms/api/putaway-tasks/create-from-balance/route.ts +50 -0
- package/src/modules/wms/api/putaway-tasks/route.ts +199 -0
- package/src/modules/wms/api/receiving-lines/route.ts +180 -0
- package/src/modules/wms/api/scan/putaway/route.ts +108 -0
- package/src/modules/wms/api/scan/receive/route.ts +118 -0
- package/src/modules/wms/api/scan/resolve-location/route.ts +92 -0
- package/src/modules/wms/api/scan/resolve-lot/route.ts +92 -0
- package/src/modules/wms/backend/wms/asns/[id]/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/asns/[id]/page.tsx +5 -0
- package/src/modules/wms/backend/wms/asns/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/asns/page.tsx +5 -0
- package/src/modules/wms/backend/wms/putaway/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/putaway/page.tsx +5 -0
- package/src/modules/wms/backend/wms/receiving/page.meta.ts +14 -0
- package/src/modules/wms/backend/wms/receiving/page.tsx +5 -0
- package/src/modules/wms/ce.ts +27 -0
- package/src/modules/wms/commands/asn.ts +2122 -0
- package/src/modules/wms/commands/index.ts +2 -0
- package/src/modules/wms/commands/inventory-actions.ts +413 -243
- package/src/modules/wms/commands/putaway.ts +1169 -0
- package/src/modules/wms/commands/shared.ts +51 -0
- package/src/modules/wms/components/backend/AssignPutawayTaskDialog.tsx +328 -0
- package/src/modules/wms/components/backend/CompletePutawayTaskDialog.tsx +366 -0
- package/src/modules/wms/components/backend/CreateAsnDialog.tsx +427 -0
- package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +20 -2
- package/src/modules/wms/components/backend/ReceiveAsnLineDialog.tsx +535 -0
- package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +2 -2
- package/src/modules/wms/components/backend/WmsAsnDetailPage.tsx +647 -0
- package/src/modules/wms/components/backend/WmsAsnsListPage.tsx +407 -0
- package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +12 -8
- package/src/modules/wms/components/backend/WmsPutawayQueuePage.tsx +677 -0
- package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +4 -5
- package/src/modules/wms/components/backend/asnCompleteOptimisticLock.ts +52 -0
- package/src/modules/wms/components/backend/asnReceivingLinesLoader.ts +83 -0
- package/src/modules/wms/components/backend/inboundStatusUi.ts +154 -0
- package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +20 -0
- package/src/modules/wms/components/backend/putawayQueueOptimisticLock.ts +20 -0
- package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +4 -0
- package/src/modules/wms/data/enrichers.ts +175 -13
- package/src/modules/wms/data/entities.ts +155 -0
- package/src/modules/wms/data/validators.ts +256 -0
- package/src/modules/wms/events.ts +11 -0
- package/src/modules/wms/extension-points.ts +2 -0
- package/src/modules/wms/i18n/de.json +205 -3
- package/src/modules/wms/i18n/en.json +205 -3
- package/src/modules/wms/i18n/es.json +205 -3
- package/src/modules/wms/i18n/ko.json +205 -3
- package/src/modules/wms/i18n/pl.json +205 -3
- package/src/modules/wms/lib/asnReceiving.ts +226 -0
- package/src/modules/wms/lib/asnVendor.ts +80 -0
- package/src/modules/wms/lib/flashMutationError.ts +4 -0
- package/src/modules/wms/lib/inventoryDisplayUi.ts +46 -0
- package/src/modules/wms/lib/inventoryPolicy.ts +31 -1
- package/src/modules/wms/lib/loadOperationalDashboard.ts +89 -1
- package/src/modules/wms/lib/putaway.ts +210 -0
- package/src/modules/wms/lib/roleFeatures.ts +2 -0
- package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +150 -1
- package/src/modules/wms/lib/scanResolve.ts +185 -0
- package/src/modules/wms/lib/wmsIntegrationToggles.ts +2 -1
- package/src/modules/wms/migrations/.snapshot-open-mercato.json +1000 -0
- package/src/modules/wms/migrations/Migration20260812120000.ts +43 -0
- package/src/modules/wms/migrations/Migration20260812130000.ts +28 -0
- package/src/modules/wms/migrations/Migration20260822120000.ts +17 -0
- package/src/modules/wms/migrations/Migration20260822130000.ts +15 -0
- package/src/modules/wms/migrations/Migration20261029120000.ts +11 -0
- package/src/modules/wms/search.ts +95 -0
- package/src/modules/wms/subscribers/asn-line-received-reevaluate-reservations.ts +21 -0
- package/src/modules/wms/subscribers/invalidate-enricher-cache-asn.ts +12 -0
- package/src/modules/wms/subscribers/procurement-goods-receipt-created.ts +238 -0
- package/src/modules/wms/subscribers/putaway-completed-reevaluate-reservations.ts +21 -0
- package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +63 -13
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
2
2
|
import { E } from "../../../generated/entities.ids.generated.js";
|
|
3
3
|
import { InventoryBalance, InventoryReservation, ProductInventoryProfile, SalesOrderWarehouseAssignment, Warehouse } from "./entities.js";
|
|
4
|
+
import { formatCatalogVariantLabel } from "../lib/inventoryDisplayUi.js";
|
|
5
|
+
import { isBalanceLocationReservable } from "../lib/inventoryPolicy.js";
|
|
4
6
|
import { resolvePrimaryWarehouseId } from "../lib/primaryWarehousePolicy.js";
|
|
5
7
|
import {
|
|
6
8
|
WMS_ENRICHER_CACHE_TTL_MS,
|
|
@@ -8,6 +10,10 @@ import {
|
|
|
8
10
|
WMS_WAREHOUSE_CACHE_TAG
|
|
9
11
|
} from "../lib/enricherCacheTags.js";
|
|
10
12
|
import { resolveWmsIntegrationToggleEnabled } from "../lib/wmsIntegrationToggles.js";
|
|
13
|
+
const EMPTY_INBOUND_SUMMARY = {
|
|
14
|
+
openAsnCount: 0,
|
|
15
|
+
nextExpectedAt: null
|
|
16
|
+
};
|
|
11
17
|
const EMPTY_ENRICHMENT = {
|
|
12
18
|
_wms: {
|
|
13
19
|
assignedWarehouseId: null,
|
|
@@ -16,8 +22,10 @@ const EMPTY_ENRICHMENT = {
|
|
|
16
22
|
stockSummary: [],
|
|
17
23
|
reservationSummary: {
|
|
18
24
|
status: "unreserved",
|
|
19
|
-
reservationIds: []
|
|
20
|
-
|
|
25
|
+
reservationIds: [],
|
|
26
|
+
reservations: []
|
|
27
|
+
},
|
|
28
|
+
inboundSummary: EMPTY_INBOUND_SUMMARY
|
|
21
29
|
}
|
|
22
30
|
};
|
|
23
31
|
const EMPTY_CATALOG_ENRICHMENT = {
|
|
@@ -73,6 +81,43 @@ function resolveReservationStatus(requiredQuantity, reservedQuantity) {
|
|
|
73
81
|
if (reservedQuantity + 1e-4 < requiredQuantity) return "partially_reserved";
|
|
74
82
|
return "fully_reserved";
|
|
75
83
|
}
|
|
84
|
+
function buildReservationLabel(input) {
|
|
85
|
+
const variantLabel = formatCatalogVariantLabel({
|
|
86
|
+
variant_name: input.variantName,
|
|
87
|
+
variant_sku: input.variantSku
|
|
88
|
+
});
|
|
89
|
+
const segments = [];
|
|
90
|
+
if (variantLabel && variantLabel !== "\u2014") segments.push(variantLabel);
|
|
91
|
+
const warehouseName = input.warehouseName?.trim();
|
|
92
|
+
if (warehouseName) segments.push(warehouseName);
|
|
93
|
+
const quantity = formatQuantity(Number(input.quantity));
|
|
94
|
+
if (quantity !== "0") segments.push(quantity);
|
|
95
|
+
return segments.length > 0 ? segments.join(" \xB7 ") : input.id;
|
|
96
|
+
}
|
|
97
|
+
function toReservationSummaryItem(reservation, warehouseNamesById, variantLabelsById) {
|
|
98
|
+
const warehouseId = extractWarehouseId(reservation);
|
|
99
|
+
const warehouseName = warehouseId ? warehouseNamesById.get(warehouseId) ?? null : null;
|
|
100
|
+
const variantMeta = variantLabelsById.get(reservation.catalogVariantId);
|
|
101
|
+
const variantName = variantMeta?.name ?? null;
|
|
102
|
+
const variantSku = variantMeta?.sku ?? null;
|
|
103
|
+
const quantity = formatQuantity(Number(reservation.quantity));
|
|
104
|
+
return {
|
|
105
|
+
id: reservation.id,
|
|
106
|
+
reservationLabel: buildReservationLabel({
|
|
107
|
+
id: reservation.id,
|
|
108
|
+
variantName,
|
|
109
|
+
variantSku,
|
|
110
|
+
warehouseName,
|
|
111
|
+
quantity
|
|
112
|
+
}),
|
|
113
|
+
catalogVariantId: reservation.catalogVariantId,
|
|
114
|
+
warehouseId,
|
|
115
|
+
warehouseName,
|
|
116
|
+
quantity,
|
|
117
|
+
variantName,
|
|
118
|
+
variantSku
|
|
119
|
+
};
|
|
120
|
+
}
|
|
76
121
|
function resolveReorderStatus(availableQuantity, profile) {
|
|
77
122
|
if (!profile) {
|
|
78
123
|
return {
|
|
@@ -100,6 +145,7 @@ function resolveReorderStatus(availableQuantity, profile) {
|
|
|
100
145
|
function buildBalanceSummaryByVariant(balances) {
|
|
101
146
|
const byVariant = /* @__PURE__ */ new Map();
|
|
102
147
|
for (const balance of balances) {
|
|
148
|
+
if (!isBalanceLocationReservable(balance)) continue;
|
|
103
149
|
const current = byVariant.get(balance.catalogVariantId) ?? {
|
|
104
150
|
onHand: 0,
|
|
105
151
|
reserved: 0,
|
|
@@ -140,6 +186,25 @@ async function isSalesOrderInventoryEnabled(context) {
|
|
|
140
186
|
return true;
|
|
141
187
|
}
|
|
142
188
|
}
|
|
189
|
+
async function loadInboundSummary(em, scope) {
|
|
190
|
+
const rows = await em.getConnection().execute(
|
|
191
|
+
`select count(*)::int as open_asn_count,
|
|
192
|
+
min(expected_at) as next_expected_at
|
|
193
|
+
from wms_asns
|
|
194
|
+
where organization_id = ?
|
|
195
|
+
and tenant_id = ?
|
|
196
|
+
and deleted_at is null
|
|
197
|
+
and status in ('draft', 'in_transit')`,
|
|
198
|
+
[scope.organizationId, scope.tenantId]
|
|
199
|
+
);
|
|
200
|
+
const row = rows[0];
|
|
201
|
+
const openAsnCount = Number(row?.open_asn_count ?? 0);
|
|
202
|
+
const nextExpected = row?.next_expected_at;
|
|
203
|
+
return {
|
|
204
|
+
openAsnCount: Number.isFinite(openAsnCount) ? openAsnCount : 0,
|
|
205
|
+
nextExpectedAt: nextExpected ? (nextExpected instanceof Date ? nextExpected : new Date(nextExpected)).toISOString() : null
|
|
206
|
+
};
|
|
207
|
+
}
|
|
143
208
|
async function loadExplicitAssignments(em, orderIds, scope) {
|
|
144
209
|
if (orderIds.length === 0) return [];
|
|
145
210
|
return findWithDecryption(
|
|
@@ -211,7 +276,8 @@ async function loadBalances(em, variantIds, scope) {
|
|
|
211
276
|
tenantId: scope.tenantId,
|
|
212
277
|
deletedAt: null
|
|
213
278
|
},
|
|
214
|
-
|
|
279
|
+
// Populate location so isBalanceLocationReservable can exclude staging/dock.
|
|
280
|
+
{ populate: ["location"] },
|
|
215
281
|
scope
|
|
216
282
|
);
|
|
217
283
|
}
|
|
@@ -229,6 +295,27 @@ async function loadCatalogVariants(context, productIds, scope) {
|
|
|
229
295
|
});
|
|
230
296
|
return result.items;
|
|
231
297
|
}
|
|
298
|
+
async function loadCatalogVariantLabelsByIds(context, variantIds, scope) {
|
|
299
|
+
if (variantIds.length === 0) return /* @__PURE__ */ new Map();
|
|
300
|
+
const container = context.container;
|
|
301
|
+
const queryEngine = container.resolve("queryEngine");
|
|
302
|
+
const result = await queryEngine.query(E.catalog.catalog_product_variant, {
|
|
303
|
+
tenantId: scope.tenantId,
|
|
304
|
+
organizationId: scope.organizationId,
|
|
305
|
+
filters: { id: { $in: variantIds } },
|
|
306
|
+
fields: ["id", "name", "sku"],
|
|
307
|
+
page: { page: 1, pageSize: Math.max(variantIds.length, 1) }
|
|
308
|
+
});
|
|
309
|
+
const labels = /* @__PURE__ */ new Map();
|
|
310
|
+
for (const row of result.items) {
|
|
311
|
+
if (typeof row.id !== "string" || row.id.length === 0) continue;
|
|
312
|
+
labels.set(row.id, {
|
|
313
|
+
name: typeof row.name === "string" ? row.name : null,
|
|
314
|
+
sku: typeof row.sku === "string" ? row.sku : null
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return labels;
|
|
318
|
+
}
|
|
232
319
|
async function loadProductInventoryProfiles(em, productIds, scope) {
|
|
233
320
|
if (productIds.length === 0) return [];
|
|
234
321
|
return findWithDecryption(
|
|
@@ -293,11 +380,12 @@ const salesOrderInventoryEnricher = {
|
|
|
293
380
|
lines.map((line) => line.product_variant_id).filter((value) => typeof value === "string" && value.length > 0)
|
|
294
381
|
)
|
|
295
382
|
);
|
|
296
|
-
const [reservations, balances, primaryWarehouseId, explicitAssignments] = await Promise.all([
|
|
383
|
+
const [reservations, balances, primaryWarehouseId, explicitAssignments, inboundSummary] = await Promise.all([
|
|
297
384
|
loadReservations(em, orderIds, scope),
|
|
298
385
|
loadBalances(em, variantIds, scope),
|
|
299
386
|
resolvePrimaryWarehouseId(em, scope),
|
|
300
|
-
loadExplicitAssignments(em, orderIds, scope)
|
|
387
|
+
loadExplicitAssignments(em, orderIds, scope),
|
|
388
|
+
loadInboundSummary(em, scope).catch(() => EMPTY_INBOUND_SUMMARY)
|
|
301
389
|
]);
|
|
302
390
|
const explicitWarehouseIdsByOrder = /* @__PURE__ */ new Map();
|
|
303
391
|
for (const assignment of explicitAssignments) {
|
|
@@ -317,14 +405,26 @@ const salesOrderInventoryEnricher = {
|
|
|
317
405
|
);
|
|
318
406
|
const warehouses = await loadWarehousesByIds(em, allRelevantWarehouseIds, scope);
|
|
319
407
|
const warehouseNamesById = new Map(warehouses.map((w) => [w.id, w.name]));
|
|
408
|
+
const activeReservationVariantIds = Array.from(
|
|
409
|
+
new Set(
|
|
410
|
+
reservations.filter((reservation) => reservation.status === "active").map((reservation) => reservation.catalogVariantId).filter((value) => typeof value === "string" && value.length > 0)
|
|
411
|
+
)
|
|
412
|
+
);
|
|
413
|
+
const variantLabelsById = await loadCatalogVariantLabelsByIds(
|
|
414
|
+
context,
|
|
415
|
+
activeReservationVariantIds,
|
|
416
|
+
scope
|
|
417
|
+
);
|
|
320
418
|
const variantAvailability = /* @__PURE__ */ new Map();
|
|
321
419
|
const variantReserved = /* @__PURE__ */ new Map();
|
|
322
420
|
for (const balance of balances) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
421
|
+
if (isBalanceLocationReservable(balance)) {
|
|
422
|
+
addToMap(
|
|
423
|
+
variantAvailability,
|
|
424
|
+
balance.catalogVariantId,
|
|
425
|
+
Number(balance.quantityOnHand) - Number(balance.quantityReserved) - Number(balance.quantityAllocated)
|
|
426
|
+
);
|
|
427
|
+
}
|
|
328
428
|
addToMap(variantReserved, balance.catalogVariantId, balance.quantityReserved);
|
|
329
429
|
}
|
|
330
430
|
const variantOrderBySalesOrder = /* @__PURE__ */ new Map();
|
|
@@ -375,6 +475,9 @@ const salesOrderInventoryEnricher = {
|
|
|
375
475
|
assignedWarehouseId = null;
|
|
376
476
|
}
|
|
377
477
|
const assignedWarehouseName = assignedWarehouseId ? warehouseNamesById.get(assignedWarehouseId) ?? null : null;
|
|
478
|
+
const reservationItems = reservationsForOrder.map(
|
|
479
|
+
(reservation) => toReservationSummaryItem(reservation, warehouseNamesById, variantLabelsById)
|
|
480
|
+
);
|
|
378
481
|
return {
|
|
379
482
|
...record,
|
|
380
483
|
_wms: {
|
|
@@ -391,8 +494,10 @@ const salesOrderInventoryEnricher = {
|
|
|
391
494
|
requiredBySalesOrder.get(orderId) ?? 0,
|
|
392
495
|
reservedBySalesOrder.get(orderId) ?? 0
|
|
393
496
|
),
|
|
394
|
-
reservationIds:
|
|
395
|
-
|
|
497
|
+
reservationIds: reservationItems.map((item) => item.id),
|
|
498
|
+
reservations: reservationItems
|
|
499
|
+
},
|
|
500
|
+
inboundSummary
|
|
396
501
|
}
|
|
397
502
|
};
|
|
398
503
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/wms/data/enrichers.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport type { ResponseEnricher, EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { FeatureTogglesService } from '@open-mercato/core/modules/feature_toggles/lib/feature-flag-check'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport { E } from '#generated/entities.ids.generated'\nimport { InventoryBalance, InventoryReservation, ProductInventoryProfile, SalesOrderWarehouseAssignment, Warehouse } from './entities'\nimport { resolvePrimaryWarehouseId } from '../lib/primaryWarehousePolicy'\nimport {\n WMS_ENRICHER_CACHE_TTL_MS,\n WMS_INVENTORY_CACHE_TAG,\n WMS_WAREHOUSE_CACHE_TAG,\n} from '../lib/enricherCacheTags'\n\ntype SalesOrderRecord = Record<string, unknown> & { id?: string }\ntype CatalogProductRecord = Record<string, unknown> & { id?: string }\ntype CatalogVariantRecord = Record<string, unknown> & { id?: string; product_id?: string; productId?: string }\n\ntype SalesOrderLineRow = {\n id?: string\n order_id?: string | null\n product_variant_id?: string | null\n quantity?: string | number | null\n line_number?: number | null\n status?: string | null\n}\n\ntype CatalogVariantRow = {\n id?: string\n product_id?: string | null\n}\ntype ReservationStatus = 'unreserved' | 'partially_reserved' | 'fully_reserved'\ntype ReorderState = 'no_profile' | 'healthy' | 'below_reorder_point' | 'below_safety_stock'\n\ntype InventoryProfileSummary = {\n profileId: string\n catalogProductId: string\n catalogVariantId: string | null\n defaultUom: string\n defaultStrategy: string\n trackLot: boolean\n trackSerial: boolean\n trackExpiration: boolean\n reorderPoint: string\n safetyStock: string\n}\n\ntype StockSummaryItem = {\n catalogVariantId: string\n onHand: string\n reserved: string\n allocated: string\n available: string\n}\n\ntype ReorderStatus = {\n state: ReorderState\n available: string\n reorderPoint: string\n safetyStock: string\n}\n\ntype SalesOrderWmsEnrichment = {\n _wms: {\n assignedWarehouseId: string | null\n assignedWarehouseName: string | null\n isExplicitlyAssigned: boolean\n stockSummary: Array<{\n catalogVariantId: string\n available: string\n reserved: string\n }>\n reservationSummary: {\n status: ReservationStatus\n reservationIds: string[]\n }\n }\n}\n\ntype CatalogWmsEnrichment = {\n _wms: {\n inventoryProfile: InventoryProfileSummary | null\n stockSummary: StockSummaryItem[]\n reorderStatus: ReorderStatus\n }\n}\n\ntype EnricherScope = EnricherContext & { em: EntityManager }\ntype Scope = { organizationId: string; tenantId: string }\ntype BalanceAggregate = { onHand: number; reserved: number; allocated: number; available: number }\n\nimport { resolveWmsIntegrationToggleEnabled } from '../lib/wmsIntegrationToggles'\nconst EMPTY_ENRICHMENT: SalesOrderWmsEnrichment = {\n _wms: {\n assignedWarehouseId: null,\n assignedWarehouseName: null,\n isExplicitlyAssigned: false,\n stockSummary: [],\n reservationSummary: {\n status: 'unreserved',\n reservationIds: [],\n },\n },\n}\n\nconst EMPTY_CATALOG_ENRICHMENT: CatalogWmsEnrichment = {\n _wms: {\n inventoryProfile: null,\n stockSummary: [],\n reorderStatus: {\n state: 'no_profile',\n available: '0',\n reorderPoint: '0',\n safetyStock: '0',\n },\n },\n}\n\nfunction extractRecordId(record: SalesOrderRecord): string | null {\n return typeof record.id === 'string' && record.id.trim().length > 0 ? record.id : null\n}\n\nfunction extractOrderIdFromLine(line: SalesOrderLineRow): string | null {\n return typeof line.order_id === 'string' && line.order_id.length > 0 ? line.order_id : null\n}\n\nfunction extractProductIdFromVariant(variant: CatalogVariantRow): string | null {\n return typeof variant.product_id === 'string' && variant.product_id.length > 0\n ? variant.product_id\n : null\n}\n\nfunction extractWarehouseId(reservation: InventoryReservation): string | null {\n const relation = reservation.warehouse as { id?: string } | undefined\n return typeof relation?.id === 'string' ? relation.id : null\n}\n\nfunction addToMap(map: Map<string, number>, key: string, value: string | number | null | undefined) {\n const numeric = typeof value === 'number' ? value : Number(value ?? 0)\n map.set(key, (map.get(key) ?? 0) + numeric)\n}\n\nfunction formatQuantity(value: number): string {\n if (!Number.isFinite(value) || value === 0) return '0'\n const normalized = value.toFixed(4).replace(/\\.?0+$/, '')\n return normalized.length > 0 ? normalized : '0'\n}\n\nfunction toInventoryProfileSummary(profile: ProductInventoryProfile): InventoryProfileSummary {\n return {\n profileId: profile.id,\n catalogProductId: profile.catalogProductId,\n catalogVariantId: profile.catalogVariantId ?? null,\n defaultUom: profile.defaultUom,\n defaultStrategy: profile.defaultStrategy,\n trackLot: profile.trackLot,\n trackSerial: profile.trackSerial,\n trackExpiration: profile.trackExpiration,\n reorderPoint: profile.reorderPoint,\n safetyStock: profile.safetyStock,\n }\n}\n\nfunction resolveReservationStatus(requiredQuantity: number, reservedQuantity: number): ReservationStatus {\n if (requiredQuantity <= 0 || reservedQuantity <= 0) return 'unreserved'\n if (reservedQuantity + 0.0001 < requiredQuantity) return 'partially_reserved'\n return 'fully_reserved'\n}\n\nfunction resolveReorderStatus(\n availableQuantity: number,\n profile: ProductInventoryProfile | null | undefined,\n): ReorderStatus {\n if (!profile) {\n return {\n state: 'no_profile',\n available: formatQuantity(availableQuantity),\n reorderPoint: '0',\n safetyStock: '0',\n }\n }\n\n const reorderPoint = Number(profile.reorderPoint)\n const safetyStock = Number(profile.safetyStock)\n let state: ReorderState = 'healthy'\n\n if (availableQuantity <= safetyStock) {\n state = 'below_safety_stock'\n } else if (availableQuantity <= reorderPoint) {\n state = 'below_reorder_point'\n }\n\n return {\n state,\n available: formatQuantity(availableQuantity),\n reorderPoint: profile.reorderPoint,\n safetyStock: profile.safetyStock,\n }\n}\n\nfunction buildBalanceSummaryByVariant(\n balances: InventoryBalance[],\n): Map<string, BalanceAggregate> {\n const byVariant = new Map<string, BalanceAggregate>()\n\n for (const balance of balances) {\n const current = byVariant.get(balance.catalogVariantId) ?? {\n onHand: 0,\n reserved: 0,\n allocated: 0,\n available: 0,\n }\n\n current.onHand += Number(balance.quantityOnHand)\n current.reserved += Number(balance.quantityReserved)\n current.allocated += Number(balance.quantityAllocated)\n current.available +=\n Number(balance.quantityOnHand) - Number(balance.quantityReserved) - Number(balance.quantityAllocated)\n\n byVariant.set(balance.catalogVariantId, current)\n }\n\n return byVariant\n}\n\nfunction buildStockSummaryItem(\n catalogVariantId: string,\n aggregate: BalanceAggregate | undefined,\n): StockSummaryItem {\n return {\n catalogVariantId,\n onHand: formatQuantity(aggregate?.onHand ?? 0),\n reserved: formatQuantity(aggregate?.reserved ?? 0),\n allocated: formatQuantity(aggregate?.allocated ?? 0),\n available: formatQuantity(aggregate?.available ?? 0),\n }\n}\n\nasync function isSalesOrderInventoryEnabled(context: EnricherContext): Promise<boolean> {\n const container = context.container as { resolve?: (name: string) => unknown } | undefined\n if (!container?.resolve) return true\n try {\n const featureTogglesService = container.resolve('featureTogglesService') as FeatureTogglesService | undefined\n const em = container.resolve('em') as EntityManager | undefined\n if (!featureTogglesService || !em) return true\n return resolveWmsIntegrationToggleEnabled(\n featureTogglesService,\n em,\n 'wms_integration_sales_order_inventory',\n context.tenantId,\n )\n } catch {\n return true\n }\n}\n\nasync function loadExplicitAssignments(\n em: EntityManager,\n orderIds: string[],\n scope: Scope,\n): Promise<SalesOrderWarehouseAssignment[]> {\n if (orderIds.length === 0) return []\n return findWithDecryption(\n em,\n SalesOrderWarehouseAssignment,\n {\n salesOrderId: { $in: orderIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadWarehousesByIds(\n em: EntityManager,\n warehouseIds: string[],\n scope: Scope,\n): Promise<Warehouse[]> {\n if (warehouseIds.length === 0) return []\n return findWithDecryption(\n em,\n Warehouse,\n {\n id: { $in: warehouseIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadOrderLines(\n context: EnricherContext,\n orderIds: string[],\n scope: Scope,\n): Promise<SalesOrderLineRow[]> {\n if (orderIds.length === 0) return []\n // Read sales order lines via QueryEngine instead of importing the sales ORM\n // entity. Keeps the WMS module decoupled from sales internals; queryEngine\n // resolves the base table via Mikro-ORM metadata.\n const container = context.container as { resolve: (name: string) => unknown }\n const queryEngine = container.resolve('queryEngine') as QueryEngine\n const result = await queryEngine.query<SalesOrderLineRow>(E.sales.sales_order_line, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n filters: { order_id: { $in: orderIds } },\n fields: ['id', 'order_id', 'product_variant_id', 'quantity', 'line_number', 'status'],\n sort: [{ field: 'line_number', dir: 'asc' as never }],\n page: { page: 1, pageSize: 5000 },\n })\n return result.items\n}\n\nasync function loadReservations(\n em: EntityManager,\n orderIds: string[],\n scope: Scope,\n): Promise<InventoryReservation[]> {\n if (orderIds.length === 0) return []\n return findWithDecryption(\n em,\n InventoryReservation,\n {\n sourceType: 'order',\n sourceId: { $in: orderIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n { orderBy: { createdAt: 'asc' } },\n scope,\n )\n}\n\nasync function loadBalances(\n em: EntityManager,\n variantIds: string[],\n scope: Scope,\n): Promise<InventoryBalance[]> {\n if (variantIds.length === 0) return []\n return findWithDecryption(\n em,\n InventoryBalance,\n {\n catalogVariantId: { $in: variantIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadCatalogVariants(\n context: EnricherContext,\n productIds: string[],\n scope: Scope,\n): Promise<CatalogVariantRow[]> {\n if (productIds.length === 0) return []\n const container = context.container as { resolve: (name: string) => unknown }\n const queryEngine = container.resolve('queryEngine') as QueryEngine\n const result = await queryEngine.query<CatalogVariantRow>(E.catalog.catalog_product_variant, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n filters: { product_id: { $in: productIds } },\n fields: ['id', 'product_id'],\n sort: [{ field: 'created_at', dir: 'asc' as never }],\n page: { page: 1, pageSize: 5000 },\n })\n return result.items\n}\n\nasync function loadProductInventoryProfiles(\n em: EntityManager,\n productIds: string[],\n scope: Scope,\n): Promise<ProductInventoryProfile[]> {\n if (productIds.length === 0) return []\n return findWithDecryption(\n em,\n ProductInventoryProfile,\n {\n catalogProductId: { $in: productIds },\n catalogVariantId: null,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadVariantInventoryProfiles(\n em: EntityManager,\n variantIds: string[],\n scope: Scope,\n): Promise<ProductInventoryProfile[]> {\n if (variantIds.length === 0) return []\n return findWithDecryption(\n em,\n ProductInventoryProfile,\n {\n catalogVariantId: { $in: variantIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nconst salesOrderInventoryEnricher: ResponseEnricher<SalesOrderRecord, SalesOrderWmsEnrichment> = {\n id: 'wms.sales-order-inventory',\n targetEntity: E.sales.sales_order,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_ENRICHMENT,\n // Reads reservations, balances, the primary warehouse and the explicit\n // assignment, so it depends on both the inventory and the warehouse tags.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG, WMS_WAREHOUSE_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<SalesOrderRecord & SalesOrderWmsEnrichment>\n const enabled = await isSalesOrderInventoryEnabled(context)\n if (!enabled) return records as Array<SalesOrderRecord & SalesOrderWmsEnrichment>\n\n const orderIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (orderIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const lines = await loadOrderLines(context, orderIds, scope)\n\n const variantIds = Array.from(\n new Set(\n lines\n .map((line) => line.product_variant_id)\n .filter((value): value is string => typeof value === 'string' && value.length > 0),\n ),\n )\n\n const [reservations, balances, primaryWarehouseId, explicitAssignments] = await Promise.all([\n loadReservations(em, orderIds, scope),\n loadBalances(em, variantIds, scope),\n resolvePrimaryWarehouseId(em, scope),\n loadExplicitAssignments(em, orderIds, scope),\n ])\n\n const explicitWarehouseIdsByOrder = new Map<string, string>()\n for (const assignment of explicitAssignments) {\n const warehouseRel = assignment.warehouse as { id?: string } | undefined\n const warehouseId = warehouseRel?.id\n if (warehouseId) {\n explicitWarehouseIdsByOrder.set(assignment.salesOrderId, warehouseId)\n }\n }\n\n const reservationWarehouseIds = reservations\n .map(extractWarehouseId)\n .filter((value): value is string => typeof value === 'string' && value.length > 0)\n const allRelevantWarehouseIds = Array.from(\n new Set([\n ...Array.from(explicitWarehouseIdsByOrder.values()),\n ...reservationWarehouseIds,\n ...(primaryWarehouseId ? [primaryWarehouseId] : []),\n ]),\n )\n const warehouses = await loadWarehousesByIds(em, allRelevantWarehouseIds, scope)\n const warehouseNamesById = new Map(warehouses.map((w) => [w.id, w.name]))\n\n const variantAvailability = new Map<string, number>()\n const variantReserved = new Map<string, number>()\n for (const balance of balances) {\n addToMap(\n variantAvailability,\n balance.catalogVariantId,\n Number(balance.quantityOnHand) - Number(balance.quantityReserved) - Number(balance.quantityAllocated),\n )\n addToMap(variantReserved, balance.catalogVariantId, balance.quantityReserved)\n }\n\n const variantOrderBySalesOrder = new Map<string, string[]>()\n const requiredBySalesOrder = new Map<string, number>()\n\n for (const line of lines) {\n const orderId = extractOrderIdFromLine(line)\n const variantId = line.product_variant_id ?? null\n if (!orderId || !variantId) continue\n\n const variantOrder = variantOrderBySalesOrder.get(orderId) ?? []\n if (!variantOrder.includes(variantId)) {\n variantOrder.push(variantId)\n variantOrderBySalesOrder.set(orderId, variantOrder)\n }\n requiredBySalesOrder.set(orderId, (requiredBySalesOrder.get(orderId) ?? 0) + Number(line.quantity))\n }\n\n const activeReservationsBySalesOrder = new Map<string, InventoryReservation[]>()\n const reservedBySalesOrder = new Map<string, number>()\n\n for (const reservation of reservations) {\n if (reservation.status !== 'active') continue\n const orderId = reservation.sourceId\n const activeReservations = activeReservationsBySalesOrder.get(orderId) ?? []\n activeReservations.push(reservation)\n activeReservationsBySalesOrder.set(orderId, activeReservations)\n reservedBySalesOrder.set(orderId, (reservedBySalesOrder.get(orderId) ?? 0) + Number(reservation.quantity))\n }\n\n return records.map((record) => {\n const orderId = extractRecordId(record)\n if (!orderId) {\n return { ...record, ...EMPTY_ENRICHMENT }\n }\n\n const reservationsForOrder = activeReservationsBySalesOrder.get(orderId) ?? []\n const warehouseIds = Array.from(\n new Set(\n reservationsForOrder\n .map(extractWarehouseId)\n .filter((value): value is string => typeof value === 'string' && value.length > 0),\n ),\n )\n const variantIdsForOrder = variantOrderBySalesOrder.get(orderId) ?? []\n\n const explicitWarehouseId = explicitWarehouseIdsByOrder.get(orderId) ?? null\n const isExplicitlyAssigned = explicitWarehouseId !== null\n\n let assignedWarehouseId: string | null\n if (isExplicitlyAssigned) {\n assignedWarehouseId = explicitWarehouseId\n } else if (warehouseIds.length === 1) {\n assignedWarehouseId = warehouseIds[0]\n } else if (warehouseIds.length === 0 && primaryWarehouseId) {\n assignedWarehouseId = primaryWarehouseId\n } else {\n assignedWarehouseId = null\n }\n\n const assignedWarehouseName = assignedWarehouseId\n ? (warehouseNamesById.get(assignedWarehouseId) ?? null)\n : null\n\n return {\n ...record,\n _wms: {\n assignedWarehouseId,\n assignedWarehouseName,\n isExplicitlyAssigned,\n stockSummary: variantIdsForOrder.map((catalogVariantId) => ({\n catalogVariantId,\n available: formatQuantity(variantAvailability.get(catalogVariantId) ?? 0),\n reserved: formatQuantity(variantReserved.get(catalogVariantId) ?? 0),\n })),\n reservationSummary: {\n status: resolveReservationStatus(\n requiredBySalesOrder.get(orderId) ?? 0,\n reservedBySalesOrder.get(orderId) ?? 0,\n ),\n reservationIds: reservationsForOrder.map((reservation) => reservation.id),\n },\n },\n }\n })\n },\n}\n\nconst catalogProductInventoryEnricher: ResponseEnricher<CatalogProductRecord, CatalogWmsEnrichment> = {\n id: 'wms.catalog-product-inventory',\n targetEntity: E.catalog.catalog_product,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_CATALOG_ENRICHMENT,\n // Reads inventory profiles and balances; also reads catalog variants, so the\n // catalog variant events invalidate the inventory tag too.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<CatalogProductRecord & CatalogWmsEnrichment>\n\n const productIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (productIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_CATALOG_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const variants = await loadCatalogVariants(context, productIds, scope)\n const variantIds = variants\n .map((variant) => variant.id)\n .filter((value): value is string => typeof value === 'string' && value.length > 0)\n const [productProfiles, balances] = await Promise.all([\n loadProductInventoryProfiles(em, productIds, scope),\n loadBalances(em, variantIds, scope),\n ])\n\n const profileByProductId = new Map(\n productProfiles.map((profile) => [profile.catalogProductId, profile] as const),\n )\n const balanceByVariantId = buildBalanceSummaryByVariant(balances)\n const variantIdsByProductId = new Map<string, string[]>()\n\n for (const variant of variants) {\n const productId = extractProductIdFromVariant(variant)\n if (!productId || typeof variant.id !== 'string') continue\n const entries = variantIdsByProductId.get(productId) ?? []\n entries.push(variant.id)\n variantIdsByProductId.set(productId, entries)\n }\n\n return records.map((record) => {\n const productId = extractRecordId(record)\n if (!productId) {\n return { ...record, ...EMPTY_CATALOG_ENRICHMENT }\n }\n\n const profile = profileByProductId.get(productId) ?? null\n const stockSummary = (variantIdsByProductId.get(productId) ?? []).map((variantId) =>\n buildStockSummaryItem(variantId, balanceByVariantId.get(variantId)),\n )\n const totalAvailable = stockSummary.reduce(\n (sum, item) => sum + Number(item.available),\n 0,\n )\n\n return {\n ...record,\n _wms: {\n inventoryProfile: profile ? toInventoryProfileSummary(profile) : null,\n stockSummary,\n reorderStatus: resolveReorderStatus(totalAvailable, profile),\n },\n }\n })\n },\n}\n\nconst catalogVariantInventoryEnricher: ResponseEnricher<CatalogVariantRecord, CatalogWmsEnrichment> = {\n id: 'wms.catalog-variant-inventory',\n targetEntity: E.catalog.catalog_product_variant,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_CATALOG_ENRICHMENT,\n // Reads inventory profiles and balances for the variant only.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<CatalogVariantRecord & CatalogWmsEnrichment>\n\n const variantIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (variantIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_CATALOG_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const [profiles, balances] = await Promise.all([\n loadVariantInventoryProfiles(em, variantIds, scope),\n loadBalances(em, variantIds, scope),\n ])\n\n const profileByVariantId = new Map(\n profiles\n .filter((profile): profile is ProductInventoryProfile & { catalogVariantId: string } => typeof profile.catalogVariantId === 'string')\n .map((profile) => [profile.catalogVariantId, profile] as const),\n )\n const balanceByVariantId = buildBalanceSummaryByVariant(balances)\n\n return records.map((record) => {\n const variantId = extractRecordId(record)\n if (!variantId) {\n return { ...record, ...EMPTY_CATALOG_ENRICHMENT }\n }\n\n const profile = profileByVariantId.get(variantId) ?? null\n const stockSummary = [buildStockSummaryItem(variantId, balanceByVariantId.get(variantId))]\n\n return {\n ...record,\n _wms: {\n inventoryProfile: profile ? toInventoryProfileSummary(profile) : null,\n stockSummary,\n reorderStatus: resolveReorderStatus(Number(stockSummary[0]?.available ?? 0), profile),\n },\n }\n })\n },\n}\n\nexport const enrichers: ResponseEnricher[] = [\n salesOrderInventoryEnricher,\n catalogProductInventoryEnricher,\n catalogVariantInventoryEnricher,\n]\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,0BAA0B;AAGnC,SAAS,SAAS;AAClB,SAAS,kBAAkB,sBAAsB,yBAAyB,+BAA+B,iBAAiB;AAC1H,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA+EP,SAAS,0CAA0C;AACnD,MAAM,mBAA4C;AAAA,EAChD,MAAM;AAAA,IACJ,qBAAqB;AAAA,IACrB,uBAAuB;AAAA,IACvB,sBAAsB;AAAA,IACtB,cAAc,CAAC;AAAA,IACf,oBAAoB;AAAA,MAClB,QAAQ;AAAA,MACR,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AACF;AAEA,MAAM,2BAAiD;AAAA,EACrD,MAAM;AAAA,IACJ,kBAAkB;AAAA,IAClB,cAAc,CAAC;AAAA,IACf,eAAe;AAAA,MACb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,QACL,GAAG;AAAA,QACH,MAAM;AAAA,UACJ,kBAAkB,UAAU,0BAA0B,OAAO,IAAI;AAAA,UACjE;AAAA,UACA,eAAe,qBAAqB,OAAO,aAAa,CAAC,GAAG,aAAa,CAAC,GAAG,OAAO;AAAA,QACtF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,YAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport type { ResponseEnricher, EnricherContext } from '@open-mercato/shared/lib/crud/response-enricher'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { FeatureTogglesService } from '@open-mercato/core/modules/feature_toggles/lib/feature-flag-check'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport { E } from '#generated/entities.ids.generated'\nimport { InventoryBalance, InventoryReservation, ProductInventoryProfile, SalesOrderWarehouseAssignment, Warehouse } from './entities'\nimport { formatCatalogVariantLabel } from '../lib/inventoryDisplayUi'\nimport { isBalanceLocationReservable } from '../lib/inventoryPolicy'\nimport { resolvePrimaryWarehouseId } from '../lib/primaryWarehousePolicy'\nimport {\n WMS_ENRICHER_CACHE_TTL_MS,\n WMS_INVENTORY_CACHE_TAG,\n WMS_WAREHOUSE_CACHE_TAG,\n} from '../lib/enricherCacheTags'\n\ntype SalesOrderRecord = Record<string, unknown> & { id?: string }\ntype CatalogProductRecord = Record<string, unknown> & { id?: string }\ntype CatalogVariantRecord = Record<string, unknown> & { id?: string; product_id?: string; productId?: string }\n\ntype SalesOrderLineRow = {\n id?: string\n order_id?: string | null\n product_variant_id?: string | null\n quantity?: string | number | null\n line_number?: number | null\n status?: string | null\n}\n\ntype CatalogVariantRow = {\n id?: string\n product_id?: string | null\n name?: string | null\n sku?: string | null\n}\n\ntype ReservationSummaryItem = {\n id: string\n reservationLabel: string\n catalogVariantId: string\n warehouseId: string | null\n warehouseName: string | null\n quantity: string\n variantName: string | null\n variantSku: string | null\n}\n\ntype ReservationStatus = 'unreserved' | 'partially_reserved' | 'fully_reserved'\ntype ReorderState = 'no_profile' | 'healthy' | 'below_reorder_point' | 'below_safety_stock'\n\ntype InventoryProfileSummary = {\n profileId: string\n catalogProductId: string\n catalogVariantId: string | null\n defaultUom: string\n defaultStrategy: string\n trackLot: boolean\n trackSerial: boolean\n trackExpiration: boolean\n reorderPoint: string\n safetyStock: string\n}\n\ntype StockSummaryItem = {\n catalogVariantId: string\n onHand: string\n reserved: string\n allocated: string\n available: string\n}\n\ntype ReorderStatus = {\n state: ReorderState\n available: string\n reorderPoint: string\n safetyStock: string\n}\n\ntype InboundSummary = {\n openAsnCount: number\n nextExpectedAt: string | null\n}\n\ntype SalesOrderWmsEnrichment = {\n _wms: {\n assignedWarehouseId: string | null\n assignedWarehouseName: string | null\n isExplicitlyAssigned: boolean\n stockSummary: Array<{\n catalogVariantId: string\n available: string\n reserved: string\n }>\n reservationSummary: {\n status: ReservationStatus\n reservationIds: string[]\n reservations: ReservationSummaryItem[]\n }\n inboundSummary: InboundSummary\n }\n}\n\ntype CatalogWmsEnrichment = {\n _wms: {\n inventoryProfile: InventoryProfileSummary | null\n stockSummary: StockSummaryItem[]\n reorderStatus: ReorderStatus\n }\n}\n\ntype EnricherScope = EnricherContext & { em: EntityManager }\ntype Scope = { organizationId: string; tenantId: string }\ntype BalanceAggregate = { onHand: number; reserved: number; allocated: number; available: number }\n\nimport { resolveWmsIntegrationToggleEnabled } from '../lib/wmsIntegrationToggles'\nconst EMPTY_INBOUND_SUMMARY: InboundSummary = {\n openAsnCount: 0,\n nextExpectedAt: null,\n}\n\nconst EMPTY_ENRICHMENT: SalesOrderWmsEnrichment = {\n _wms: {\n assignedWarehouseId: null,\n assignedWarehouseName: null,\n isExplicitlyAssigned: false,\n stockSummary: [],\n reservationSummary: {\n status: 'unreserved',\n reservationIds: [],\n reservations: [],\n },\n inboundSummary: EMPTY_INBOUND_SUMMARY,\n },\n}\n\nconst EMPTY_CATALOG_ENRICHMENT: CatalogWmsEnrichment = {\n _wms: {\n inventoryProfile: null,\n stockSummary: [],\n reorderStatus: {\n state: 'no_profile',\n available: '0',\n reorderPoint: '0',\n safetyStock: '0',\n },\n },\n}\n\nfunction extractRecordId(record: SalesOrderRecord): string | null {\n return typeof record.id === 'string' && record.id.trim().length > 0 ? record.id : null\n}\n\nfunction extractOrderIdFromLine(line: SalesOrderLineRow): string | null {\n return typeof line.order_id === 'string' && line.order_id.length > 0 ? line.order_id : null\n}\n\nfunction extractProductIdFromVariant(variant: CatalogVariantRow): string | null {\n return typeof variant.product_id === 'string' && variant.product_id.length > 0\n ? variant.product_id\n : null\n}\n\nfunction extractWarehouseId(reservation: InventoryReservation): string | null {\n const relation = reservation.warehouse as { id?: string } | undefined\n return typeof relation?.id === 'string' ? relation.id : null\n}\n\nfunction addToMap(map: Map<string, number>, key: string, value: string | number | null | undefined) {\n const numeric = typeof value === 'number' ? value : Number(value ?? 0)\n map.set(key, (map.get(key) ?? 0) + numeric)\n}\n\nfunction formatQuantity(value: number): string {\n if (!Number.isFinite(value) || value === 0) return '0'\n const normalized = value.toFixed(4).replace(/\\.?0+$/, '')\n return normalized.length > 0 ? normalized : '0'\n}\n\nfunction toInventoryProfileSummary(profile: ProductInventoryProfile): InventoryProfileSummary {\n return {\n profileId: profile.id,\n catalogProductId: profile.catalogProductId,\n catalogVariantId: profile.catalogVariantId ?? null,\n defaultUom: profile.defaultUom,\n defaultStrategy: profile.defaultStrategy,\n trackLot: profile.trackLot,\n trackSerial: profile.trackSerial,\n trackExpiration: profile.trackExpiration,\n reorderPoint: profile.reorderPoint,\n safetyStock: profile.safetyStock,\n }\n}\n\nfunction resolveReservationStatus(requiredQuantity: number, reservedQuantity: number): ReservationStatus {\n if (requiredQuantity <= 0 || reservedQuantity <= 0) return 'unreserved'\n if (reservedQuantity + 0.0001 < requiredQuantity) return 'partially_reserved'\n return 'fully_reserved'\n}\n\nfunction buildReservationLabel(input: {\n id: string\n variantName: string | null\n variantSku: string | null\n warehouseName: string | null\n quantity: string\n}): string {\n const variantLabel = formatCatalogVariantLabel({\n variant_name: input.variantName,\n variant_sku: input.variantSku,\n })\n const segments: string[] = []\n if (variantLabel && variantLabel !== '\u2014') segments.push(variantLabel)\n const warehouseName = input.warehouseName?.trim()\n if (warehouseName) segments.push(warehouseName)\n const quantity = formatQuantity(Number(input.quantity))\n if (quantity !== '0') segments.push(quantity)\n return segments.length > 0 ? segments.join(' \u00B7 ') : input.id\n}\n\nfunction toReservationSummaryItem(\n reservation: InventoryReservation,\n warehouseNamesById: Map<string, string>,\n variantLabelsById: Map<string, { name: string | null; sku: string | null }>,\n): ReservationSummaryItem {\n const warehouseId = extractWarehouseId(reservation)\n const warehouseName = warehouseId ? (warehouseNamesById.get(warehouseId) ?? null) : null\n const variantMeta = variantLabelsById.get(reservation.catalogVariantId)\n const variantName = variantMeta?.name ?? null\n const variantSku = variantMeta?.sku ?? null\n const quantity = formatQuantity(Number(reservation.quantity))\n return {\n id: reservation.id,\n reservationLabel: buildReservationLabel({\n id: reservation.id,\n variantName,\n variantSku,\n warehouseName,\n quantity,\n }),\n catalogVariantId: reservation.catalogVariantId,\n warehouseId,\n warehouseName,\n quantity,\n variantName,\n variantSku,\n }\n}\n\nfunction resolveReorderStatus(\n availableQuantity: number,\n profile: ProductInventoryProfile | null | undefined,\n): ReorderStatus {\n if (!profile) {\n return {\n state: 'no_profile',\n available: formatQuantity(availableQuantity),\n reorderPoint: '0',\n safetyStock: '0',\n }\n }\n\n const reorderPoint = Number(profile.reorderPoint)\n const safetyStock = Number(profile.safetyStock)\n let state: ReorderState = 'healthy'\n\n if (availableQuantity <= safetyStock) {\n state = 'below_safety_stock'\n } else if (availableQuantity <= reorderPoint) {\n state = 'below_reorder_point'\n }\n\n return {\n state,\n available: formatQuantity(availableQuantity),\n reorderPoint: profile.reorderPoint,\n safetyStock: profile.safetyStock,\n }\n}\n\nfunction buildBalanceSummaryByVariant(\n balances: InventoryBalance[],\n): Map<string, BalanceAggregate> {\n const byVariant = new Map<string, BalanceAggregate>()\n\n for (const balance of balances) {\n // Match reservation / sales-automation: staging/dock are inbound holding\n // and must not inflate widget \"Available\" (or sellable on-hand aggregates).\n if (!isBalanceLocationReservable(balance)) continue\n\n const current = byVariant.get(balance.catalogVariantId) ?? {\n onHand: 0,\n reserved: 0,\n allocated: 0,\n available: 0,\n }\n\n current.onHand += Number(balance.quantityOnHand)\n current.reserved += Number(balance.quantityReserved)\n current.allocated += Number(balance.quantityAllocated)\n current.available +=\n Number(balance.quantityOnHand) - Number(balance.quantityReserved) - Number(balance.quantityAllocated)\n\n byVariant.set(balance.catalogVariantId, current)\n }\n\n return byVariant\n}\n\nfunction buildStockSummaryItem(\n catalogVariantId: string,\n aggregate: BalanceAggregate | undefined,\n): StockSummaryItem {\n return {\n catalogVariantId,\n onHand: formatQuantity(aggregate?.onHand ?? 0),\n reserved: formatQuantity(aggregate?.reserved ?? 0),\n allocated: formatQuantity(aggregate?.allocated ?? 0),\n available: formatQuantity(aggregate?.available ?? 0),\n }\n}\n\nasync function isSalesOrderInventoryEnabled(context: EnricherContext): Promise<boolean> {\n const container = context.container as { resolve?: (name: string) => unknown } | undefined\n if (!container?.resolve) return true\n try {\n const featureTogglesService = container.resolve('featureTogglesService') as FeatureTogglesService | undefined\n const em = container.resolve('em') as EntityManager | undefined\n if (!featureTogglesService || !em) return true\n return resolveWmsIntegrationToggleEnabled(\n featureTogglesService,\n em,\n 'wms_integration_sales_order_inventory',\n context.tenantId,\n )\n } catch {\n return true\n }\n}\n\nasync function loadInboundSummary(em: EntityManager, scope: Scope): Promise<InboundSummary> {\n // Aggregate only \u2014 never load all open ASN rows (backlog can blow the enricher timeout).\n const rows = await em.getConnection().execute<\n Array<{ open_asn_count: string | number; next_expected_at: Date | string | null }>\n >(\n `select count(*)::int as open_asn_count,\n min(expected_at) as next_expected_at\n from wms_asns\n where organization_id = ?\n and tenant_id = ?\n and deleted_at is null\n and status in ('draft', 'in_transit')`,\n [scope.organizationId, scope.tenantId],\n )\n const row = rows[0]\n const openAsnCount = Number(row?.open_asn_count ?? 0)\n const nextExpected = row?.next_expected_at\n return {\n openAsnCount: Number.isFinite(openAsnCount) ? openAsnCount : 0,\n nextExpectedAt: nextExpected\n ? (nextExpected instanceof Date ? nextExpected : new Date(nextExpected)).toISOString()\n : null,\n }\n}\n\nasync function loadExplicitAssignments(\n em: EntityManager,\n orderIds: string[],\n scope: Scope,\n): Promise<SalesOrderWarehouseAssignment[]> {\n if (orderIds.length === 0) return []\n return findWithDecryption(\n em,\n SalesOrderWarehouseAssignment,\n {\n salesOrderId: { $in: orderIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadWarehousesByIds(\n em: EntityManager,\n warehouseIds: string[],\n scope: Scope,\n): Promise<Warehouse[]> {\n if (warehouseIds.length === 0) return []\n return findWithDecryption(\n em,\n Warehouse,\n {\n id: { $in: warehouseIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadOrderLines(\n context: EnricherContext,\n orderIds: string[],\n scope: Scope,\n): Promise<SalesOrderLineRow[]> {\n if (orderIds.length === 0) return []\n // Read sales order lines via QueryEngine instead of importing the sales ORM\n // entity. Keeps the WMS module decoupled from sales internals; queryEngine\n // resolves the base table via Mikro-ORM metadata.\n const container = context.container as { resolve: (name: string) => unknown }\n const queryEngine = container.resolve('queryEngine') as QueryEngine\n const result = await queryEngine.query<SalesOrderLineRow>(E.sales.sales_order_line, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n filters: { order_id: { $in: orderIds } },\n fields: ['id', 'order_id', 'product_variant_id', 'quantity', 'line_number', 'status'],\n sort: [{ field: 'line_number', dir: 'asc' as never }],\n page: { page: 1, pageSize: 5000 },\n })\n return result.items\n}\n\nasync function loadReservations(\n em: EntityManager,\n orderIds: string[],\n scope: Scope,\n): Promise<InventoryReservation[]> {\n if (orderIds.length === 0) return []\n return findWithDecryption(\n em,\n InventoryReservation,\n {\n sourceType: 'order',\n sourceId: { $in: orderIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n { orderBy: { createdAt: 'asc' } },\n scope,\n )\n}\n\nasync function loadBalances(\n em: EntityManager,\n variantIds: string[],\n scope: Scope,\n): Promise<InventoryBalance[]> {\n if (variantIds.length === 0) return []\n return findWithDecryption(\n em,\n InventoryBalance,\n {\n catalogVariantId: { $in: variantIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n // Populate location so isBalanceLocationReservable can exclude staging/dock.\n { populate: ['location'] },\n scope,\n )\n}\n\nasync function loadCatalogVariants(\n context: EnricherContext,\n productIds: string[],\n scope: Scope,\n): Promise<CatalogVariantRow[]> {\n if (productIds.length === 0) return []\n const container = context.container as { resolve: (name: string) => unknown }\n const queryEngine = container.resolve('queryEngine') as QueryEngine\n const result = await queryEngine.query<CatalogVariantRow>(E.catalog.catalog_product_variant, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n filters: { product_id: { $in: productIds } },\n fields: ['id', 'product_id'],\n sort: [{ field: 'created_at', dir: 'asc' as never }],\n page: { page: 1, pageSize: 5000 },\n })\n return result.items\n}\n\nasync function loadCatalogVariantLabelsByIds(\n context: EnricherContext,\n variantIds: string[],\n scope: Scope,\n): Promise<Map<string, { name: string | null; sku: string | null }>> {\n if (variantIds.length === 0) return new Map()\n const container = context.container as { resolve: (name: string) => unknown }\n const queryEngine = container.resolve('queryEngine') as QueryEngine\n const result = await queryEngine.query<CatalogVariantRow>(E.catalog.catalog_product_variant, {\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n filters: { id: { $in: variantIds } },\n fields: ['id', 'name', 'sku'],\n page: { page: 1, pageSize: Math.max(variantIds.length, 1) },\n })\n const labels = new Map<string, { name: string | null; sku: string | null }>()\n for (const row of result.items) {\n if (typeof row.id !== 'string' || row.id.length === 0) continue\n labels.set(row.id, {\n name: typeof row.name === 'string' ? row.name : null,\n sku: typeof row.sku === 'string' ? row.sku : null,\n })\n }\n return labels\n}\n\nasync function loadProductInventoryProfiles(\n em: EntityManager,\n productIds: string[],\n scope: Scope,\n): Promise<ProductInventoryProfile[]> {\n if (productIds.length === 0) return []\n return findWithDecryption(\n em,\n ProductInventoryProfile,\n {\n catalogProductId: { $in: productIds },\n catalogVariantId: null,\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nasync function loadVariantInventoryProfiles(\n em: EntityManager,\n variantIds: string[],\n scope: Scope,\n): Promise<ProductInventoryProfile[]> {\n if (variantIds.length === 0) return []\n return findWithDecryption(\n em,\n ProductInventoryProfile,\n {\n catalogVariantId: { $in: variantIds },\n organizationId: scope.organizationId,\n tenantId: scope.tenantId,\n deletedAt: null,\n },\n undefined,\n scope,\n )\n}\n\nconst salesOrderInventoryEnricher: ResponseEnricher<SalesOrderRecord, SalesOrderWmsEnrichment> = {\n id: 'wms.sales-order-inventory',\n targetEntity: E.sales.sales_order,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_ENRICHMENT,\n // Reads reservations, balances, the primary warehouse and the explicit\n // assignment, so it depends on both the inventory and the warehouse tags.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG, WMS_WAREHOUSE_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<SalesOrderRecord & SalesOrderWmsEnrichment>\n const enabled = await isSalesOrderInventoryEnabled(context)\n if (!enabled) return records as Array<SalesOrderRecord & SalesOrderWmsEnrichment>\n\n const orderIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (orderIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const lines = await loadOrderLines(context, orderIds, scope)\n\n const variantIds = Array.from(\n new Set(\n lines\n .map((line) => line.product_variant_id)\n .filter((value): value is string => typeof value === 'string' && value.length > 0),\n ),\n )\n\n // inboundSummary is best-effort (raw ASN SQL); isolate so a missing table /\n // migration lag cannot reject the whole Promise.all and drop stock/reservation.\n const [reservations, balances, primaryWarehouseId, explicitAssignments, inboundSummary] =\n await Promise.all([\n loadReservations(em, orderIds, scope),\n loadBalances(em, variantIds, scope),\n resolvePrimaryWarehouseId(em, scope),\n loadExplicitAssignments(em, orderIds, scope),\n loadInboundSummary(em, scope).catch(() => EMPTY_INBOUND_SUMMARY),\n ])\n\n const explicitWarehouseIdsByOrder = new Map<string, string>()\n for (const assignment of explicitAssignments) {\n const warehouseRel = assignment.warehouse as { id?: string } | undefined\n const warehouseId = warehouseRel?.id\n if (warehouseId) {\n explicitWarehouseIdsByOrder.set(assignment.salesOrderId, warehouseId)\n }\n }\n\n const reservationWarehouseIds = reservations\n .map(extractWarehouseId)\n .filter((value): value is string => typeof value === 'string' && value.length > 0)\n const allRelevantWarehouseIds = Array.from(\n new Set([\n ...Array.from(explicitWarehouseIdsByOrder.values()),\n ...reservationWarehouseIds,\n ...(primaryWarehouseId ? [primaryWarehouseId] : []),\n ]),\n )\n const warehouses = await loadWarehousesByIds(em, allRelevantWarehouseIds, scope)\n const warehouseNamesById = new Map(warehouses.map((w) => [w.id, w.name]))\n\n const activeReservationVariantIds = Array.from(\n new Set(\n reservations\n .filter((reservation) => reservation.status === 'active')\n .map((reservation) => reservation.catalogVariantId)\n .filter((value): value is string => typeof value === 'string' && value.length > 0),\n ),\n )\n const variantLabelsById = await loadCatalogVariantLabelsByIds(\n context,\n activeReservationVariantIds,\n scope,\n )\n\n const variantAvailability = new Map<string, number>()\n const variantReserved = new Map<string, number>()\n for (const balance of balances) {\n // Staging/dock must not count toward Available (same rule as reserve path).\n if (isBalanceLocationReservable(balance)) {\n addToMap(\n variantAvailability,\n balance.catalogVariantId,\n Number(balance.quantityOnHand) - Number(balance.quantityReserved) - Number(balance.quantityAllocated),\n )\n }\n addToMap(variantReserved, balance.catalogVariantId, balance.quantityReserved)\n }\n\n const variantOrderBySalesOrder = new Map<string, string[]>()\n const requiredBySalesOrder = new Map<string, number>()\n\n for (const line of lines) {\n const orderId = extractOrderIdFromLine(line)\n const variantId = line.product_variant_id ?? null\n if (!orderId || !variantId) continue\n\n const variantOrder = variantOrderBySalesOrder.get(orderId) ?? []\n if (!variantOrder.includes(variantId)) {\n variantOrder.push(variantId)\n variantOrderBySalesOrder.set(orderId, variantOrder)\n }\n requiredBySalesOrder.set(orderId, (requiredBySalesOrder.get(orderId) ?? 0) + Number(line.quantity))\n }\n\n const activeReservationsBySalesOrder = new Map<string, InventoryReservation[]>()\n const reservedBySalesOrder = new Map<string, number>()\n\n for (const reservation of reservations) {\n if (reservation.status !== 'active') continue\n const orderId = reservation.sourceId\n const activeReservations = activeReservationsBySalesOrder.get(orderId) ?? []\n activeReservations.push(reservation)\n activeReservationsBySalesOrder.set(orderId, activeReservations)\n reservedBySalesOrder.set(orderId, (reservedBySalesOrder.get(orderId) ?? 0) + Number(reservation.quantity))\n }\n\n return records.map((record) => {\n const orderId = extractRecordId(record)\n if (!orderId) {\n return { ...record, ...EMPTY_ENRICHMENT }\n }\n\n const reservationsForOrder = activeReservationsBySalesOrder.get(orderId) ?? []\n const warehouseIds = Array.from(\n new Set(\n reservationsForOrder\n .map(extractWarehouseId)\n .filter((value): value is string => typeof value === 'string' && value.length > 0),\n ),\n )\n const variantIdsForOrder = variantOrderBySalesOrder.get(orderId) ?? []\n\n const explicitWarehouseId = explicitWarehouseIdsByOrder.get(orderId) ?? null\n const isExplicitlyAssigned = explicitWarehouseId !== null\n\n let assignedWarehouseId: string | null\n if (isExplicitlyAssigned) {\n assignedWarehouseId = explicitWarehouseId\n } else if (warehouseIds.length === 1) {\n assignedWarehouseId = warehouseIds[0]\n } else if (warehouseIds.length === 0 && primaryWarehouseId) {\n assignedWarehouseId = primaryWarehouseId\n } else {\n assignedWarehouseId = null\n }\n\n const assignedWarehouseName = assignedWarehouseId\n ? (warehouseNamesById.get(assignedWarehouseId) ?? null)\n : null\n\n const reservationItems = reservationsForOrder.map((reservation) =>\n toReservationSummaryItem(reservation, warehouseNamesById, variantLabelsById),\n )\n\n return {\n ...record,\n _wms: {\n assignedWarehouseId,\n assignedWarehouseName,\n isExplicitlyAssigned,\n stockSummary: variantIdsForOrder.map((catalogVariantId) => ({\n catalogVariantId,\n available: formatQuantity(variantAvailability.get(catalogVariantId) ?? 0),\n reserved: formatQuantity(variantReserved.get(catalogVariantId) ?? 0),\n })),\n reservationSummary: {\n status: resolveReservationStatus(\n requiredBySalesOrder.get(orderId) ?? 0,\n reservedBySalesOrder.get(orderId) ?? 0,\n ),\n reservationIds: reservationItems.map((item) => item.id),\n reservations: reservationItems,\n },\n inboundSummary,\n },\n }\n })\n },\n}\n\nconst catalogProductInventoryEnricher: ResponseEnricher<CatalogProductRecord, CatalogWmsEnrichment> = {\n id: 'wms.catalog-product-inventory',\n targetEntity: E.catalog.catalog_product,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_CATALOG_ENRICHMENT,\n // Reads inventory profiles and balances; also reads catalog variants, so the\n // catalog variant events invalidate the inventory tag too.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<CatalogProductRecord & CatalogWmsEnrichment>\n\n const productIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (productIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_CATALOG_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const variants = await loadCatalogVariants(context, productIds, scope)\n const variantIds = variants\n .map((variant) => variant.id)\n .filter((value): value is string => typeof value === 'string' && value.length > 0)\n const [productProfiles, balances] = await Promise.all([\n loadProductInventoryProfiles(em, productIds, scope),\n loadBalances(em, variantIds, scope),\n ])\n\n const profileByProductId = new Map(\n productProfiles.map((profile) => [profile.catalogProductId, profile] as const),\n )\n const balanceByVariantId = buildBalanceSummaryByVariant(balances)\n const variantIdsByProductId = new Map<string, string[]>()\n\n for (const variant of variants) {\n const productId = extractProductIdFromVariant(variant)\n if (!productId || typeof variant.id !== 'string') continue\n const entries = variantIdsByProductId.get(productId) ?? []\n entries.push(variant.id)\n variantIdsByProductId.set(productId, entries)\n }\n\n return records.map((record) => {\n const productId = extractRecordId(record)\n if (!productId) {\n return { ...record, ...EMPTY_CATALOG_ENRICHMENT }\n }\n\n const profile = profileByProductId.get(productId) ?? null\n const stockSummary = (variantIdsByProductId.get(productId) ?? []).map((variantId) =>\n buildStockSummaryItem(variantId, balanceByVariantId.get(variantId)),\n )\n const totalAvailable = stockSummary.reduce(\n (sum, item) => sum + Number(item.available),\n 0,\n )\n\n return {\n ...record,\n _wms: {\n inventoryProfile: profile ? toInventoryProfileSummary(profile) : null,\n stockSummary,\n reorderStatus: resolveReorderStatus(totalAvailable, profile),\n },\n }\n })\n },\n}\n\nconst catalogVariantInventoryEnricher: ResponseEnricher<CatalogVariantRecord, CatalogWmsEnrichment> = {\n id: 'wms.catalog-variant-inventory',\n targetEntity: E.catalog.catalog_product_variant,\n features: ['wms.view'],\n priority: 40,\n timeout: 2000,\n fallback: EMPTY_CATALOG_ENRICHMENT,\n // Reads inventory profiles and balances for the variant only.\n cache: {\n strategy: 'read-through',\n ttl: WMS_ENRICHER_CACHE_TTL_MS,\n tags: [WMS_INVENTORY_CACHE_TAG],\n },\n\n async enrichOne(record, context: EnricherScope) {\n return (await this.enrichMany!([record], context))[0]\n },\n\n async enrichMany(records, context: EnricherScope) {\n if (records.length === 0) return records as Array<CatalogVariantRecord & CatalogWmsEnrichment>\n\n const variantIds = records\n .map(extractRecordId)\n .filter((value): value is string => Boolean(value))\n\n if (variantIds.length === 0) {\n return records.map((record) => ({ ...record, ...EMPTY_CATALOG_ENRICHMENT }))\n }\n\n const em = context.em.fork()\n const scope = { organizationId: context.organizationId, tenantId: context.tenantId }\n\n const [profiles, balances] = await Promise.all([\n loadVariantInventoryProfiles(em, variantIds, scope),\n loadBalances(em, variantIds, scope),\n ])\n\n const profileByVariantId = new Map(\n profiles\n .filter((profile): profile is ProductInventoryProfile & { catalogVariantId: string } => typeof profile.catalogVariantId === 'string')\n .map((profile) => [profile.catalogVariantId, profile] as const),\n )\n const balanceByVariantId = buildBalanceSummaryByVariant(balances)\n\n return records.map((record) => {\n const variantId = extractRecordId(record)\n if (!variantId) {\n return { ...record, ...EMPTY_CATALOG_ENRICHMENT }\n }\n\n const profile = profileByVariantId.get(variantId) ?? null\n const stockSummary = [buildStockSummaryItem(variantId, balanceByVariantId.get(variantId))]\n\n return {\n ...record,\n _wms: {\n inventoryProfile: profile ? toInventoryProfileSummary(profile) : null,\n stockSummary,\n reorderStatus: resolveReorderStatus(Number(stockSummary[0]?.available ?? 0), profile),\n },\n }\n })\n },\n}\n\nexport const enrichers: ResponseEnricher[] = [\n salesOrderInventoryEnricher,\n catalogProductInventoryEnricher,\n catalogVariantInventoryEnricher,\n]\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,0BAA0B;AAGnC,SAAS,SAAS;AAClB,SAAS,kBAAkB,sBAAsB,yBAAyB,+BAA+B,iBAAiB;AAC1H,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAoGP,SAAS,0CAA0C;AACnD,MAAM,wBAAwC;AAAA,EAC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K,QAAQ,GAAG,KAAK;AAC3B,UAAM,QAAQ,EAAE,gBAAgB,QAAQ,gBAAgB,UAAU,QAAQ,SAAS;AAEnF,UAAM,CAAC,UAAU,QAAQ,IAAI,MAAM,QAAQ,IAAI;AAAA,MAC7C,6BAA6B,IAAI,YAAY,KAAK;AAAA,MAClD,aAAa,IAAI,YAAY,KAAK;AAAA,IACpC,CAAC;AAED,UAAM,qBAAqB,IAAI;AAAA,MAC7B,SACG,OAAO,CAAC,YAA+E,OAAO,QAAQ,qBAAqB,QAAQ,EACnI,IAAI,CAAC,YAAY,CAAC,QAAQ,kBAAkB,OAAO,CAAU;AAAA,IAClE;AACA,UAAM,qBAAqB,6BAA6B,QAAQ;AAEhE,WAAO,QAAQ,IAAI,CAAC,WAAW;AAC7B,YAAM,YAAY,gBAAgB,MAAM;AACxC,UAAI,CAAC,WAAW;AACd,eAAO,EAAE,GAAG,QAAQ,GAAG,yBAAyB;AAAA,MAClD;AAEA,YAAM,UAAU,mBAAmB,IAAI,SAAS,KAAK;AACrD,YAAM,eAAe,CAAC,sBAAsB,WAAW,mBAAmB,IAAI,SAAS,CAAC,CAAC;AAEzF,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,UACJ,kBAAkB,UAAU,0BAA0B,OAAO,IAAI;AAAA,UACjE;AAAA,UACA,eAAe,qBAAqB,OAAO,aAAa,CAAC,GAAG,aAAa,CAAC,GAAG,OAAO;AAAA,QACtF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,YAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,7 +8,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
8
8
|
if (kind && result) __defProp(target, key, result);
|
|
9
9
|
return result;
|
|
10
10
|
};
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
12
12
|
import { Collection, OptionalProps } from "@mikro-orm/core";
|
|
13
13
|
import {
|
|
14
14
|
Entity,
|
|
@@ -453,12 +453,161 @@ InventoryMovement = __decorateClass([
|
|
|
453
453
|
expression: 'create unique index "wms_inventory_movements_idempotency_unique_idx" on "wms_inventory_movements" ("organization_id", "idempotency_key") where idempotency_key is not null and deleted_at is null'
|
|
454
454
|
})
|
|
455
455
|
], InventoryMovement);
|
|
456
|
+
let Asn = class extends (_j = WmsScopedEntity, OptionalProps, _j) {
|
|
457
|
+
constructor() {
|
|
458
|
+
super(...arguments);
|
|
459
|
+
this.status = "draft";
|
|
460
|
+
this.lines = new Collection(this);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
__decorateClass([
|
|
464
|
+
ManyToOne(() => Warehouse, { fieldName: "warehouse_id" })
|
|
465
|
+
], Asn.prototype, "warehouse", 2);
|
|
466
|
+
__decorateClass([
|
|
467
|
+
Property({ name: "vendor_id", type: "uuid", nullable: true })
|
|
468
|
+
], Asn.prototype, "vendorId", 2);
|
|
469
|
+
__decorateClass([
|
|
470
|
+
Property({ type: "text", default: "draft" })
|
|
471
|
+
], Asn.prototype, "status", 2);
|
|
472
|
+
__decorateClass([
|
|
473
|
+
Property({ name: "expected_at", type: Date })
|
|
474
|
+
], Asn.prototype, "expectedAt", 2);
|
|
475
|
+
__decorateClass([
|
|
476
|
+
Property({ name: "reference_number", type: "text", nullable: true })
|
|
477
|
+
], Asn.prototype, "referenceNumber", 2);
|
|
478
|
+
__decorateClass([
|
|
479
|
+
Property({ name: "source_key", type: "text", nullable: true })
|
|
480
|
+
], Asn.prototype, "sourceKey", 2);
|
|
481
|
+
__decorateClass([
|
|
482
|
+
Property({ type: "text", nullable: true })
|
|
483
|
+
], Asn.prototype, "notes", 2);
|
|
484
|
+
__decorateClass([
|
|
485
|
+
OneToMany(() => ReceivingLine, (line) => line.asn)
|
|
486
|
+
], Asn.prototype, "lines", 2);
|
|
487
|
+
Asn = __decorateClass([
|
|
488
|
+
Entity({ tableName: "wms_asns" }),
|
|
489
|
+
Index({ name: "wms_asns_org_tenant_idx", properties: ["organizationId", "tenantId"] }),
|
|
490
|
+
Index({
|
|
491
|
+
name: "wms_asns_org_warehouse_status_expected_idx",
|
|
492
|
+
properties: ["organizationId", "warehouse", "status", "expectedAt"]
|
|
493
|
+
}),
|
|
494
|
+
Index({
|
|
495
|
+
name: "wms_asns_org_vendor_expected_idx",
|
|
496
|
+
expression: 'create index "wms_asns_org_vendor_expected_idx" on "wms_asns" ("organization_id", "vendor_id", "expected_at" desc) where deleted_at is null'
|
|
497
|
+
}),
|
|
498
|
+
Index({
|
|
499
|
+
name: "wms_asns_org_source_key_unique_idx",
|
|
500
|
+
expression: 'create unique index "wms_asns_org_source_key_unique_idx" on "wms_asns" ("organization_id", "source_key") where source_key is not null and deleted_at is null'
|
|
501
|
+
})
|
|
502
|
+
], Asn);
|
|
503
|
+
let ReceivingLine = class extends (_k = WmsScopedEntity, OptionalProps, _k) {
|
|
504
|
+
constructor() {
|
|
505
|
+
super(...arguments);
|
|
506
|
+
this.receivedQty = "0";
|
|
507
|
+
this.qcStatus = "pending";
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
__decorateClass([
|
|
511
|
+
ManyToOne(() => Asn, { fieldName: "asn_id" })
|
|
512
|
+
], ReceivingLine.prototype, "asn", 2);
|
|
513
|
+
__decorateClass([
|
|
514
|
+
Property({ name: "catalog_variant_id", type: "uuid" })
|
|
515
|
+
], ReceivingLine.prototype, "catalogVariantId", 2);
|
|
516
|
+
__decorateClass([
|
|
517
|
+
Property({ name: "expected_qty", type: "numeric", precision: 16, scale: 4 })
|
|
518
|
+
], ReceivingLine.prototype, "expectedQty", 2);
|
|
519
|
+
__decorateClass([
|
|
520
|
+
Property({ name: "received_qty", type: "numeric", precision: 16, scale: 4, default: "0" })
|
|
521
|
+
], ReceivingLine.prototype, "receivedQty", 2);
|
|
522
|
+
__decorateClass([
|
|
523
|
+
Property({ name: "lot_number", type: "text", nullable: true })
|
|
524
|
+
], ReceivingLine.prototype, "lotNumber", 2);
|
|
525
|
+
__decorateClass([
|
|
526
|
+
Property({ name: "serial_numbers", type: "jsonb", nullable: true })
|
|
527
|
+
], ReceivingLine.prototype, "serialNumbers", 2);
|
|
528
|
+
__decorateClass([
|
|
529
|
+
Property({ name: "qc_status", type: "text", default: "pending" })
|
|
530
|
+
], ReceivingLine.prototype, "qcStatus", 2);
|
|
531
|
+
__decorateClass([
|
|
532
|
+
Property({ name: "target_staging_location_id", type: "uuid", nullable: true })
|
|
533
|
+
], ReceivingLine.prototype, "targetStagingLocationId", 2);
|
|
534
|
+
__decorateClass([
|
|
535
|
+
Property({ name: "rejection_reason", type: "text", nullable: true })
|
|
536
|
+
], ReceivingLine.prototype, "rejectionReason", 2);
|
|
537
|
+
ReceivingLine = __decorateClass([
|
|
538
|
+
Entity({ tableName: "wms_receiving_lines" }),
|
|
539
|
+
Index({ name: "wms_receiving_lines_org_tenant_idx", properties: ["organizationId", "tenantId"] }),
|
|
540
|
+
Index({ name: "wms_receiving_lines_org_asn_idx", properties: ["organizationId", "asn"] }),
|
|
541
|
+
Index({
|
|
542
|
+
name: "wms_receiving_lines_org_variant_qc_idx",
|
|
543
|
+
properties: ["organizationId", "catalogVariantId", "qcStatus"]
|
|
544
|
+
})
|
|
545
|
+
], ReceivingLine);
|
|
546
|
+
let PutawayTask = class extends (_l = WmsScopedEntity, OptionalProps, _l) {
|
|
547
|
+
constructor() {
|
|
548
|
+
super(...arguments);
|
|
549
|
+
this.status = "open";
|
|
550
|
+
this.priority = 5;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
__decorateClass([
|
|
554
|
+
ManyToOne(() => Warehouse, { fieldName: "warehouse_id" })
|
|
555
|
+
], PutawayTask.prototype, "warehouse", 2);
|
|
556
|
+
__decorateClass([
|
|
557
|
+
Property({ name: "source_location_id", type: "uuid" })
|
|
558
|
+
], PutawayTask.prototype, "sourceLocationId", 2);
|
|
559
|
+
__decorateClass([
|
|
560
|
+
Property({ name: "target_location_id", type: "uuid", nullable: true })
|
|
561
|
+
], PutawayTask.prototype, "targetLocationId", 2);
|
|
562
|
+
__decorateClass([
|
|
563
|
+
Property({ name: "catalog_variant_id", type: "uuid" })
|
|
564
|
+
], PutawayTask.prototype, "catalogVariantId", 2);
|
|
565
|
+
__decorateClass([
|
|
566
|
+
Property({ name: "lot_id", type: "uuid", nullable: true })
|
|
567
|
+
], PutawayTask.prototype, "lotId", 2);
|
|
568
|
+
__decorateClass([
|
|
569
|
+
Property({ name: "serial_number", type: "text", nullable: true })
|
|
570
|
+
], PutawayTask.prototype, "serialNumber", 2);
|
|
571
|
+
__decorateClass([
|
|
572
|
+
Property({ type: "numeric", precision: 16, scale: 4 })
|
|
573
|
+
], PutawayTask.prototype, "quantity", 2);
|
|
574
|
+
__decorateClass([
|
|
575
|
+
Property({ type: "text", default: "open" })
|
|
576
|
+
], PutawayTask.prototype, "status", 2);
|
|
577
|
+
__decorateClass([
|
|
578
|
+
Property({ name: "assigned_to", type: "uuid", nullable: true })
|
|
579
|
+
], PutawayTask.prototype, "assignedTo", 2);
|
|
580
|
+
__decorateClass([
|
|
581
|
+
Property({ type: "integer", default: 5 })
|
|
582
|
+
], PutawayTask.prototype, "priority", 2);
|
|
583
|
+
__decorateClass([
|
|
584
|
+
Property({ name: "putaway_key", type: "text", nullable: true })
|
|
585
|
+
], PutawayTask.prototype, "putawayKey", 2);
|
|
586
|
+
PutawayTask = __decorateClass([
|
|
587
|
+
Entity({ tableName: "wms_putaway_tasks" }),
|
|
588
|
+
Index({ name: "wms_putaway_tasks_org_tenant_idx", properties: ["organizationId", "tenantId"] }),
|
|
589
|
+
Index({
|
|
590
|
+
name: "wms_putaway_tasks_org_warehouse_status_priority_idx",
|
|
591
|
+
properties: ["organizationId", "warehouse", "status", "priority"]
|
|
592
|
+
}),
|
|
593
|
+
Index({
|
|
594
|
+
name: "wms_putaway_tasks_org_assigned_status_idx",
|
|
595
|
+
properties: ["organizationId", "assignedTo", "status"]
|
|
596
|
+
}),
|
|
597
|
+
Index({
|
|
598
|
+
name: "wms_putaway_tasks_org_putaway_key_unique_idx",
|
|
599
|
+
expression: `create unique index "wms_putaway_tasks_org_putaway_key_unique_idx" on "wms_putaway_tasks" ("organization_id", "putaway_key") where putaway_key is not null and deleted_at is null and status <> 'cancelled'`
|
|
600
|
+
})
|
|
601
|
+
], PutawayTask);
|
|
456
602
|
export {
|
|
603
|
+
Asn,
|
|
457
604
|
InventoryBalance,
|
|
458
605
|
InventoryLot,
|
|
459
606
|
InventoryMovement,
|
|
460
607
|
InventoryReservation,
|
|
461
608
|
ProductInventoryProfile,
|
|
609
|
+
PutawayTask,
|
|
610
|
+
ReceivingLine,
|
|
462
611
|
SalesOrderWarehouseAssignment,
|
|
463
612
|
Warehouse,
|
|
464
613
|
WarehouseLocation,
|