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

Deprecate order tax zone #1543

Merged
merged 3 commits into from
Nov 2, 2016

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Oct 20, 2016

This PR is two commits which are extracted from #1537, so that the Giant Removal is hopefully easier to understand.

First, its a fix to promotion_handler/coupon_spec, which had weird spec setup in places that led to hard-to-debug errors. Second, it's deprecating Spree::Order#tax_zone, which is conceptually a terrible idea and rather expensive to use.

With the deprecation, I can also safely drop extra behaviour to Spree::Order#reload. Yay!

@mamhoff mamhoff force-pushed the deprecate-order-tax-zone branch from a336321 to 7b3f26e Compare October 20, 2016 17:25
This commit removes call to `Spree::Order#tax_zone` from the codebase.

These calls are problematic, because whenever we have to check whether
a zone includes another zone entirely, we have to iterate over all of
both zones members. Really, it's enough to check whether the order's tax
address is within the desired zone (for a taxation or shipping zone).

This also comes with a number of fixes in specs where calls to `order.tax_zone`
were abused for test setup.
@mamhoff mamhoff force-pushed the deprecate-order-tax-zone branch from 7b3f26e to d5320e3 Compare October 20, 2016 17:51
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.

Great stuff. Like how it simplifies things.

I only have some nit picks about lots of law of Demeter violations (only talk to your immediate neighbor). But as you mostly doing a search and replace here, we can address this in a later PR. But I saw to many "undefined method yada for NilClass" errors in my life, because of expectations made on the objects being correctly build. They're often enough not.

Can be merged in my opinion


@order = Spree::Order.create!(store: store)
allow(@order).to receive_messages coupon_code: "10off"
expect(order).to receive(:tax_address).at_least(:once).and_return(Spree::Tax::TaxLocation.new(country: zone.countries.first))
Copy link
Member

Choose a reason for hiding this comment

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

Haha. Great. Much better to read and understand 👏🏻

@@ -141,7 +141,9 @@
end

it "shows correct tax amount" do
Copy link
Member

Choose a reason for hiding this comment

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

I like to use aggregate_failures when using multiple expectations

@jrochkind
Copy link
Contributor

Without Spree::Order#tax_zone, what's the right way to tell what tax zone an Order is in for calculating taxes? Am I missing something?

@mamhoff
Copy link
Contributor Author

mamhoff commented Oct 27, 2016

@jrochkind An order's shipping address might actually match several zones with tax rates attached. It's far easier to check which zones have the state or country of the shipping address, and then get the tax rates for them.

The way this worked before was:

We run Zone.match, get an array of zones and arbitrarily select one of them and designate it the tax zone. THEN, we do a matching of zones against that zone, where we had to check whether the rates zones wholly contain the order's tax zone, and it's all really unnecessarily complex. If you feel like, watch my talk on the subject: https://www.youtube.com/watch?v=BRnY-BidYRM :)

@jhawthorn jhawthorn added this to the 2.1.0 milestone Nov 1, 2016
@jhawthorn jhawthorn merged commit 9e31d79 into solidusio:master Nov 2, 2016
@jhawthorn
Copy link
Contributor

jhawthorn commented Nov 2, 2016

Thanks Martin. This is much more sensible.

Looking forward to the follow-up removal of default_tax, which should simplify a little more and remove a query or two.

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