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

Remove tax refunds #2196

Merged
merged 9 commits into from
Sep 11, 2017
Merged

Remove tax refunds #2196

merged 9 commits into from
Sep 11, 2017

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Aug 31, 2017

This takes inspiration from #2194 - if we can remove that migratory task because we assume people have run it when they were on 1.3 or 1.4, we must also be able to remove all the code paths around tax "refunds" that are only run when a default tax zone is present.

For a bit of background: In versions of Solidus pre-1.3, a "default tax zone" existed. If that zone had a VAT-style tax rate, all prices in the system were assumed to include VAT, making it necessary to refund that via a Franken-adjustment.

We have sinced moved to a system where we have country-dependent prices, and the default tax zone doesn't exist anymore or mean anything.

I'll rebase on master once #2194 is merged.

@mamhoff mamhoff requested a review from tvdeyen August 31, 2017 20:29
@mamhoff mamhoff force-pushed the remove-tax-refunds branch 2 times, most recently from 55603b8 to 5318a36 Compare August 31, 2017 22:14
@jasonfb
Copy link

jasonfb commented Sep 1, 2017

I'm really curious, what's a "Franken-adjustment"? I couldn't find that term on Google (but lots of references to American Senator Al Franken and tax reform). Is than an accounting term?

Or do you just mean like "frankenstein," like a "big messy thing?"

@mamhoff
Copy link
Contributor Author

mamhoff commented Sep 1, 2017

jasonfb: It's a reference to Frankenstein the movie, and yeah, it's a messy thing. It's an included tax adjustment (which by definition does not change the line item's amount) with a negative amount, which - because of its negative amount - is counted as additional, changing the line item's amount. If that sounds confusing to you, that's because it is.

Since Solidus 1.3, these code paths are not touched anymore. They can safely be deleted.
@@ -16,7 +16,6 @@ def compute_order(order)
line_items_total = matched_line_items.sum(&:discounted_amount)
if rate.included_in_price
order_tax_amount = round_to_two_places(line_items_total - ( line_items_total / (1 + rate.amount) ) )
refund_if_necessary(order_tax_amount, order.tax_address)
Copy link
Contributor

@jhawthorn jhawthorn Sep 6, 2017

Choose a reason for hiding this comment

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

Is this going to do the right thing with this removed? If so, the assignment on the previous line should be removed to make it more obvious that it is just being returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it will. And also, yes the assignment is unnecessary. I'm not sure we need to ship this entire method any longer, either, as it we don't do taxation on orders since Spree 2.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amended!

end

(rates_for_order(order) + default_rates_with_unmatched_tax_category).uniq
rates_for_order(order)
Copy link
Member

Choose a reason for hiding this comment

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

Could we reduce the number of methods here or are these semi-public interfaces? In terms of private, but widely used by extensions/shops?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can reduce them. I chose to keep applicable_rates, because that's what's being used in calculators, and remove rates_for_order. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, but I think we can remove even more.

applicable_rates is never called outside of this helper. The calculators only use rates_for_item.

If we also move sum_of_included_tax_rates into Spree::Calculator::DefaultTax (the only place where this is called) we can reduce the module to:

module Spree
  module Tax
    module TaxHelpers
      private

      def rates_for_item(item)
        rates = Spree::TaxRate.for_address(item.order.tax_address)
        rates.select do |rate|
          rate.tax_categories.map(&:id).include?(item.tax_category_id)
        end
      end
    end
  end
end

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

And maybe we should rename the method to something meaningful then

tax_rates_for(item) maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not realize the module is only called via rates_for_item by now, good catch! However, I did not change the name of the method. While it's not grammatically perfect, it conveys what the method does, and this way I don't have to change the calling code.

I kept the ivar caching, but removed the two superfluous methods.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect! Thanks

This code has not been in use since Solidus 1.3. It can safely be deleted.
We don't create shipping rate taxes with negative amounts any longer.
This method has not been used since Solidus 1.3. It's been deprecated long enough
and can safely be deleted.
…ntains?

All of these methods have not been in use since Solidus 1.3. They can safely be deleted.
No new tax refunds can be created since Solidus 1.4, and the strings generated here
are by now stored in the database.
This commit has not been relevant since Solidus 1.3
This column has been empty since Solidus 1.3.
We only call Spree::Tax::TaxHelpers#rates_for_item from multiple
places, so this commit reduces the module to one private method.

I chose to keep the instance variable caching to reduce database requests.
Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

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

Looks good to me, looks like all the code removed isn't anything we'd ever want people to run. (aka the old tax system)

@mamhoff mamhoff merged commit c9c9f05 into solidusio:master Sep 11, 2017
@mamhoff mamhoff deleted the remove-tax-refunds branch September 11, 2017 16:26
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.

5 participants