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

Support for Colorado Delivery Fee (flat fee and order-level taxes) #4491

Merged
merged 9 commits into from
Sep 15, 2022

Conversation

adammathys
Copy link
Member

@adammathys adammathys commented Aug 5, 2022

❗ TODO

  • Add radio buttons for TaxRate#level enum to admin
  • Tweak descriptions for TaxRate#rate and TaxRate#calculator in admin
  • Add specs for order-level taxes
  • Rake task to automatically generate Colorado Delivery Fee stuff

Summary

Add support for the new Colorado Delivery Fee. This is achieved by making two small changes to the existing tax system:

  1. New Spree::Calculator::FlatFee calculator. Can be used to return a fixed amount that comes from an associated Spree::TaxRate.
  2. Spree::TaxRate#level enum to distinguish between item- and order-level tax rates. Item-level taxes remain the default, since we very rarely if ever want to use order-level tax rates.

These changes in additional to the recent work to support order-level taxes in Spree::OrderTaxation (#4477), makes it possible to configure a tax rate for the Colorado Delivery Fee.

Screen Shot 2022-08-05 at 2 18 26 PM

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the readme to account for my changes.

@waiting-for-dev
Copy link
Contributor

Hey @adammathys, it looks nice. How is it going? Do you need any help?

@waiting-for-dev waiting-for-dev added type:enhancement Proposed or newly added feature changelog:solidus_core Changes to the solidus_core gem Important Change labels Aug 25, 2022
@adammathys adammathys force-pushed the adammathys/flat-fee-taxes branch from 1c50314 to ac1faf2 Compare August 26, 2022 22:24
@adammathys
Copy link
Member Author

@waiting-for-dev I haven't had much time to work on this as of late, but I should be able to wrap up the remaining TODO items next week.

@github-actions github-actions bot added the changelog:solidus_backend Changes to the solidus_backend gem label Sep 2, 2022
@adammathys adammathys force-pushed the adammathys/flat-fee-taxes branch from 927b48c to f160208 Compare September 2, 2022 21:10
@adammathys adammathys marked this pull request as ready for review September 2, 2022 21:35
@adammathys adammathys force-pushed the adammathys/flat-fee-taxes branch 2 times, most recently from 055d51a to e9b55d9 Compare September 2, 2022 21:50
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require_dependency 'spree/calculator'
Copy link
Contributor

Choose a reason for hiding this comment

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

require_dependency has been deprecated. Anyway, why do we need it? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see it's also used in the other calculators. I wonder if it can be removed safely. However, feel free to ignore the comment as it's outside this PR's scope.

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

That's impressive work, @adammathys!

I've tried it locally with the data generated from the new task, and it looks like it applies the Colorado tax twice:

screenshot-localhost_3000-2022 09 08-11_55_51

Do you have an idea what might be going on?

Also, do you think it'd be challenging to update the label rendered if somebody sets "show_rate_in_label" to true?

@adammathys
Copy link
Member Author

adammathys commented Sep 8, 2022

@waiting-for-dev The double render is fixed by my two other PRs in the frontend repos. (solidusio/solidus_starter_frontend#242 and solidusio/solidus_frontend#11) It's a longstanding issue with the code where it'll double render any order-level tax adjustments. I believe it had gone unnoticed until now because we typically didn't have any.

I don't think it'd be too difficult to update the label if show_rate_in_label was set to true. We should be able to add some logic that checked the type of calculator since that would be the determining factor.

@waiting-for-dev
Copy link
Contributor

waiting-for-dev commented Sep 9, 2022

The double render is fixed by my two other PRs in the frontend repos.

Oh, sorry, I missed that. Thanks for pointing this out.

I don't think it'd be too difficult to update the label if show_rate_in_label was set to true. We should be able to add some logic that checked the type of calculator since that would be the determining factor.

What do you think of doing it as part of this PR to make the work complete here? Otherwise, we can follow up.

BTW, it'd be nice to add information about this change in the CHANGELOG, including the available task.

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

👏 great work Adam! I left a question about a possible small change.

backend/app/views/spree/admin/tax_rates/_form.html.erb Outdated Show resolved Hide resolved
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks for the excellent work @adammathys! I left a question but am super in favor of merging this.

core/app/models/spree/tax/tax_helpers.rb Outdated Show resolved Hide resolved
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks @adammathys! Approving, I'm fine even without that last comment, but not merging yet.

adammathys and others added 8 commits September 14, 2022 13:44
Very simple calculator that will always return the same amount. Will
hopefully be useful for the Colorado Delivery Fee, but might also be
usable for different fees that come  up.
We unfortunately need to introduce the concept of order-level tax rates
to handle the Colorado Delivery fee. (And maybe other similar things?)
The simplest solution is to add an enum to our TaxRate model to help
distinguish between rates that should be applied on an order-level and
our regular item-level taxes.

Co-Authored-By: Andrew Stewart <andrew@super.gd>
Updates TaxHelpers#rates_for_item to use our new enum to filter for
rates that only apply to items.

Co-Authored-By: Andrew Stewart <andrew@super.gd>
Looks for all order-level tax rates and computes order taxes based on
the ones matching the order's ship address and tax categories.
Just a simple radio input to help set the value in the admin.
Adds the translation entry for the class and makes a small tweak to the
tax rate calculator hint to explain the difference between the two
calculators.
Now that this field can be used in two different ways, as a percentage
or as a flat amount, we want to ensure the explanation is still helpful
for users.
Simple task that can be used to help setup all of the records necessary
for calculating the new Colorado Delivery Fee in stores.
Skips the logic for deciding if the "rate" should be shown in the label,
since that never makes sense for flat fee tax rates.
@adammathys adammathys force-pushed the adammathys/flat-fee-taxes branch from 7d2fc19 to d762e2e Compare September 14, 2022 20:44
@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Merging #4491 (d762e2e) into master (8052691) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4491      +/-   ##
==========================================
+ Coverage   85.55%   85.58%   +0.02%     
==========================================
  Files         569      570       +1     
  Lines       14653    14675      +22     
==========================================
+ Hits        12537    12559      +22     
  Misses       2116     2116              
Impacted Files Coverage Δ
core/lib/spree/app_configuration.rb 99.29% <ø> (ø)
core/app/models/spree/calculator/flat_fee.rb 100.00% <100.00%> (ø)
core/app/models/spree/tax/tax_helpers.rb 100.00% <100.00%> (ø)
core/app/models/spree/tax_calculator/default.rb 100.00% <100.00%> (ø)
core/app/models/spree/tax_rate.rb 100.00% <100.00%> (ø)
...ee/testing_support/factories/calculator_factory.rb 93.75% <100.00%> (+0.41%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@kennyadsl kennyadsl merged commit 23930a3 into solidusio:master Sep 15, 2022
@adammathys adammathys deleted the adammathys/flat-fee-taxes branch September 15, 2022 15:11
@waiting-for-dev
Copy link
Contributor

Thanks, @adammathys, that's great. It would be great to update the Changelog if you have the time, even if in a separate PR. I think this change is worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants