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.

Say which shelf a stock movement happened on

Łukasz Adamczyk0b9661e124af
diff --git a/packages/admin-sdk/src/types/generated/StockMovement.ts b/packages/admin-sdk/src/types/generated/StockMovement.ts
index d41221fb79..a674d1d530 100644
--- a/packages/admin-sdk/src/types/generated/StockMovement.ts
+++ b/packages/admin-sdk/src/types/generated/StockMovement.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 11f40ca93a3e53f1ff13e7a160c567c3
+// Typelizer digest 88e96495001b08912702f1c8d8e0e7f1
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -10,6 +10,11 @@ interface StockMovement {
created_at: string;
updated_at: string;
stock_level_id: string | null;
+ stock_location_id: string | null;
+ stock_location_name: string | null;
+ variant_id: string | null;
+ variant_name: string | null;
+ variant_sku: string | null;
order_id: string | null;
fulfillment_id: string | null;
return_id: string | null;
diff --git a/packages/dashboard/src/components/spree/stock-history-card.tsx b/packages/dashboard/src/components/spree/stock-history-card.tsx
index 9379a6bbb1..072a7fe72d 100644
--- a/packages/dashboard/src/components/spree/stock-history-card.tsx
+++ b/packages/dashboard/src/components/spree/stock-history-card.tsx
@@ -95,6 +95,8 @@ export function StockHistoryCard({
<TableHeader>
<TableRow>
<TableHead>{t('admin.stock_history.columns.when')}</TableHead>
+ <TableHead>{t('admin.stock_history.columns.product')}</TableHead>
+ <TableHead>{t('admin.stock_history.columns.where')}</TableHead>
<TableHead>{t('admin.stock_history.columns.change')}</TableHead>
<TableHead>{t('admin.stock_history.columns.kind')}</TableHead>
<TableHead>{t('admin.stock_history.columns.cause')}</TableHead>
@@ -106,6 +108,19 @@ export function StockHistoryCard({
<TableCell className="whitespace-nowrap text-muted-foreground text-sm">
<RelativeTime iso={movement.created_at} />
</TableCell>
+ <TableCell>
+ <div className="min-w-0">
+ <div className="truncate font-medium">{movement.variant_name ?? '—'}</div>
+ {movement.variant_sku && (
+ <div className="text-muted-foreground text-xs">
+ {movement.variant_sku}
+ </div>
+ )}
+ </div>
+ </TableCell>
+ <TableCell className="whitespace-nowrap text-sm">
+ {movement.stock_location_name ?? '—'}
+ </TableCell>
<TableCell className="font-medium tabular-nums">
<QuantityChange movement={movement} />
</TableCell>
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 160043102b..87ea09e69a 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -5459,7 +5459,9 @@
"empty": "لم يتغير هذا المخزون بعد",
"columns": {
"when": "الوقت",
+ "product": "المنتج",
"change": "التغيير",
+ "where": "المكان",
"kind": "ما حدث",
"cause": "السبب"
},
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 91fb4516a1..08a9c5f2ff 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -5430,7 +5430,9 @@
"empty": "Dieser Bestand hat sich noch nicht verändert",
"columns": {
"when": "Wann",
+ "product": "Produkt",
"change": "Änderung",
+ "where": "Wo",
"kind": "Was passiert ist",
"cause": "Warum"
},
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 955aeb00b1..4ad66c3616 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -5430,7 +5430,9 @@
"empty": "Nothing has changed this stock yet",
"columns": {
"when": "When",
+ "product": "Product",
"change": "Change",
+ "where": "Where",
"kind": "What happened",
"cause": "Why"
},
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index c5e0714808..18018e3899 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -5430,7 +5430,9 @@
"empty": "Ce stock n'a pas encore changé",
"columns": {
"when": "Quand",
+ "product": "Produit",
"change": "Variation",
+ "where": "Où",
"kind": "Ce qui s'est passé",
"cause": "Pourquoi"
},
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index a53081d124..3dcc08a9cb 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -5492,7 +5492,9 @@
"empty": "Ten stan jeszcze się nie zmieniał",
"columns": {
"when": "Kiedy",
+ "product": "Produkt",
"change": "Zmiana",
+ "where": "Gdzie",
"kind": "Co się stało",
"cause": "Dlaczego"
},
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index db3377b2e3..5e03b0bff8 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -5419,7 +5419,9 @@
"empty": "此库存尚无变动",
"columns": {
"when": "时间",
+ "product": "商品",
"change": "变动",
+ "where": "位置",
"kind": "发生了什么",
"cause": "原因"
},
diff --git a/spree/api/app/controllers/spree/api/v3/admin/stock_movements_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/stock_movements_controller.rb
index 938177f00a..566fbe59b5 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/stock_movements_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/stock_movements_controller.rb
@@ -18,8 +18,10 @@ module Spree
Spree.api.admin_stock_movement_serializer
end
+ # Every row names its shelf and its SKU, so both come along rather
+ # than costing a query each.
def collection_includes
- [:stock_level]
+ [{ stock_level: [:stock_location, { variant: :product }] }]
end
# Newest first: a stock history is read from the most recent change
diff --git a/spree/api/app/serializers/spree/api/v3/admin/stock_movement_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/stock_movement_serializer.rb
index 2715c6d503..81f18bd2dc 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/stock_movement_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/stock_movement_serializer.rb
@@ -8,7 +8,37 @@ module Spree
stock_transfer_id: [:string, nullable: true],
purchase_order_id: [:string, nullable: true],
unit_cost: [:string, nullable: true],
- display_unit_cost: [:string, nullable: true]
+ display_unit_cost: [:string, nullable: true],
+ stock_location_id: [:string, nullable: true],
+ stock_location_name: [:string, nullable: true],
+ variant_id: [:string, nullable: true],
+ variant_name: [:string, nullable: true],
+ variant_sku: [:string, nullable: true]
+
+ # Which shelf, and which SKU. A movement names neither directly —
+ # both hang off its stock level, the (variant, warehouse) pair — but
+ # a history panel cannot be read without them: scoped to a variant
+ # the warehouse is what varies, scoped to a warehouse the SKU is,
+ # and scoped to one transfer both do.
+ attribute :stock_location_id do |movement|
+ movement.stock_level&.stock_location&.prefixed_id
+ end
+
+ attribute :stock_location_name do |movement|
+ movement.stock_level&.stock_location&.name
+ end
+
+ attribute :variant_id do |movement|
+ movement.stock_level&.variant&.prefixed_id
+ end
+
+ attribute :variant_name do |movement|
+ movement.stock_level&.variant&.product&.name
+ end
+
+ attribute :variant_sku do |movement|
+ movement.stock_level&.variant&.sku
+ end
# The cause. Exactly which keys are set follows from the kind — a
# dispatch carries its fulfillment and its order, a transfer carries