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.

Fix: Filed tax for each order of a split draft and corrected exemption reason wording

Damian Legawiecd14876d60b37
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index d994afa772..fc01bc6918 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -27970,7 +27970,8 @@ paths:
description: |-
Renames a tax exemption reason or retires it. Deactivating keeps it on the
certificates that already record it while removing it from the pickers. The
- code is fixed once a certificate records it.
+ code can change at any time, and every certificate holding the reason sends
+ the new code to the tax provider from then on.
**Required scope:** `write_settings` (for API-key authentication).
@@ -28066,6 +28067,14 @@ paths:
responses:
'204':
description: tax exemption reason deleted
+ '422':
+ description: tax exemption reason is in use
+ content:
+ application/json:
+ example:
+ error:
+ code: validation_error
+ message: Tax exemption reason cannot be deleted
"/api/v3/admin/promotions/{promotion_id}/coupon_codes":
parameters:
- name: promotion_id
diff --git a/packages/dashboard/src/components/spree/reasons/reason-section.tsx b/packages/dashboard/src/components/spree/reasons/reason-section.tsx
index 1d1cb5c550..21e4b05854 100644
--- a/packages/dashboard/src/components/spree/reasons/reason-section.tsx
+++ b/packages/dashboard/src/components/spree/reasons/reason-section.tsx
@@ -22,6 +22,7 @@ import {
SheetFooter,
SheetHeader,
SheetTitle,
+ Skeleton,
Switch,
Table,
TableBody,
@@ -390,7 +391,7 @@ function ReasonCodeField({ form }: { form: UseFormReturn<ReasonFormValues> }) {
const { errors } = form.formState
const { data } = useTaxProviders()
const { permissions } = usePermissions()
- const marketProviders = useMarketTaxProviders()
+ const { groups: marketProviders, isLoading } = useMarketTaxProviders()
// Only engines a market actually taxes with: a store that has Avalara set
// up but still taxes every market itself keeps free-text codes. Staff who
// cannot see markets fall back to every engine the store has set up.
@@ -416,7 +417,11 @@ function ReasonCodeField({ form }: { form: UseFormReturn<ReasonFormValues> }) {
return (
<Field>
<FieldLabel htmlFor="reason-code">{t('admin.fields.code.label')}</FieldLabel>
- {engineCodes.length ? (
+ {/* Which control fits is only known once the engines and markets load;
+ choosing early swaps a half-typed code into a picker. */}
+ {isLoading ? (
+ <Skeleton className="h-9 w-full" />
+ ) : engineCodes.length ? (
<Controller
control={form.control}
name="code"
diff --git a/packages/dashboard/src/components/spree/taxes/market-tax-providers.tsx b/packages/dashboard/src/components/spree/taxes/market-tax-providers.tsx
index 22d7b563cb..4c80152187 100644
--- a/packages/dashboard/src/components/spree/taxes/market-tax-providers.tsx
+++ b/packages/dashboard/src/components/spree/taxes/market-tax-providers.tsx
@@ -30,15 +30,16 @@ interface ProviderMarkets {
/**
* The store's markets grouped by the tax engine each one uses. A market that
* names no engine runs on the installation default. Empty for staff who
- * cannot read markets.
+ * cannot read markets. `isLoading` tells a store still loading apart from one
+ * whose markets settled on no engine.
*/
-export function useMarketTaxProviders(): ProviderMarkets[] {
+export function useMarketTaxProviders(): { groups: ProviderMarkets[]; isLoading: boolean } {
const { permissions } = usePermissions()
const canReadMarkets = permissions.can('read', Subject.Market)
- const { markets } = useAllMarkets({ enabled: canReadMarkets })
- const { data } = useTaxProviders()
+ const { markets, isLoading: marketsLoading } = useAllMarkets({ enabled: canReadMarkets })
+ const { data, isLoading: providersLoading } = useTaxProviders()
- return useMemo(() => {
+ const groups = useMemo(() => {
if (!canReadMarkets) return []
const providers = data?.data ?? []
@@ -58,13 +59,15 @@ export function useMarketTaxProviders(): ProviderMarkets[] {
return [...groups.values()]
}, [canReadMarkets, markets, data])
+
+ return { groups, isLoading: providersLoading || (canReadMarkets && marketsLoading) }
}
/** Which tax engine each market uses, with a link to change it. */
export function TaxProviderSummary() {
const { t } = useTranslation()
const { storeId } = useParams({ strict: false }) as { storeId: string }
- const groups = useMarketTaxProviders()
+ const { groups } = useMarketTaxProviders()
if (groups.length === 0) return null
@@ -102,7 +105,7 @@ export function TaxProviderSummary() {
*/
export function TaxRatesUsageNote() {
const { t } = useTranslation()
- const groups = useMarketTaxProviders()
+ const { groups } = useMarketTaxProviders()
const external = groups.filter((group) => group.providerId !== INTERNAL_PROVIDER)
if (external.length === 0) return null
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index ffbdebcafb..c2d1092505 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -5678,7 +5678,7 @@
},
"never_expires": "بلا تاريخ انتهاء",
"no_document": "لا يوجد مستند مرفق",
- "no_reasons": "لا توجد أسباب إعفاء بعد. أضفها من الإعدادات ← الأسباب.",
+ "no_reasons": "لا توجد أسباب إعفاء بعد. أضفها من الإعدادات ← الضرائب ← أسباب الإعفاء.",
"revoke_action": "إلغاء",
"revoke_confirm": {
"message": "لن تعود الشهادة {{number}} تسري على الطلبات الجديدة، لكنها تبقى محفوظة كسجل.",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 0d58aa37da..1462f2c0ef 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -5641,7 +5641,7 @@
},
"never_expires": "Läuft nicht ab",
"no_document": "Kein Dokument hinterlegt",
- "no_reasons": "Noch keine Befreiungsgründe. Fügen Sie sie unter Einstellungen → Gründe hinzu.",
+ "no_reasons": "Noch keine Befreiungsgründe. Fügen Sie sie unter Einstellungen → Steuern → Befreiungsgründe hinzu.",
"revoke_action": "Widerrufen",
"revoke_confirm": {
"message": "Bescheinigung {{number}} gilt dann nicht mehr für neue Bestellungen. Sie bleibt als Nachweis erhalten.",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index bba0c6f18b..35b6a598ff 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -5641,7 +5641,7 @@
},
"never_expires": "Does not expire",
"no_document": "No document attached",
- "no_reasons": "No exemption reasons yet. Add them in Settings → Reasons.",
+ "no_reasons": "No exemption reasons yet. Add them in Settings → Taxes → Exemption reasons.",
"revoke_action": "Revoke",
"revoke_confirm": {
"message": "Certificate {{number}} stops applying to new orders. It stays on file as a record.",
diff --git a/packages/dashboard/src/locales/es.json b/packages/dashboard/src/locales/es.json
index a4c6be4f42..eb7cf2d345 100644
--- a/packages/dashboard/src/locales/es.json
+++ b/packages/dashboard/src/locales/es.json
@@ -5050,7 +5050,7 @@
},
"never_expires": "No vence",
"no_document": "Sin documento adjunto",
- "no_reasons": "Aún no hay motivos de exención. Añádelos en Configuración → Motivos.",
+ "no_reasons": "Aún no hay motivos de exención. Añádelos en Configuración → Impuestos → Motivos de exención.",
"revoke_action": "Revocar",
"revoke_confirm": {
"message": "El certificado {{number}} deja de aplicar a pedidos nuevos. Queda archivado como registro.",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index c9f1a290e2..1647a419d6 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -5641,7 +5641,7 @@
},
"never_expires": "Sans expiration",
"no_document": "Aucun document joint",
- "no_reasons": "Aucun motif d'exonération. Ajoutez-en dans Paramètres → Motifs.",
+ "no_reasons": "Aucun motif d'exonération. Ajoutez-en dans Paramètres → Taxes → Motifs d’exonération.",
"revoke_action": "Révoquer",
"revoke_confirm": {
"message": "L'attestation {{number}} ne s'appliquera plus aux nouvelles commandes. Elle reste conservée comme justificatif.",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index b37772dcaf..439bf4ec07 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -5707,7 +5707,7 @@
},
"never_expires": "Bez daty wygaśnięcia",
"no_document": "Brak załączonego dokumentu",
- "no_reasons": "Brak powodów zwolnienia. Dodaj je w Ustawienia → Powody.",
+ "no_reasons": "Brak powodów zwolnienia. Dodaj je w Ustawienia → Podatki → Powody zwolnień.",
"revoke_action": "Unieważnij",
"revoke_confirm": {
"message": "Certyfikat {{number}} przestanie obowiązywać dla nowych zamówień. Pozostanie zapisany jako dokumentacja.",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 88ee47e1d7..3beff84cb5 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -5629,7 +5629,7 @@
},
"never_expires": "长期有效",
"no_document": "未附文件",
- "no_reasons": "尚无免税原因。请在 设置 → 原因 中添加。",
+ "no_reasons": "尚无免税原因。请在 设置 → 税费 → 免税原因 中添加。",
"revoke_action": "撤销",
"revoke_confirm": {
"message": "证明 {{number}} 将不再适用于新订单,但会作为记录保留。",
diff --git a/spree/api/spec/integration/spree/api/v3/admin/tax_exemption_reasons_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/tax_exemption_reasons_spec.rb
index b78a2bfbb3..a54278b53f 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/tax_exemption_reasons_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/tax_exemption_reasons_spec.rb
@@ -138,7 +138,8 @@ RSpec.describe 'Admin Tax Exemption Reasons API', type: :request, swagger_doc: '
description <<~DESC
Renames a tax exemption reason or retires it. Deactivating keeps it on the
certificates that already record it while removing it from the pickers. The
- code is fixed once a certificate records it.
+ code can change at any time, and every certificate holding the reason sends
+ the new code to the tax provider from then on.
DESC
admin_scope :write, :settings
@@ -182,6 +183,17 @@ RSpec.describe 'Admin Tax Exemption Reasons API', type: :request, swagger_doc: '
run_test!
end
+
+ response '422', 'tax exemption reason is in use' do
+ let(:'x-spree-api-key') { secret_api_key.plaintext_token }
+ let(:id) { reason.prefixed_id }
+
+ before { create(:tax_exemption_certificate, company: create(:company, store: store), reason_code: reason.code) }
+
+ schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ run_test!
+ end
end
end
end
diff --git a/spree/core/app/workflows/spree/carts/complete.rb b/spree/core/app/workflows/spree/carts/complete.rb
index ae685da729..7e796e22d6 100644
--- a/spree/core/app/workflows/spree/carts/complete.rb
+++ b/spree/core/app/workflows/spree/carts/complete.rb
@@ -80,8 +80,14 @@ module Spree
# A draft leaves before FINALIZE, so the document that phase files is
# filed here — otherwise it charged tax that never reached the return.
- # Never split, so it is the only order to file.
- @order = result.value
+ # A draft holding several sellers' goods divides like a checkout, and
+ # each of its orders is a sale of its own to file.
+ if result.value.is_a?(Spree::OrderGroup)
+ @order_group = result.value
+ @order = order_group.orders.order(:id).first
+ else
+ @order = result.value
+ end
external_step :commit_tax
halt!(result.value)
diff --git a/spree/core/spec/models/spree/product/scopes_spec.rb b/spree/core/spec/models/spree/product/scopes_spec.rb
index 80570632cb..3878173ec4 100644
--- a/spree/core/spec/models/spree/product/scopes_spec.rb
+++ b/spree/core/spec/models/spree/product/scopes_spec.rb
@@ -156,12 +156,15 @@ describe 'Product scopes', type: :model do
create_list(:product, 3, categories: [create(:category)])
end
- # Products sharing a minimum position have no defined order between them.
it 'orders products by ascending taxons minimum position' do
- products = ordered_products.to_a
-
- expect(products.first(2)).to contain_exactly(product_2, product_5)
- expect(products.drop(2)).to eq([product_4, product_6, product_3, product_1])
+ expect(ordered_products).to eq(
+ [
+ product_2, product_5, # position: 1
+ product_4, # position: 2
+ product_6, product_3, # position: 3
+ product_1 # position: 4
+ ]
+ )
end
end
diff --git a/spree/core/spec/workflows/spree/carts/complete_spec.rb b/spree/core/spec/workflows/spree/carts/complete_spec.rb
index 0d75c56bb9..6f9ade7569 100644
--- a/spree/core/spec/workflows/spree/carts/complete_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/complete_spec.rb
@@ -436,6 +436,27 @@ module Spree
expect(provider).to have_received(:commit).with(draft)
end
+ it 'files each order of a draft divided between sellers' do
+ draft = create(:order_ready_to_ship, store: store, line_items_count: 2)
+ draft.update_columns(status: 'draft', completed_at: nil, payment_status: nil)
+ draft.line_items.reload.zip(create_list(:seller, 2, :approved, store: store)).each do |line_item, seller|
+ line_item.variant.update!(seller: seller)
+ line_item.update_columns(seller_id: seller.id)
+ end
+ draft.reload.recalculate_totals!
+ draft.payments.destroy_all
+ create(:payment, order: draft, status: 'completed', amount: draft.reload.total)
+ filed = []
+ provider = instance_double(Spree::TaxProvider::Internal, estimate: nil)
+ allow(provider).to receive(:commit) { |placed| filed << placed }
+ allow_any_instance_of(Spree::Order).to receive(:tax_provider).and_return(provider)
+
+ result = described_class.call(cart: draft.reload)
+
+ expect(result.value).to be_a(Spree::OrderGroup)
+ expect(filed).to match_array(result.value.orders.to_a)
+ end
+
# An empty list, not nil: the reader has to tell "found no claim" apart
# from an order placed before the column existed.
it 'freezes an empty list when the sale claimed no exemption' do