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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Split one tax rate's jurisdictions all or nothing
Łukasz Adamczykbb3ef32d8d31
diff --git a/spree/core/lib/tasks/tax_zones_migration.rake b/spree/core/lib/tasks/tax_zones_migration.rakeindex b12d8aa02b..624a4dd199 100644--- a/spree/core/lib/tasks/tax_zones_migration.rake+++ b/spree/core/lib/tasks/tax_zones_migration.rake@@ -38,20 +38,29 @@ namespace :spree doendfirst, *rest = jurisdictions- rate.update_columns(country_iso: first[:country_iso], state_code: first[:state_code], updated_at: Time.current)- converted += 1- rest.each do |jurisdiction|- Spree::TaxRate.insert(- rate.attributes.slice(*Spree::TaxRate.column_names).except('id', 'created_at', 'updated_at').merge(- 'country_iso' => jurisdiction[:country_iso],- 'state_code' => jurisdiction[:state_code],- 'created_at' => Time.current,- 'updated_at' => Time.current+ # One rate's split is all-or-nothing. Stamping the source before the copies+ # exist means an interrupted run leaves a converted rate whose other+ # jurisdictions were never created — and the next run skips it, because it+ # now carries a country. The merchant would be short a rate with nothing+ # saying so.+ ApplicationRecord.transaction do+ rate.update_columns(country_iso: first[:country_iso], state_code: first[:state_code], updated_at: Time.current)++ rest.each do |jurisdiction|+ Spree::TaxRate.insert(+ rate.attributes.slice(*Spree::TaxRate.column_names).except('id', 'created_at', 'updated_at').merge(+ 'country_iso' => jurisdiction[:country_iso],+ 'state_code' => jurisdiction[:state_code],+ 'created_at' => Time.current,+ 'updated_at' => Time.current+ ))- )- duplicated += 1+ endend++ converted += 1+ duplicated += rest.sizeendputs " Converted #{converted} tax rates, split #{duplicated} extra rate(s) off multi-jurisdiction zones, " \