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
Fix bug on calculator_decorator line_items_for where input is line_item with a nil order #3072
Fix bug on calculator_decorator line_items_for where input is line_item with a nil order #3072
Conversation
b71b505
to
76abeaf
Compare
76abeaf
to
8feca27
Compare
8feca27
to
b0d1843
Compare
I have tested this locally, buying 3 items of a product of 5 kgs and paying enterprise fees per kg and shipping fees also per kg and with a payment method with "flexible rate" (first item one price, following items another price). All the calculations are correct as far as I understand these things:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that both #2932 and #3072 are not supposed to change the current calculator behaviour?
Considering the following:
- OC exchange with Weight calculator
- More than one line item in the order
It seems that #2932 changed the calculation for this type of order and then #3072 changes it back.
With #2932:
EnterpriseFee::PER_ORDER_CALCULATORS
does not include the weight calculator- The weight-based fee is calculated per line item for which the fee is applicable
- But the calculation per line item uses the total weight of the order, not just the line item, so the fee is bigger
I think the current behaviour is the correct one, but if I'm correct, we need to know what should be done regarding #2932.
nice @kristinalim, thanks for your review! I went back to reading the enterprise fees code and validated that #3072 does introduce a bug on orders with multiple line items with weight in order cycles with enterprise fees that use a weight calculator. I immediately went to the main live instances to see how many cases we have, lucky we are, this is only used in FR live in the "Hub demo Open Food France" (I checked AUS, UK, FR and ES). This was the SQL I used: In @myriamboure 's test on #3072, here: I tested locally in master and this PR and it's obviously broken in master and it is working in this PR. So, the only bad news is the bug in production.
|
…em with an nil order. Adapted line_items_for so that weight_calculator.line_items_for could be removed.
e1ef698
to
38ff997
Compare
I had to rebase the PR to get the google maps pending specs out of the way... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luisramos0 Could you also check for coordinator fees that use Calculator::Weight
? And maybe, even just for active order cycles, we should check any order status and not only completed orders. Crossing fingers that there are no matches.
I think these should be also be done:
- Create an issue to add specs that would test for this bug, because IMO the
line_items_for
method is difficult to visualize and we might make the same mistake. - Does the SQL check need to be done again right before deploying to each of the instances?
- Update release notes to mention that this bug has been fixed.
What do you think?
thanks @kristinalim I agree. I will do that. |
So, updating the checks:
Checked UK, AUS, ES and FR. Nothing detected except in France where there is one enterprise using this in 2016/2017 and then the only 2 test enterprises using it as well. I am trying to write the automated test to validate this case, in progress. |
ok @kristinalim |
@kristinalim can you please re-review this one? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the late response here - I didn't notice this mention among the recent notifications. (Need to update my work process.)
@luisramos0 This looks great. I wrote comments on very minor issues, but happy with this PR.
add_enterprise_fee admin_fee | ||
|
||
cart_service = CartService.new(order) | ||
cart_service.populate(variants: { product_fee.variants.first.id => 3, product_tax.variants.first.id => 5 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quantity of 5 here really confused me because the cart total was only computing for 3 units. If the product factory's on_hand
value of 3 for product_tax
is important in this test, what do you think of specifying this attribute when defining product_tax
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, good catch. I dont see (and cant remember either) any reason to have that quantity capped in this test. I just changed it to 3 in this line! Maybe it was just a typo in the first place.
I fixed the double quotes as well.
I force-pushed the last commit with these fixes.
also, agree, we should have a extra re-review on this tricky PR.
thanks!
@sauloperez There have been important changes since your approval. I'll request another review from you to unmark it, and you or another dev can do the second review. |
37e7595
to
2893f1c
Compare
Nice! now it's way easier to understand. |
Testing Notes
One possibly related glitch I noticed:
Pre-existing glitch I noticed:
https://docs.google.com/document/d/178DpKby-lpQMkMX_AF2UCzfXejiMlzHUVmzFU14XdFY/edit# |
I didn't see any errors while Sally was testing. Sally found that glitch is pre-existing. So this is ready to go. |
What? Why?
Take 2 on weight calculator (#2932), this time for a more fundamental change (remove line_items_for method all together).
The specific issue we address in the calculator is that the passed "object" could be a line_item that would "respond? :order" but with a nil order. In this case, the option to return [line_item] is the correct option.
What should we test?
Functional: we changed the way calculators work internally so we need to review all the points where calculators are used, not just weight. We need to review shipping fees, enterprise fees, and weight line items. I dont think it's possible these changes will break the calculations (the numbers), if something is wrong, things will just not work, no fees calculated, for example.
Tech: there could be a class loading issue with this PR, we need to watch in staging if there are any class loading error messages.
Specs: All specs related to calculators are green in the 2-0 branch. Fixes tests in spree upgrade issue #3025
Release Notes
Changelog Category: Fixed
Fixed bug in fees calculated based on weight. Bug introduced in previous release (#3072). This bug was applicable to orders with multiple line items with weight in order cycles with enterprise fees that use a weight calculator (this was validated in live environments and we didn't detect any case where this was applicable)