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

Move all Calculators from spree to OFN and out of the Spree namespace #5613

Merged
merged 21 commits into from
Jul 13, 2020

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented Jun 15, 2020

What? Why?

Closes #5687
Something I wanted to do for a long time.
We move all needed code from core/app/models/spree/calculator to OFN. And then we move what's in app/models/spree/calculator to app/models/calculator where there are already 2 calculators 👌

What should we test?

First of all we need to verify that the calculators defined before this PR is deployed will still work correctly after the deployment of this PR. For example, create an order with some fees (with specific calculators, for example, flat_rate). After deploying this PR, go to admin/orders and press "Update and recalculate fees", the fees should still be correct.

We need to make a simple verification of each calculator in each part of the app where they are used. Maybe not a multiplication of these two things but for example:

  • test FlatPercentItemTotal and FatRate and PerItem calculators on a shipping method
  • test PriceSack on a payment method
  • test FlexiRate on an enterprise fee
  • test DefaultTax calculator in Tax Rates admin/tax_rates/ verify the tax is still applied. The code was just moved, not changed, so we don't really need to test all the details here.

Release notes

Changelog Category: Changed
Simplified a lot the calculators code used to calculate taxes and fees in OFN.

@luisramos0 luisramos0 changed the title Calculators Move all Calculators from spree to OFN and out of the Spree namespace Jun 15, 2020
@luisramos0 luisramos0 self-assigned this Jun 15, 2020
@luisramos0 luisramos0 marked this pull request as draft June 15, 2020 21:23
@luisramos0 luisramos0 marked this pull request as ready for review June 16, 2020 16:51
@Matt-Yorkley
Copy link
Contributor

Relevant failing specs and a merge conflict, moving to in dev. Looks good though 😄

@luisramos0 luisramos0 force-pushed the calculators branch 2 times, most recently from fbfc5a8 to 2f28c39 Compare June 17, 2020 18:52
@luisramos0
Copy link
Contributor Author

yes, there was a problem in the last refactoring and also conflicts with #5492, all resolved now. Ready for review again.

Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

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

Neat! 👏

@luisramos0 luisramos0 force-pushed the calculators branch 2 times, most recently from c2c5090 to 1da1a39 Compare June 23, 2020 10:26
@luisramos0
Copy link
Contributor Author

rebased to resolve conflicts.

@luisramos0
Copy link
Contributor Author

rebased to resolve conflict in schema.rb

@Matt-Yorkley
Copy link
Contributor

More conflicts...

@luisramos0
Copy link
Contributor Author

ok, rebased to resolve conflicts. Ready for review again.

@luisramos0
Copy link
Contributor Author

build is good, just flaky.

@sauloperez
Copy link
Contributor

I just rebuilt it to get a green build. I think we can move it to test ready afterwards.

@luisramos0
Copy link
Contributor Author

It needs a second review, right?

@sauloperez
Copy link
Contributor

sauloperez commented Jul 9, 2020

yes, it does but... last time we heard from someone else was 22 days ago and I think most of the changes are rather simple.

@luisramos0
Copy link
Contributor Author

🎉 🎉 🎉 🎉

@filipefurtad0 filipefurtad0 self-assigned this Jul 12, 2020
@filipefurtad0 filipefurtad0 added pr-staged-fr staging.coopcircuits.fr and removed pr-staged-fr staging.coopcircuits.fr labels Jul 12, 2020
@filipefurtad0
Copy link
Contributor

Hey @luisramos0 ,

Thank your for the detailed testing notes!

Before staging this PR I've set enterprise fees, of all available kinds:

p1 - Flat percent (per item)
p2 - Weight (per kg)
p3 - Flat rate (per order)
p4 - Flat rate (per item)
p5 - Flexible rate (per item)
p6 - Price Sack

Test cases/steps:

  • Added these fees to the respective Order Cycle and placed an order (5 items of each product).
  • Checked the order confirmation

Then, I staged this PR:

  • Clicked "Updated and recalculate fees" on the previously placed order: the order total remains the same as before - OK
  • Placed a similar order as before (5 items of each product): the order total remains the same as before - OK
  • Observed that the fees applied per order - p3, p4, p6 - appear as "Admin & Handling" on /cart /checkout and invoice - OK

After setting "charges GST" in the for that hub, and by changing the Tax category of the different enterprise fees (inheriting from product or others) apply taxes over:

  • products and enterprise fees
  • only products
  • only enterprise fees

This worked as expected.

Also checked if calculators still work correctly on shipping/payment methods. I followed your testing notes:

  • checked FlatPercentItemTotal and FatRate and PerItem calculators on a shipping method
  • tested PriceSack and FlexibleRate on a payment methods

The calculators rendered the expected value for each order; fees operate on the price per item without including the respective enterprise fee, for example, Price Sack, or flat-percent - this is a known issue:

This PR really touches a lot of corners of the app!
But looks ready to go, so one step closer to "bye bye Spree" 🎉
Thanks Luis!

Please note that this PR was tested with the following failing spec:

rspec ./spec/models/variant_override_spec.rb:36 # VariantOverride scopes fetching variant overrides indexed by variant does not include overrides for soft-deleted variants

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Jul 13, 2020
@luisramos0 luisramos0 merged commit 9c8318d into openfoodfoundation:master Jul 13, 2020
@luisramos0
Copy link
Contributor Author

bam 💥 , merged
thanks Filipe!

@luisramos0 luisramos0 deleted the calculators branch July 13, 2020 14:16
@sauloperez
Copy link
Contributor

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.

[ByeBye Spree] Move Calculators to OFN
4 participants