Skip to content

Commit

Permalink
Merge pull request #1068 from magiclabs/convert-old-broken-migration-…
Browse files Browse the repository at this point in the history
…to-rake-task

Upgrade path for shipping rate tax data
  • Loading branch information
jhawthorn committed Apr 19, 2016
2 parents 99c2c5d + f432741 commit 614759f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
The shipping rate taxer class can be exchanged for a custom estimator class
using the new Spree::Appconfiguration.shipping_rate_taxer_class preference.

Shipping rates for completed orders before this change will, unfortunately, not be shown
with their taxes from Solidus 1.3 onwards. If you do change the shipping rate on an
old order, its taxes will be calculated correctly, though.

https://github.com/solidusio/solidus/pull/904

In order to convert your historical shipping rate taxation data, please run
`rake solidus:upgrade:one_point_three` - this will create persisted taxation notes
for historical shipping rates. Be aware though that these taxation notes are
estimations and should not be used for accounting purposes.

https://github.com/solidusio/solidus/pull/1068

* Deprecate setting a line item's currency by hand

Previously, a line item's currency could be set directly, and differently from the line item's
Expand Down

This file was deleted.

17 changes: 17 additions & 0 deletions core/lib/tasks/migrations/migrate_shipping_rate_taxes.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace :solidus do
namespace :migrations do
namespace :migrate_shipping_rate_taxes do
task up: :environment do
puts "Adding persisted tax notes to historic shipping rates"
Spree::ShippingRate.where.not(tax_rate_id: nil).find_each do |shipping_rate|
tax_rate = Spree::TaxRate.unscoped.find(shipping_rate.tax_rate_id)
shipping_rate.taxes.find_or_create_by!(
tax_rate: tax_rate,
amount: tax_rate.compute_amount(shipping_rate)
)
end
Spree::ShippingRate.where.not(tax_rate_id: nil).update_all(tax_rate: nil)
end
end
end
end
3 changes: 2 additions & 1 deletion core/lib/tasks/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ namespace :solidus do
namespace :upgrade do
desc "Upgrade Solidus to version 1.3"
task one_point_three: [
'solidus:migrations:assure_store_on_orders:up'
'solidus:migrations:assure_store_on_orders:up',
'solidus:migrations:migrate_shipping_rate_taxes:up'
] do
puts "Your Solidus install is ready for Solidus 1.3."
end
Expand Down

0 comments on commit 614759f

Please sign in to comment.