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.

Exempt suppliers from customer erasure, and drive the receive screen in a browser

Łukasz Adamczyk73508852f265
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 0f58bd944e..6002b8ecc1 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -31,6 +31,11 @@ import {
FIXTURE_PROMO_SKU,
FIXTURE_PROMO_TAXON,
FIXTURE_PROMO_TAXON_PERMALINK,
+ FIXTURE_SUPPLIER,
+ FIXTURE_TRANSFER_DESTINATION,
+ FIXTURE_TRANSFER_PRODUCT,
+ FIXTURE_TRANSFER_SKU,
+ FIXTURE_TRANSFER_SOURCE,
} from './helpers'
import { ASYNC_JOBS_INITIALIZER, CREDENTIALS_FILE, E2E_DIR, RAILS_PID_FILE } from './paths'
@@ -122,6 +127,17 @@ const BOOTSTRAP_RUBY = [
`ledger_seller.seller_payouts.where(amount: ${FIXTURE_LEDGER_OWED_AMOUNT}).first_or_create!(store: s, currency: s.default_currency, provider: Spree::PayoutProvider::System.provider_key, status: 'pending')`,
`ledger_order = s.orders.where(seller: ledger_seller).first || Spree::Order.create!(store: s, seller: ledger_seller, currency: s.default_currency, email: '[email protected]', status: 'placed', completed_at: Time.current)`,
`ledger_seller.seller_transfers.first_or_create!(store: s, order: ledger_order, payout: ledger_payout, amount: ${FIXTURE_LEDGER_PAYOUT_AMOUNT}, currency: s.default_currency, kind: 'earning', provider: Spree::PayoutProvider::System.provider_key, status: 'completed')`,
+ // Inventory operations: a second warehouse to transfer into, a stocked
+ // product to send, and a supplier to order from. A transfer cannot be
+ // created from its own screens without two warehouses.
+ `transfer_source = s.stock_locations.where(name: '${FIXTURE_TRANSFER_SOURCE}').first_or_create!(active: true)`,
+ `transfer_destination = s.stock_locations.where(name: '${FIXTURE_TRANSFER_DESTINATION}').first_or_create!(active: true)`,
+ `transfer_product = Spree::Product.where(name: '${FIXTURE_TRANSFER_PRODUCT}').first_or_create!(store: s, status: 'active')`,
+ `transfer_product.default_variant.update!(sku: '${FIXTURE_TRANSFER_SKU}')`,
+ `transfer_product.default_variant.set_price(s.default_currency, 24.99)`,
+ // Deep enough that the serial suite can ship from it repeatedly.
+ 'transfer_source.stock_levels.where(variant: transfer_product.default_variant).first_or_create!.update!(count_on_hand: 5000)',
+ `s.suppliers.where(name: '${FIXTURE_SUPPLIER}').first_or_create!(email: '[email protected]')`,
'port = ENV.fetch("PORT", 3010)',
'puts JSON.generate(api_url: "http://localhost:#{port}", admin_email: admin.email, admin_password: "spree123", store_id: s.prefixed_id, store_name: s.name)',
].join('; ')
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index 25d5a35b73..1a76113291 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -145,6 +145,18 @@ export const FIXTURE_BULK_CATEGORY_PERMALINK = 'e2e-bulk-category'
// Second channel beyond the seeded default `online`. Used by the
// channels bulk-action and filter specs.
export const FIXTURE_BULK_CHANNEL_CODE = 'e2e-bulk'
+
+/**
+ * Inventory-operations fixtures. A transfer needs two warehouses and stock at
+ * the source before it can ship, and neither is creatable from the transfer
+ * screens themselves.
+ */
+export const FIXTURE_TRANSFER_SOURCE = 'E2E Source Warehouse'
+export const FIXTURE_TRANSFER_DESTINATION = 'E2E Destination Warehouse'
+export const FIXTURE_TRANSFER_PRODUCT = 'E2E Transfer Product'
+/** Unique so the transfer specs can resolve exactly the stocked variant. */
+export const FIXTURE_TRANSFER_SKU = 'E2E-TRANSFER-SKU'
+export const FIXTURE_SUPPLIER = 'E2E Supplier'
export const FIXTURE_BULK_CHANNEL_NAME = 'E2E Bulk Channel'
/**
* A seller with one settled sale and one payout still owed, so the ledger
diff --git a/packages/dashboard/e2e/stock-transfers.spec.ts b/packages/dashboard/e2e/stock-transfers.spec.ts
index e352b3fd48..97ebfe5258 100644
--- a/packages/dashboard/e2e/stock-transfers.spec.ts
+++ b/packages/dashboard/e2e/stock-transfers.spec.ts
@@ -1,26 +1,137 @@
import { expect, test } from '@playwright/test'
-import { gotoIndex, login } from './helpers'
+import {
+ FIXTURE_TRANSFER_DESTINATION,
+ FIXTURE_TRANSFER_SKU,
+ FIXTURE_TRANSFER_SOURCE,
+ gotoIndex,
+ login,
+} from './helpers'
const TRANSFERS_PATH = (storeId: string) => `/${storeId}/products/transfers`
const CTA = /new transfer/i
+/**
+ * The whole point of the 6.0 transfer: a trip has a middle. Stock leaves the
+ * source when the van goes and lands at the destination when somebody counts
+ * it in — and counting in less than was sent has to be the ordinary case.
+ *
+ * The draft is opened through the API rather than the form: the receive screen
+ * is what is new here, and driving two warehouse selects through the UI only
+ * re-tests the select primitive.
+ */
test.describe('stock transfers', () => {
- test('lists stock transfers', async ({ page }) => {
+ test('lists transfers', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, TRANSFERS_PATH(creds.store_id), CTA)
})
- // The "new transfer" Sheet requires picking a stocked variant. We only
- // assert the sheet opens; a full create needs a product + variant with
- // stock items, which the dummy app's seed pipeline doesn't provision.
- test('opens the new transfer sheet', async ({ page }) => {
+ test('offers the create form', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, TRANSFERS_PATH(creds.store_id), CTA)
- await page.getByRole('button', { name: /new transfer/i }).click()
- await expect(page.getByRole('heading', { name: /new stock transfer/i })).toBeVisible({
+ await page.getByRole('button', { name: CTA }).click()
+
+ await expect(page.getByRole('heading', { name: /new stock transfer/i })).toBeVisible()
+ await expect(page.locator('#source')).toBeVisible()
+ await expect(page.locator('#destination')).toBeVisible()
+ // Empty until a SKU is added — a draft may open with nothing on it.
+ await expect(page.getByRole('button', { name: /create draft/i })).toBeVisible()
+ })
+
+ test('sends a draft, then receives less than was sent', async ({ page }) => {
+ const creds = await login(page)
+ const transfer = await createInTransitTransfer(page, creds.accessToken, 10)
+
+ await page.goto(`${TRANSFERS_PATH(creds.store_id)}/${transfer.id}`)
+
+ await expect(page.getByRole('heading', { name: transfer.number })).toBeVisible({
timeout: 15_000,
})
- await expect(page.locator('#destination')).toBeVisible()
+ await expect(page.getByText(/^in transit$/i).first()).toBeVisible()
+ // Gone from the source, not yet at the destination.
+ await expect(page.getByText('0 received of 10 shipped')).toBeVisible()
+
+ // Count in eight of the ten, and say why two are missing.
+ await page.getByLabel(/^received$/i).fill('8')
+ const discrepancy = page.getByLabel(/discrepancy/i)
+ await discrepancy.click()
+ await page.getByRole('option', { name: /damaged in transit/i }).click()
+ await page.getByRole('button', { name: /^receive$/i }).click()
+
+ // Short, so the trip stays open rather than closing.
+ await expect(page.getByText(/^partially received$/i).first()).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText('8 received of 10 shipped')).toBeVisible()
+ })
+
+ test('makes the merchant say what happened to units already gone', async ({ page }) => {
+ const creds = await login(page)
+ const transfer = await createInTransitTransfer(page, creds.accessToken, 4)
+
+ await page.goto(`${TRANSFERS_PATH(creds.store_id)}/${transfer.id}`)
+ await expect(page.getByRole('heading', { name: transfer.number })).toBeVisible({
+ timeout: 15_000,
+ })
+
+ // The units are physically gone from the source, so the screen offers
+ // restock or write-off rather than guessing.
+ await expect(page.getByText(/the units have already left/i)).toBeVisible()
+ await expect(page.locator('#in-transit-resolution')).toBeVisible()
+ await expect(page.getByRole('button', { name: /cancel transfer/i })).toBeVisible()
+ // Nothing to mark ready or send any more.
+ await expect(page.getByRole('button', { name: /mark in transit/i })).toHaveCount(0)
})
})
+
+/**
+ * A transfer already on the road, opened through the Admin API.
+ *
+ * Both warehouses and the product come from the global-setup fixtures, which
+ * is also where the source's stock comes from — a transfer cannot ship from an
+ * empty shelf.
+ */
+async function createInTransitTransfer(
+ page: import('@playwright/test').Page,
+ accessToken: string,
+ quantity: number,
+) {
+ const headers = { Authorization: `Bearer ${accessToken}` }
+
+ const locations = await page.request
+ .get('/api/v3/admin/stock_locations', { headers, params: { limit: 100 } })
+ .then((res) => res.json())
+ const source = locations.data.find((l: { name: string }) => l.name === FIXTURE_TRANSFER_SOURCE)
+ const destination = locations.data.find(
+ (l: { name: string }) => l.name === FIXTURE_TRANSFER_DESTINATION,
+ )
+
+ // By SKU, not by search: the fixture SKU resolves exactly the variant whose
+ // stock global-setup put on the source shelf, and a transfer cannot ship
+ // from an empty one.
+ const variants = await page.request
+ .get('/api/v3/admin/variants', {
+ headers,
+ params: { 'q[sku_eq]': FIXTURE_TRANSFER_SKU },
+ })
+ .then((res) => res.json())
+ expect(variants.data, `no variant with SKU ${FIXTURE_TRANSFER_SKU}`).not.toHaveLength(0)
+
+ const created = await page.request.post('/api/v3/admin/stock_transfers', {
+ headers,
+ data: {
+ source_location_id: source.id,
+ destination_location_id: destination.id,
+ reference: `E2E restock ${Date.now()}`,
+ items: [{ variant_id: variants.data[0].id, quantity_shipped: quantity }],
+ },
+ })
+ expect(created.status(), await created.text()).toBe(201)
+ const transfer = await created.json()
+
+ const shipped = await page.request.patch(
+ `/api/v3/admin/stock_transfers/${transfer.id}/mark_in_transit`,
+ { headers },
+ )
+ expect(shipped.status(), await shipped.text()).toBe(200)
+
+ return transfer
+}
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 9a168c9e96..5c757c6fa4 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
@@ -1,5 +1,5 @@
import type { PurchaseOrder, PurchaseOrderItem } from '@spree/admin-sdk'
-import { Can, Subject } from '@spree/dashboard-core'
+import { Can, PageHeader, Subject } from '@spree/dashboard-core'
import {
Button,
Card,
@@ -16,8 +16,7 @@ import {
TableRow,
useConfirm,
} from '@spree/dashboard-ui'
-import { ArrowLeftIcon } from '@spree/dashboard-ui/icons'
-import { createFileRoute, useNavigate } from '@tanstack/react-router'
+import { createFileRoute } from '@tanstack/react-router'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { InventoryStatusBadge } from '../../../../../components/spree/inventory-status-badge'
@@ -37,8 +36,7 @@ export const Route = createFileRoute(
function PurchaseOrderDetailPage() {
const { t } = useTranslation()
- const { storeId, purchaseOrderId } = Route.useParams()
- const navigate = useNavigate()
+ const { purchaseOrderId } = Route.useParams()
const { data: purchaseOrder, isLoading } = usePurchaseOrder(purchaseOrderId)
if (isLoading || !purchaseOrder) {
@@ -47,21 +45,11 @@ function PurchaseOrderDetailPage() {
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">
- <div className="flex items-center gap-3">
- <Button
- type="button"
- size="icon-sm"
- variant="ghost"
- onClick={() =>
- navigate({ to: '/$storeId/products/purchase-orders', params: { storeId } })
- }
- >
- <ArrowLeftIcon className="size-4" />
- <span className="sr-only">{t('admin.actions.back')}</span>
- </Button>
- <h1 className="text-xl font-semibold tabular-nums">{purchaseOrder.number}</h1>
- <InventoryStatusBadge status={purchaseOrder.status} resource="purchase_orders" />
- </div>
+ <PageHeader
+ title={purchaseOrder.number}
+ backTo="products/purchase-orders"
+ badges={<InventoryStatusBadge status={purchaseOrder.status} resource="purchase_orders" />}
+ />
<SummaryCard purchaseOrder={purchaseOrder} />
<ItemsCard purchaseOrder={purchaseOrder} />
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
index 4005bc219e..846b70f807 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/purchase-orders/new.tsx
@@ -1,4 +1,9 @@
-import { CurrencySelect, StoreDatePicker, useStockLocations } from '@spree/dashboard-core'
+import {
+ CurrencySelect,
+ PageHeader,
+ StoreDatePicker,
+ useStockLocations,
+} from '@spree/dashboard-core'
import {
Button,
Card,
@@ -76,9 +81,11 @@ function NewPurchaseOrderPage() {
return (
<div className="mx-auto flex w-full max-w-3xl flex-col gap-4 p-4">
+ <PageHeader title={t('admin.purchase_orders.new_title')} backTo="products/purchase-orders" />
+
<Card>
<CardHeader>
- <CardTitle>{t('admin.purchase_orders.new_title')}</CardTitle>
+ <CardTitle>{t('admin.purchase_orders.details_title')}</CardTitle>
</CardHeader>
<CardContent>
<FieldGroup>
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 8fe1827c32..243126089d 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/$transferId.tsx
@@ -1,5 +1,5 @@
import type { StockTransfer, StockTransferItem } from '@spree/admin-sdk'
-import { Can, Subject, useStockLocations } from '@spree/dashboard-core'
+import { Can, PageHeader, Subject, useStockLocations } from '@spree/dashboard-core'
import {
Button,
Card,
@@ -23,8 +23,7 @@ import {
TableRow,
useConfirm,
} from '@spree/dashboard-ui'
-import { ArrowLeftIcon } from '@spree/dashboard-ui/icons'
-import { createFileRoute, useNavigate } from '@tanstack/react-router'
+import { createFileRoute } from '@tanstack/react-router'
import { useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { InventoryStatusBadge } from '../../../../../components/spree/inventory-status-badge'
@@ -49,8 +48,7 @@ export const Route = createFileRoute('/_authenticated/$storeId/products/transfer
function StockTransferDetailPage() {
const { t } = useTranslation()
- const { storeId, transferId } = Route.useParams()
- const navigate = useNavigate()
+ const { transferId } = Route.useParams()
const { data: transfer, isLoading } = useStockTransfer(transferId)
if (isLoading || !transfer) {
@@ -59,19 +57,11 @@ function StockTransferDetailPage() {
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4">
- <div className="flex items-center gap-3">
- <Button
- type="button"
- size="icon-sm"
- variant="ghost"
- onClick={() => navigate({ to: '/$storeId/products/transfers', params: { storeId } })}
- >
- <ArrowLeftIcon className="size-4" />
- <span className="sr-only">{t('admin.actions.back')}</span>
- </Button>
- <h1 className="text-xl font-semibold tabular-nums">{transfer.number}</h1>
- <InventoryStatusBadge status={transfer.status} resource="stock_transfers" />
- </div>
+ <PageHeader
+ title={transfer.number}
+ backTo="products/transfers"
+ badges={<InventoryStatusBadge status={transfer.status} resource="stock_transfers" />}
+ />
<SummaryCard transfer={transfer} />
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/new.tsx
index a8a50a760e..23b2f8aebb 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/transfers/new.tsx
@@ -1,4 +1,4 @@
-import { useStockLocations } from '@spree/dashboard-core'
+import { PageHeader, useStockLocations } from '@spree/dashboard-core'
import {
Button,
Card,
@@ -70,9 +70,11 @@ function NewStockTransferPage() {
return (
<div className="mx-auto flex w-full max-w-3xl flex-col gap-4 p-4">
+ <PageHeader title={t('admin.stock_transfers.new_title')} backTo="products/transfers" />
+
<Card>
<CardHeader>
- <CardTitle>{t('admin.stock_transfers.new_title')}</CardTitle>
+ <CardTitle>{t('admin.stock_transfers.details_title')}</CardTitle>
</CardHeader>
<CardContent>
<FieldGroup>
diff --git a/spree/core/spec/models/spree/customer_personal_data_coverage_spec.rb b/spree/core/spec/models/spree/customer_personal_data_coverage_spec.rb
index 3ef8840d25..f9ce69fa6a 100644
--- a/spree/core/spec/models/spree/customer_personal_data_coverage_spec.rb
+++ b/spree/core/spec/models/spree/customer_personal_data_coverage_spec.rb
@@ -49,6 +49,7 @@ RSpec.describe 'personal data coverage' do
'spree_invitations' => 'staff invitations — an admin lifecycle, not a customer one',
'spree_company_invitations' => 'B2B invitations, erased with the company rather than the buyer',
'spree_stock_locations' => 'a warehouse contact number, not a customer',
+ 'spree_suppliers' => 'a business the merchant buys from, not a shopper',
'spree_webhook_deliveries' => 'operational log with its own retention; payloads expire on their own schedule',
'spree_seller_requirement_submissions' => 'seller onboarding evidence, not customer data',
'spree_sellers' => 'marketplace seller contact details, not a shopper',