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.

Act on the bot review

Łukasz Adamczykf9388b140f65
diff --git a/packages/dashboard/src/components/spree/purchase-order-form.tsx b/packages/dashboard/src/components/spree/purchase-order-form.tsx
index 398846bdae..8779c3bf53 100644
--- a/packages/dashboard/src/components/spree/purchase-order-form.tsx
+++ b/packages/dashboard/src/components/spree/purchase-order-form.tsx
@@ -89,12 +89,18 @@ export function PurchaseOrderForm({
const [notes, setNotes] = useState(initial.notes)
const [lines, setLines] = useState<VariantLine[]>(initial.lines)
+ // A cleared cost input is not zero — it is nothing, which the server rejects
+ // field-by-field. `Number('')` is 0 and finite, so the emptiness has to be
+ // checked before the number is.
+ const hasCost = (value?: string) => {
+ const trimmed = value?.trim()
+ return !!trimmed && Number.isFinite(Number(trimmed)) && Number(trimmed) >= 0
+ }
+
const canSubmit =
!!supplierId &&
!!destinationId &&
- // A cleared cost input is not zero — it is nothing, which the server
- // rejects field-by-field. Catch it here, where the field is.
- lines.every((line) => line.quantity > 0 && Number.isFinite(Number(line.unitCost)))
+ lines.every((line) => line.quantity > 0 && hasCost(line.unitCost))
return (
<>
diff --git a/packages/dashboard/src/components/spree/stock-transfer-form.tsx b/packages/dashboard/src/components/spree/stock-transfer-form.tsx
index 57a68daa2b..0764c547a4 100644
--- a/packages/dashboard/src/components/spree/stock-transfer-form.tsx
+++ b/packages/dashboard/src/components/spree/stock-transfer-form.tsx
@@ -74,8 +74,9 @@ export function StockTransferForm({
const sameLocation = !!sourceId && sourceId === destinationId
// Lines were picked for the shelf they are leaving, so the source is fixed
// once there are any: changing it would silently keep SKUs the new source
- // may hold none of. Emptying the list frees it again.
- const sourceLocked = lines.length > 0 && !!initial.sourceId
+ // may hold none of. Emptying the list frees it again. Applies while creating
+ // too — the picker filters by source there as well.
+ const sourceLocked = lines.length > 0
const canSubmit =
!!sourceId && !!destinationId && !sameLocation && lines.every((line) => line.quantity > 0)
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 83c2a58610..885e0653ec 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -5087,7 +5087,8 @@
"failed_to_mark_in_transit": "تعذّر تعيين التحويل كفي الطريق",
"failed_to_receive": "تعذّر استلام التحويل",
"failed_to_cancel": "تعذّر إلغاء التحويل",
- "not_editable": "تم تجهيز هذا النقل، ومحتواه الآن سجل ثابت. ألغِه إذا لم يكن ينبغي إرساله."
+ "not_editable": "تم تجهيز هذا النقل، ومحتواه الآن سجل ثابت. ألغِه إذا لم يكن ينبغي إرساله.",
+ "failed_to_load": "تعذّر تحميل هذا النقل."
},
"messages": {
"deleted": "تم حذف التحويل",
@@ -5556,7 +5557,8 @@
"failed_to_order": "تعذّر إرسال أمر الشراء",
"failed_to_receive": "تعذّر تسجيل التوريد",
"failed_to_cancel": "تعذّر إلغاء أمر الشراء",
- "not_editable": "أُرسل هذا الأمر إلى المورّد، وبنوده الآن التزام بين شركتين. ألغِه إذا لم يكن ينبغي أن يستمر."
+ "not_editable": "أُرسل هذا الأمر إلى المورّد، وبنوده الآن التزام بين شركتين. ألغِه إذا لم يكن ينبغي أن يستمر.",
+ "failed_to_load": "تعذّر تحميل أمر الشراء هذا."
},
"delete_confirm": {
"title": "حذف أمر الشراء هذا؟",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index a85443c3dd..8c45f68804 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -5065,7 +5065,8 @@
"failed_to_mark_in_transit": "Umlagerung konnte nicht als unterwegs markiert werden",
"failed_to_receive": "Wareneingang konnte nicht gebucht werden",
"failed_to_cancel": "Umlagerung konnte nicht abgebrochen werden",
- "not_editable": "Diese Umbuchung ist gepackt, ihr Inhalt ist damit dokumentiert. Storniere sie, wenn sie nicht gehen soll."
+ "not_editable": "Diese Umbuchung ist gepackt, ihr Inhalt ist damit dokumentiert. Storniere sie, wenn sie nicht gehen soll.",
+ "failed_to_load": "Diese Umbuchung konnte nicht geladen werden."
},
"messages": {
"deleted": "Umlagerung gelöscht",
@@ -5527,7 +5528,8 @@
"failed_to_order": "Bestellung konnte nicht aufgegeben werden",
"failed_to_receive": "Lieferung konnte nicht eingebucht werden",
"failed_to_cancel": "Bestellung konnte nicht abgebrochen werden",
- "not_editable": "Diese Bestellung liegt beim Lieferanten, ihre Positionen sind damit verbindlich. Storniere sie, wenn sie nicht gelten soll."
+ "not_editable": "Diese Bestellung liegt beim Lieferanten, ihre Positionen sind damit verbindlich. Storniere sie, wenn sie nicht gelten soll.",
+ "failed_to_load": "Diese Bestellung konnte nicht geladen werden."
},
"delete_confirm": {
"title": "Diese Bestellung löschen?",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 9832a04222..8a4d115e61 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -5065,7 +5065,8 @@
"failed_to_mark_in_transit": "Failed to mark the transfer in transit",
"failed_to_receive": "Failed to receive the transfer",
"failed_to_cancel": "Failed to cancel the transfer",
- "not_editable": "This transfer has been packed, so what is in it is now a matter of record. Cancel it if it should not go."
+ "not_editable": "This transfer has been packed, so what is in it is now a matter of record. Cancel it if it should not go.",
+ "failed_to_load": "This transfer could not be loaded."
},
"messages": {
"deleted": "Transfer deleted",
@@ -5527,7 +5528,8 @@
"failed_to_order": "Failed to place the purchase order",
"failed_to_receive": "Failed to book in the delivery",
"failed_to_cancel": "Failed to cancel the purchase order",
- "not_editable": "This order has gone to the supplier, so its lines are a matter of record between two businesses. Cancel it if it should not stand."
+ "not_editable": "This order has gone to the supplier, so its lines are a matter of record between two businesses. Cancel it if it should not stand.",
+ "failed_to_load": "This purchase order could not be loaded."
},
"delete_confirm": {
"title": "Delete this purchase order?",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 04ae0aff21..50f7fb12d3 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -5065,7 +5065,8 @@
"failed_to_mark_in_transit": "Impossible de marquer le transfert en transit",
"failed_to_receive": "Échec de la réception du transfert",
"failed_to_cancel": "Échec de l'annulation du transfert",
- "not_editable": "Ce transfert est emballé : son contenu fait désormais foi. Annulez-le s'il ne doit pas partir."
+ "not_editable": "Ce transfert est emballé : son contenu fait désormais foi. Annulez-le s'il ne doit pas partir.",
+ "failed_to_load": "Ce transfert n'a pas pu être chargé."
},
"messages": {
"deleted": "Transfert supprimé",
@@ -5527,7 +5528,8 @@
"failed_to_order": "Échec du passage de la commande",
"failed_to_receive": "Échec de l'enregistrement de la livraison",
"failed_to_cancel": "Échec de l'annulation du bon de commande",
- "not_editable": "Ce bon est parti chez le fournisseur : ses lignes engagent les deux parties. Annulez-le s'il ne doit pas tenir."
+ "not_editable": "Ce bon est parti chez le fournisseur : ses lignes engagent les deux parties. Annulez-le s'il ne doit pas être maintenu.",
+ "failed_to_load": "Ce bon de commande n'a pas pu être chargé."
},
"delete_confirm": {
"title": "Supprimer ce bon de commande ?",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 1b1c30c54a..00bb6aa568 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -5123,7 +5123,8 @@
"failed_to_mark_in_transit": "Nie udało się oznaczyć przesunięcia jako w drodze",
"failed_to_receive": "Nie udało się przyjąć przesunięcia",
"failed_to_cancel": "Nie udało się anulować przesunięcia",
- "not_editable": "Ten transfer jest zapakowany, więc jego zawartość jest już zapisem. Anuluj go, jeśli nie ma jechać."
+ "not_editable": "Ten transfer jest zapakowany, więc jego zawartość jest już zapisem. Anuluj go, jeśli nie ma jechać.",
+ "failed_to_load": "Nie udało się wczytać tego transferu."
},
"messages": {
"deleted": "Przesunięcie usunięte",
@@ -5589,7 +5590,8 @@
"failed_to_order": "Nie udało się złożyć zamówienia",
"failed_to_receive": "Nie udało się zaksięgować dostawy",
"failed_to_cancel": "Nie udało się anulować zamówienia zakupu",
- "not_editable": "To zamówienie trafiło do dostawcy, więc jego pozycje wiążą obie strony. Anuluj je, jeśli nie ma obowiązywać."
+ "not_editable": "To zamówienie trafiło do dostawcy, więc jego pozycje wiążą obie strony. Anuluj je, jeśli nie ma obowiązywać.",
+ "failed_to_load": "Nie udało się wczytać tego zamówienia."
},
"delete_confirm": {
"title": "Usunąć to zamówienie zakupu?",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index b8da18866b..0f5f325ff7 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -5056,7 +5056,8 @@
"failed_to_mark_in_transit": "标记调拨为在途失败",
"failed_to_receive": "调拨收货失败",
"failed_to_cancel": "取消调拨失败",
- "not_editable": "该调拨已打包,内容已成为记录。如果不该发出,请取消它。"
+ "not_editable": "该调拨已打包,内容已成为记录。如果不该发出,请取消它。",
+ "failed_to_load": "无法加载该调拨。"
},
"messages": {
"deleted": "调拨已删除",
@@ -5516,7 +5517,8 @@
"failed_to_order": "下单失败",
"failed_to_receive": "到货入库失败",
"failed_to_cancel": "取消采购订单失败",
- "not_editable": "该订单已发给供应商,其商品行是两家企业之间的约定。如果不该继续,请取消它。"
+ "not_editable": "该订单已发给供应商,其商品行是两家企业之间的约定。如果不该继续,请取消它。",
+ "failed_to_load": "无法加载该采购订单。"
},
"delete_confirm": {
"title": "删除此采购订单?",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId/index.tsx
index a5f4b74a19..cc80687c7b 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/$purchaseOrderId/index.tsx
@@ -7,6 +7,7 @@ import {
CardHeader,
CardTitle,
DropdownMenuItem,
+ ErrorState,
RelativeTime,
Table,
TableBody,
@@ -41,12 +42,24 @@ export const Route = createFileRoute(
function PurchaseOrderDetailPage() {
const { t } = useTranslation()
const { purchaseOrderId } = Route.useParams()
- const { data: purchaseOrder, isLoading } = usePurchaseOrder(purchaseOrderId)
+ const { data: purchaseOrder, isLoading, error, refetch } = usePurchaseOrder(purchaseOrderId)
- if (isLoading || !purchaseOrder) {
+ if (isLoading) {
return <div className="p-4 text-sm text-muted-foreground">{t('admin.common.loading')}</div>
}
+ // A failed request is not a slow one: without this the screen shows
+ // "Loading…" for as long as the merchant is willing to look at it.
+ if (error || !purchaseOrder) {
+ return (
+ <ErrorState
+ title={t('admin.purchase_orders.errors.failed_to_load')}
+ error={error as Error | undefined}
+ onRetry={() => refetch()}
+ />
+ )
+ }
+
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">
<PurchaseOrderHeader purchaseOrder={purchaseOrder} />
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId/index.tsx
index f2334ad988..68f0fd9294 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId/index.tsx
@@ -7,6 +7,7 @@ import {
CardHeader,
CardTitle,
DropdownMenuItem,
+ ErrorState,
RelativeTime,
Select,
SelectContent,
@@ -49,12 +50,24 @@ export const Route = createFileRoute('/_authenticated/$storeId/products/transfer
function StockTransferDetailPage() {
const { t } = useTranslation()
const { transferId } = Route.useParams()
- const { data: transfer, isLoading } = useStockTransfer(transferId)
+ const { data: transfer, isLoading, error, refetch } = useStockTransfer(transferId)
- if (isLoading || !transfer) {
+ if (isLoading) {
return <div className="p-4 text-sm text-muted-foreground">{t('admin.common.loading')}</div>
}
+ // A failed request is not a slow one: without this the screen shows
+ // "Loading…" for as long as the merchant is willing to look at it.
+ if (error || !transfer) {
+ return (
+ <ErrorState
+ title={t('admin.stock_transfers.errors.failed_to_load')}
+ error={error as Error | undefined}
+ onRetry={() => refetch()}
+ />
+ )
+ }
+
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">
<TransferHeader transfer={transfer} />
diff --git a/spree/core/lib/tasks/inventory_operations_migration.rake b/spree/core/lib/tasks/inventory_operations_migration.rake
index 84f8c8205a..22650ab941 100644
--- a/spree/core/lib/tasks/inventory_operations_migration.rake
+++ b/spree/core/lib/tasks/inventory_operations_migration.rake
@@ -97,13 +97,22 @@ module Spree
# One line per variant, summing the movements that named it: a 5.x receive
# of five SKUs is five movement rows whose only link is the transfer.
+ #
+ # Signed, so rows that offset each other total what they actually moved.
+ # A variant summing to zero is dropped — it received nothing, and a line
+ # of zero would fail validation and take the whole transfer with it. A
+ # negative total is left alone deliberately: the line then refuses to
+ # validate and the transfer is skipped for someone to look at, which is
+ # the right answer for a receive that reads as a dispatch.
def lines_from(movements)
- movements.each_with_object({}) do |movement, lines|
+ totals = movements.each_with_object({}) do |movement, lines|
variant_id = movement.stock_level&.variant_id
next if variant_id.nil?
- lines[variant_id] = lines.fetch(variant_id, 0) + movement.quantity.abs
+ lines[variant_id] = lines.fetch(variant_id, 0) + movement.quantity
end
+
+ totals.reject { |_variant_id, quantity| quantity.zero? }
end
def supplier_for(store)
diff --git a/spree/core/spec/lib/tasks/inventory_operations_migration_spec.rb b/spree/core/spec/lib/tasks/inventory_operations_migration_spec.rb
index facb3c67b3..b351978beb 100644
--- a/spree/core/spec/lib/tasks/inventory_operations_migration_spec.rb
+++ b/spree/core/spec/lib/tasks/inventory_operations_migration_spec.rb
@@ -101,6 +101,19 @@ describe 'spree:upgrade inventory operations' do
not_to change(Spree::PurchaseOrder, :count)
end
+ # Signed rather than absolute: two rows that cancel each other out moved
+ # nothing, and a line of zero would fail validation and take the whole
+ # transfer down with it.
+ it 'drops a variant whose movements cancel out, rather than adding them up' do
+ transfer = legacy_external_receive(quantity: 5)
+ level = destination.stock_level(variant.id)
+ level.stock_movements.create!(quantity: -5, kind: 'adjusted', stock_transfer: transfer,
+ reason: 'Counted back out at the time')
+
+ expect { run_task }.not_to change(Spree::PurchaseOrder, :count)
+ expect(Spree::StockTransfer.find(transfer.id)).to be_present
+ end
+
it 'skips a receive whose movements no longer name a variant' do
transfer = create(:stock_transfer, store: store, destination_location: destination, quantity: 0)
transfer.update_columns(source_location_id: nil, status: nil)