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.

Give every company record one address, not two

Łukasz Adamczyk86ee92aac936
diff --git a/docs/plans/6.0-tax-provider.md b/docs/plans/6.0-tax-provider.md
index 43453d0182..30f94dfd35 100644
--- a/docs/plans/6.0-tax-provider.md
+++ b/docs/plans/6.0-tax-provider.md
@@ -1265,17 +1265,32 @@ end
```
GET/POST /api/v3/admin/companies
-PATCH/DELETE /api/v3/admin/companies/:id
-POST /api/v3/admin/companies/:company_id/locations
-PATCH/DELETE /api/v3/admin/company_locations/:id
-POST /api/v3/admin/company_locations/:location_id/contacts
-DELETE /api/v3/admin/company_contacts/:id
+GET/PATCH/DELETE /api/v3/admin/companies/:id
+
+GET/POST /api/v3/admin/companies/:company_id/locations
+GET/PATCH/DELETE /api/v3/admin/company_locations/:id
+
+GET/POST /api/v3/admin/company_locations/:location_id/contacts
+GET/DELETE /api/v3/admin/company_contacts/:id
+
+GET/POST /api/v3/admin/companies/:company_id/tax_identifiers
+GET/PATCH/DELETE /api/v3/admin/companies/:company_id/tax_identifiers/:id
+POST /api/v3/admin/companies/:company_id/tax_identifiers/:id/validate
GET/POST /api/v3/admin/companies/:company_id/tax_exemption_certificates
-PATCH/DELETE /api/v3/admin/companies/:company_id/tax_exemption_certificates/:id
+GET/PATCH/DELETE /api/v3/admin/companies/:company_id/tax_exemption_certificates/:id
PATCH /api/v3/admin/companies/:company_id/tax_exemption_certificates/:id/verify
+PATCH /api/v3/admin/companies/:company_id/tax_exemption_certificates/:id/revoke
+GET /api/v3/admin/companies/:company_id/tax_exemption_certificates/:id/download
```
+**Why children split across two prefixes.** A child is listed and created under the parent you arrived
+from, then read and written by its own id. That is not inconsistency: contacts cannot nest under
+`companies/:id/locations/:id` without breaching the two-level cap in `6.0-admin-api.md`, so
+`company_locations/:id` has to exist as a path regardless — and once it does, the branch's own member
+actions belong there. It follows the returns precedent, where a resource lives at both prefixes with a
+different job at each. Every record has exactly one `show`.
+
Certificate creation takes a direct-upload signed blob for `document`, as the CSV importer does.
Transitions are member PATCH actions, per the returns plan's convention — no destroy on a verified
certificate, revoke instead. Scope-gated on `write_customers` (a company is a customer record), and
diff --git a/spree/api/config/routes.rb b/spree/api/config/routes.rb
index 799a5b0be5..4dffd902c2 100644
--- a/spree/api/config/routes.rb
+++ b/spree/api/config/routes.rb
@@ -403,7 +403,11 @@ Spree::Core::Engine.add_routes do
# parent and then addressed directly, so a caller holding a branch id
# does not have to know which company it belongs to.
resources :companies do
- resources :locations, controller: 'companies/locations', only: [:index, :show, :create]
+ # Listed and created under the company you arrived from; read and
+ # written by their own id below, which has to exist anyway as the
+ # parent path for contacts (three levels of nesting is over the cap —
+ # docs/plans/6.0-admin-api.md).
+ resources :locations, controller: 'companies/locations', only: [:index, :create]
# The business's own registration — the number on its invoices, which
# outranks the buyer's own. Same shape as the customer's.
@@ -426,7 +430,7 @@ Spree::Core::Engine.add_routes do
end
resources :company_locations, only: [:show, :update, :destroy] do
- resources :contacts, controller: 'company_locations/contacts', only: [:index, :show, :create]
+ resources :contacts, controller: 'company_locations/contacts', only: [:index, :create]
end
resources :company_contacts, only: [:show, :destroy]