-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TaxRate M-M TaxCategory #1851
Merged
jordan-brough
merged 4 commits into
solidusio:master
from
vladstoick:tax_category_tax_rate_relation
May 23, 2017
Merged
TaxRate M-M TaxCategory #1851
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ed0fd82
Temporarily disable specs that create TaxRates
vladstoick c0f8394
Migrate TaxRate, TaxCategory relation to a M-M
vladstoick 1c5c5de
Re-enable specs that create tax rates
vladstoick 8033843
Update CHANGELOG with TaxRate<->TaxCategory change
vladstoick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Spree | ||
class TaxRateTaxCategory < Spree::Base | ||
belongs_to :tax_rate, class_name: Spree::TaxRate, inverse_of: :tax_rate_tax_categories | ||
belongs_to :tax_category, class_name: Spree::TaxCategory, inverse_of: :tax_rate_tax_categories | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
core/db/migrate/20170412103617_transform_tax_rate_category_relation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class TransformTaxRateCategoryRelation < ActiveRecord::Migration[5.0] | ||
class TaxRate < ActiveRecord::Base | ||
self.table_name = "spree_tax_rates" | ||
end | ||
|
||
class TaxRateTaxCategory < ActiveRecord::Base | ||
self.table_name = "spree_tax_rate_tax_categories" | ||
end | ||
|
||
def up | ||
create_table :spree_tax_rate_tax_categories do |t| | ||
t.integer :tax_category_id, index: true, null: false | ||
t.integer :tax_rate_id, index: true, null: false | ||
end | ||
|
||
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_categories, column: :tax_category_id | ||
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_rates, column: :tax_rate_id | ||
|
||
TaxRate.where.not(tax_category_id: nil).find_each do |tax_rate| | ||
TaxRateTaxCategory.create!( | ||
tax_rate_id: tax_rate.id, | ||
tax_category_id: tax_rate.tax_category_id | ||
) | ||
end | ||
|
||
remove_column :spree_tax_rates, :tax_category_id | ||
end | ||
|
||
def down | ||
add_column :spree_tax_rates, :tax_category_id, :integer, index: true | ||
add_foreign_key :spree_tax_rates, :spree_tax_categories, column: :tax_category_id | ||
|
||
TaxRate.find_each do |tax_rate| | ||
tax_category_ids = TaxRateTaxCategory.where(tax_rate_id: tax_rate.id).pluck(:tax_category_id) | ||
|
||
tax_category_ids.each_with_index do |category_id, i| | ||
if i.zero? | ||
tax_rate.update!(tax_category_id: category_id) | ||
else | ||
new_tax_rate = tax_rate.dup | ||
new_tax_rate.update!(tax_category_id: category_id) | ||
end | ||
end | ||
end | ||
|
||
drop_table :spree_tax_rate_tax_categories | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, you might want to use an internationalized separator, as not all locales will work with a comma separated list. Most will though, so I won't insist. :)