Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Show a transfer's own movements, not its warehouse's

Łukasz Adamczyk86a21e91f13e
diff --git a/packages/dashboard/src/components/spree/stock-history-card.tsx b/packages/dashboard/src/components/spree/stock-history-card.tsx
index 0e896073f2..9379a6bbb1 100644
--- a/packages/dashboard/src/components/spree/stock-history-card.tsx
+++ b/packages/dashboard/src/components/spree/stock-history-card.tsx
@@ -22,38 +22,55 @@ import { useTranslation } from 'react-i18next'
/**
* Why the on-hand number is what it is.
*
- * Movement history is only ever read in the context of a variant or a
- * warehouse — "why is this SKU 47?" and "what changed in Brooklyn this week?"
- * are the questions merchants actually ask, and the legacy admin's
- * undifferentiated firehose answered neither
- * (docs/plans/6.0-inventory-operations.md). So this is a panel, never a page.
+ * Movement history is only ever read about something — a SKU ("why is this 47?"),
+ * a warehouse ("what changed in Brooklyn this week?"), or one document ("what
+ * did this trip actually move?"). The legacy admin's undifferentiated firehose
+ * answered none of them (docs/plans/6.0-inventory-operations.md), so this is a
+ * panel, never a page, and it takes exactly one subject.
*/
export function StockHistoryCard({
variantIds,
stockLocationId,
+ stockTransferId,
+ purchaseOrderId,
title,
}: {
/** One SKU's history, or a product's across all of its variants. */
variantIds?: string[]
stockLocationId?: string | null
+ /** One trip's own rows — its departure and its arrivals, across both ends. */
+ stockTransferId?: string | null
+ /** One order's own rows: every delivery counted in against it. */
+ purchaseOrderId?: string | null
title?: string
}) {
const { t } = useTranslation()
const [page, setPage] = useState(1)
- // Movements carry no variant or location of their own — they hang off a
- // stock level, which is the (variant, warehouse) pair — so both filters
- // reach through it.
- const filter = variantIds
- ? { stock_level_variant_id_in: variantIds }
- : { stock_level_stock_location_id_eq: stockLocationId }
-
- const scopeKey = variantIds ? variantIds.join(',') : (stockLocationId ?? '')
+ // A movement carries no variant or warehouse of its own — it hangs off a
+ // stock level, which is the (variant, warehouse) pair — so those two filters
+ // reach through it. A document's id sits on the movement directly, which is
+ // what lets a transfer show both ends of its own trip: the departure is
+ // recorded against the source's shelf and the arrivals against the
+ // destination's, so a warehouse scope could only ever show half of it.
+ const scope = [
+ variantIds?.length
+ ? { key: variantIds.join(','), stock_level_variant_id_in: variantIds }
+ : null,
+ stockTransferId ? { key: stockTransferId, stock_transfer_id_eq: stockTransferId } : null,
+ purchaseOrderId ? { key: purchaseOrderId, purchase_order_id_eq: purchaseOrderId } : null,
+ stockLocationId
+ ? { key: stockLocationId, stock_level_stock_location_id_eq: stockLocationId }
+ : null,
+ ].find((candidate) => candidate !== null)
const { data, isLoading } = useQuery({
- queryKey: useResourceKey('stock-movements', `${scopeKey}-${page}`),
- queryFn: () => adminClient.stockMovements.list({ page, limit: 10, ...filter }),
- enabled: variantIds ? variantIds.length > 0 : !!stockLocationId,
+ queryKey: useResourceKey('stock-movements', `${scope?.key ?? ''}-${page}`),
+ queryFn: () => {
+ const { key: _key, ...filter } = scope ?? {}
+ return adminClient.stockMovements.list({ page, limit: 10, ...filter })
+ },
+ enabled: !!scope,
})
const movements = data?.data ?? []
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index e1dca3b1b8..160043102b 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -5109,7 +5109,7 @@
"items_title": "البنود",
"items_empty": "لا توجد بنود بعد — أضف منتجًا لإرساله.",
"receive_title": "الاستلام",
- "history_title": "الحركة في المستودع المستقبِل",
+ "history_title": "حركات المخزون لهذا النقل",
"units_summary": "تم استلام {{received}} من {{shipped}} وحدة مُرسَلة",
"receive_running_total": "تم عدّ {{counted}} من {{shipped}} وحدة مُرسَلة",
"discrepancy_placeholder": "سبب نقص الكمية الواصلة",
@@ -5488,7 +5488,7 @@
"items_title": "البنود",
"items_empty": "لا توجد بنود بعد — أضف منتجًا لطلبه.",
"receive_title": "الاستلام",
- "history_title": "الحركة في المستودع المستقبِل",
+ "history_title": "حركات المخزون لأمر الشراء هذا",
"units_summary": "تم استلام {{received}} من {{ordered}} وحدة مطلوبة",
"receive_running_total": "تم عدّ {{counted}} من {{ordered}} وحدة مطلوبة",
"table": {
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index e562ac551a..91fb4516a1 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -5087,7 +5087,7 @@
"items_title": "Positionen",
"items_empty": "Noch keine Positionen – fügen Sie ein Produkt hinzu.",
"receive_title": "Wareneingang",
- "history_title": "Bewegungen im Ziellager",
+ "history_title": "Bestandsbewegungen dieser Umbuchung",
"units_summary": "{{received}} von {{shipped}} versandten Einheiten eingegangen",
"receive_running_total": "{{counted}} von {{shipped}} versandten Einheiten gezählt",
"discrepancy_placeholder": "Warum weniger eingetroffen ist",
@@ -5459,7 +5459,7 @@
"items_title": "Positionen",
"items_empty": "Noch keine Positionen – fügen Sie ein Produkt hinzu.",
"receive_title": "Wareneingang",
- "history_title": "Bewegungen im Ziellager",
+ "history_title": "Bestandsbewegungen dieser Bestellung",
"units_summary": "{{received}} von {{ordered}} bestellten Einheiten eingegangen",
"receive_running_total": "{{counted}} von {{ordered}} bestellten Einheiten gezählt",
"table": {
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index fc5a30b9c4..955aeb00b1 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -5087,7 +5087,7 @@
"items_title": "Items",
"items_empty": "No items yet — add a product to send.",
"receive_title": "Receive",
- "history_title": "Activity at the destination",
+ "history_title": "Stock movements for this transfer",
"units_summary": "{{received}} received of {{shipped}} shipped",
"receive_running_total": "{{counted}} counted of {{shipped}} shipped",
"discrepancy_placeholder": "Why fewer arrived",
@@ -5459,7 +5459,7 @@
"items_title": "Items",
"items_empty": "No items yet — add a product to order.",
"receive_title": "Receive",
- "history_title": "Activity at the destination",
+ "history_title": "Stock movements for this order",
"units_summary": "{{received}} received of {{ordered}} ordered",
"receive_running_total": "{{counted}} counted of {{ordered}} ordered",
"table": {
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 3db4a63cab..c5e0714808 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -5087,7 +5087,7 @@
"items_title": "Articles",
"items_empty": "Aucun article — ajoutez un produit à envoyer.",
"receive_title": "Réception",
- "history_title": "Activité à destination",
+ "history_title": "Mouvements de stock de ce transfert",
"units_summary": "{{received}} reçues sur {{shipped}} expédiées",
"receive_running_total": "{{counted}} comptées sur {{shipped}} expédiées",
"discrepancy_placeholder": "Pourquoi il en manque",
@@ -5459,7 +5459,7 @@
"items_title": "Articles",
"items_empty": "Aucun article — ajoutez un produit à commander.",
"receive_title": "Réception",
- "history_title": "Activité à destination",
+ "history_title": "Mouvements de stock de ce bon de commande",
"units_summary": "{{received}} reçues sur {{ordered}} commandées",
"receive_running_total": "{{counted}} comptées sur {{ordered}} commandées",
"table": {
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 7c5b898d10..a53081d124 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -5145,7 +5145,7 @@
"items_title": "Pozycje",
"items_empty": "Brak pozycji — dodaj produkt do wysłania.",
"receive_title": "Przyjęcie",
- "history_title": "Ruchy w magazynie docelowym",
+ "history_title": "Ruchy magazynowe tego transferu",
"units_summary": "przyjęto {{received}} z {{shipped}} wysłanych",
"receive_running_total": "policzono {{counted}} z {{shipped}} wysłanych",
"discrepancy_placeholder": "Dlaczego dotarło mniej",
@@ -5521,7 +5521,7 @@
"items_title": "Pozycje",
"items_empty": "Brak pozycji — dodaj produkt do zamówienia.",
"receive_title": "Przyjęcie",
- "history_title": "Ruchy w magazynie docelowym",
+ "history_title": "Ruchy magazynowe tego zamówienia",
"units_summary": "przyjęto {{received}} z {{ordered}} zamówionych",
"receive_running_total": "policzono {{counted}} z {{ordered}} zamówionych",
"table": {
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 37552dd317..db3377b2e3 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -5078,7 +5078,7 @@
"items_title": "明细",
"items_empty": "暂无明细 — 请添加要发出的商品。",
"receive_title": "收货",
- "history_title": "目标仓库的变动",
+ "history_title": "此调拨的库存变动",
"units_summary": "已发出 {{shipped}} 件,已收到 {{received}} 件",
"receive_running_total": "已发出 {{shipped}} 件,已清点 {{counted}} 件",
"discrepancy_placeholder": "为何到货变少",
@@ -5448,7 +5448,7 @@
"items_title": "明细",
"items_empty": "暂无明细 — 请添加要订购的商品。",
"receive_title": "收货",
- "history_title": "目标仓库的变动",
+ "history_title": "此采购订单的库存变动",
"units_summary": "已订购 {{ordered}} 件,已收到 {{received}} 件",
"receive_running_total": "已订购 {{ordered}} 件,已清点 {{counted}} 件",
"table": {
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx
index cf769abb88..1e4ced2c3f 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId.tsx
@@ -55,7 +55,7 @@ function PurchaseOrderDetailPage() {
<ItemsCard purchaseOrder={purchaseOrder} />
<StockHistoryCard
- stockLocationId={purchaseOrder.destination_location_id}
+ purchaseOrderId={purchaseOrder.id}
title={t('admin.purchase_orders.history_title')}
/>
</div>
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx
index a3605717eb..d84f47f6a7 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx
@@ -71,7 +71,7 @@ function StockTransferDetailPage() {
destination warehouse, which is the shelf the merchant is
reconciling. */}
<StockHistoryCard
- stockLocationId={transfer.destination_location_id}
+ stockTransferId={transfer.id}
title={t('admin.stock_transfers.history_title')}
/>
</div>