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

WIP remove Spree::Zone.default_tax and associated code paths #1537

Closed
wants to merge 3 commits into from

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Oct 19, 2016

Previously, Spree and Solidus had code paths for tax reimbursements:
If an orders tax address was outside the "default tax zone" and value added tax
applied from that default tax zone, Solidus would create negative tax
adjustments, i.e. Reimbursements. Since Solidus 1.3, the taxation system
has been overhauled and we do not need this hack anymore. Taking it out is
roughly this commit. It can (and should) be broken up into smaller commits,
and we need to come up with a good deprecation plan for many of these methods.

@mamhoff mamhoff force-pushed the remove-default-tax-zone branch from 08fa704 to 105cf76 Compare October 19, 2016 15:19
@jhawthorn jhawthorn added this to the 2.1.0 milestone Nov 1, 2016
@mamhoff mamhoff force-pushed the remove-default-tax-zone branch from 105cf76 to e858943 Compare November 5, 2016 10:52
Previously, Spree and Solidus had code paths for tax reimbursements:
If an orders tax address was outside the "default tax zone" and value added tax
applied from that default tax zone, Solidus would create negative tax
adjustments, i.e. Reimbursements. Since Solidus 1.3, the taxation system
has been overhauled and we do not need this hack anymore.
@mamhoff mamhoff force-pushed the remove-default-tax-zone branch from e858943 to b27de36 Compare November 5, 2016 11:14
Spree::Zone.match suffers of several shortcomings:
1. It's badly named. What's matching?
2. It returns arbitrary results (why does smaller match more?)
3. It's expensive database-wise.
4. It's only used in now deprecated `Spree::Order.tax_zone`.

This commit deprecates it, too.
This method checks whether a zone is wholly contained in another zone.
Since zones should really be used as auxiliary constructs for finding
out which shipping methods or tax rates apply to a particular address,
comparing zones to zones is unnecessary.
@mamhoff mamhoff force-pushed the remove-default-tax-zone branch from 33b4cec to 7ca8081 Compare November 5, 2016 13:26
@mamhoff mamhoff changed the title WIP remove Spree::Zone.default_tax and associated code paths Remove Spree::Zone.default_tax and associated code paths Nov 7, 2016
@mamhoff mamhoff changed the title Remove Spree::Zone.default_tax and associated code paths WIP remove Spree::Zone.default_tax and associated code paths Nov 7, 2016
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Although I know that this code is dead and we've done a lot to prevent errors. But still I'm anxious to delete so much code (especially money related code).

Maybe we just should deprecate another round and remove this in 3.0 instead?

WDYT?

In versions prior to Solidus 1.3, instead of changing prices for
different VAT territories, there was an assumption that backend
prices would include VAT, and the tax system was tasked with "refunding" that. This has since been changed so we could now delete a lot of code paths that performed these "refunds".

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be enough the link to the 1.3 blog post.

@@ -227,7 +227,7 @@ def backordered?
# Returns the relevant zone (if any) to be used for taxation purposes.
# Uses default tax zone unless there is a specific match
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this outdated comment

@@ -42,13 +41,17 @@ class Zone < Spree::Base
self.whitelisted_ransackable_attributes = ['description']

def self.default_tax
where(default_tax: true).first
Spree::Deprecation.warn("There is no default tax zone anymore.", caller)
all.detect { |zone| zone.try(:default_tax) }
Copy link
Member

Choose a reason for hiding this comment

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

If the column is gone, there is no need for this anymore, right? Maybe we should keep the column for at least one minor version instead?

if Spree::Zone.where(default_tax: true).any?
raise DefaultTaxZonePresent, "Please run the the solidus:migrations:create_vat_prices rake task."
end
remove_column :spree_zones, :default_tax, :boolean, default: false
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we keep the column for another round?

# Returns the most specific matching zone for an address. Specific means:
# A State zone wins over a country zone, and a zone with few members wins
# over one with many members. If there is no match, returns nil.
def self.match(address)
Spree::Deprecation.warn("Spree::Zone.match is deprecated. Please use Spree::Zone.for_adress instead.", caller)
Copy link
Contributor

Choose a reason for hiding this comment

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

small typo. should be Spree::Zone.for_address

@peterberkenbosch
Copy link
Contributor

public API does not change right? This cleans up so nicely :) I really like it. That being said, I think these kind of changes should be introduced very defensively.

@mamhoff mamhoff mentioned this pull request Nov 11, 2016
@mamhoff
Copy link
Contributor Author

mamhoff commented Nov 11, 2016

Closing in favour of #1586 .

@mamhoff mamhoff closed this Nov 11, 2016
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.

4 participants