Skip to content
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

Conversation

vladstoick
Copy link
Contributor

@vladstoick vladstoick commented Apr 21, 2017

Related to issue #1836

  • Transform TaxRate - TaxCategory in a many to many relation via TaxRateTaxCategory and update all places that used tax_rate.tax_category_id.
  • Update UI to use multiple from select2
    image
  • Fix all specs that use factory for tax_rate and update it to tax_categories: []

@@ -4,7 +4,10 @@ class TaxCategory < Spree::Base
validates :name, presence: true
validates_uniqueness_of :name, unless: :deleted_at

has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

@@ -4,7 +4,10 @@ class TaxCategory < Spree::Base
validates :name, presence: true
validates_uniqueness_of :name, unless: :deleted_at

has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch 3 times, most recently from c3babf9 to d8bb9e9 Compare April 21, 2017 10:41
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great improvement. One thing though: Would you mind moving the spec changes to be the first commit, mark them as pending, and re-enable them once you're done with the refactoring? We want to make sure every single commit passes CI, and the way the commits are organized here they won't, unfortunately.

Also, please have a look at Chris Beams guide on commit messages. Some of your commit messages have very long headings, and almost none give any background as to why you did the change.

<td class="align-center"><%=tax_rate.tax_category.try(:name) || Spree.t(:not_available) %></td>
<td class="align-center">
<% if tax_rate.tax_categories.any? %>
<%= tax_rate.tax_categories.map(&:name).join(", ") %>
Copy link
Contributor

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. :)

@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch 2 times, most recently from 9487529 to 3293845 Compare May 22, 2017 09:44
@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch from 3293845 to bdc504a Compare May 22, 2017 09:59
Copy link
Contributor

@jordan-brough jordan-brough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Left a couple minor comments.

TaxRate.find_each do |tax_rate|
tax_category_ids = TaxRateTaxCategory.where(tax_rate_id: tax_rate.id).pluck(:tax_category_id)

if tax_category_ids.count == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Don't need this if right? The logic in the else would handle it?

@@ -4,7 +4,9 @@ class TaxCategory < Spree::Base
validates :name, presence: true
validates_uniqueness_of :name, unless: :deleted_at

has_many :tax_rates, dependent: :destroy, inverse_of: :tax_category
has_many :tax_rate_tax_categories, class_name: Spree::TaxRateTaxCategory, dependent: :destroy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since inverse_of is currently broken in Solidus it's probably worth adding it to these since we're starting fresh with them?

@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch from bdc504a to 877bd25 Compare May 22, 2017 10:23
Copy link
Contributor

@jordan-brough jordan-brough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 assuming specs are green

@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch from 877bd25 to a2f5206 Compare May 22, 2017 10:48
@vladstoick vladstoick closed this May 22, 2017
@vladstoick vladstoick deleted the tax_category_tax_rate_relation branch May 22, 2017 10:48
@vladstoick vladstoick reopened this May 22, 2017
@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch 3 times, most recently from 9c6b3cb to 9337dcc Compare May 22, 2017 12:40
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Thanks for addressing my feedback :)

solidusio#1851 will change the
type of relation to a many to many so specs will temporarily need to
be skipped until changes are made to the specs.
Implements solidusio#1836

The current relation between TaxRate and TaxCategory can lead
to unnecessary tax rates if a store has multiple tax categories
and if it supports countries (such as Australia) that have a
standard tax rate. This means that for each TaxCategory, the store
will have an extra tax rate even if the percent is the same.

By transforming this relation to a M-M we can allow stores to
create tax rates that have multiple tax categories.
Specs have been disabled until changes to the relation between
TaxRate and TaxCategory have been updated.
@vladstoick vladstoick force-pushed the tax_category_tax_rate_relation branch from 7a66fff to 8033843 Compare May 23, 2017 09:40
@jordan-brough jordan-brough merged commit 154f3d5 into solidusio:master May 23, 2017
jordan-brough pushed a commit to Lostmyname/solidus that referenced this pull request Jun 2, 2017
solidusio#1851 will change the
type of relation to a many to many so specs will temporarily need to
be skipped until changes are made to the specs.
vladstoick added a commit to Lostmyname/solidus that referenced this pull request Aug 4, 2017
solidusio#1851 will change the
type of relation to a many to many so specs will temporarily need to
be skipped until changes are made to the specs.
jordan-brough pushed a commit to Lostmyname/solidus that referenced this pull request Dec 12, 2017
solidusio#1851 will change the
type of relation to a many to many so specs will temporarily need to
be skipped until changes are made to the specs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants