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

add condition on warning_forfeit_remaining_amount note #11694

Conversation

prateek0411999
Copy link
Contributor

@prateek0411999 prateek0411999 commented Oct 20, 2023

What? Why?

Resolves the issue where the **warning_forfeit_remaining_amount note ** ->(Note: if your order total is less than your voucher you may not be able to spend the remaining value.') was still visible even when the percentage voucher was applied.

What should we test?

  1. As an enterprise manager, Set up a percentage voucher on a shop (make sure the feature toggle "vouchers" is activated"
  2. As a shopper, apply that voucher to step 2 of the checkout process - the message should not be displayed
  3. Again check with a (non percentage/flat) voucher and check the message is showing up.

Changelog Category:

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled
Screenshot 2023-10-20 at 1 31 17 PM Screenshot 2023-10-20 at 1 30 50 PM

Copy link
Collaborator

@rioug rioug 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 your contribution ! 🙏
Could you address the feedback ? let me know if anything isn't clear, thanks!

create(:voucher_percentage_rate, code: 'percent_code',
enterprise: percent_order.distributor, amount: 20)
}
let(:adjustment) { flat_voucher.create_adjustment(flat_voucher.code, order) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I can see this is not used, could you remove this line ?


def type_flat?
type == 'Vouchers::FlatRate'
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Voucher is meant to be an abstract class, ie it is meant to be subclassed to implement a "concrete voucher" in our case flat rate and percentage voucher (I should have added some comment around that to make it clearer). That said, Voucher shouldn't know what type of voucher are going to exist. By adding this method you created a dependency on Vouchers::FlatRate meaning it is implying that Vouchers::FlatRate exists. In general it's better to avoid this.
A simpler solution is to use is_a? method in the view.

To be fair in our code base, we do have an explicit dependency on Vouchers::FlatRate, as it is the default type in the vouchers table, meaning we actually need Vouchers::FlatRate to be defined :

t.string "type", limit: 255, default: "Vouchers::FlatRate", null: false

@@ -11,7 +11,7 @@
= link_to t("split_checkout.step2.voucher.remove_code"), voucher_adjustment_path(id: voucher_adjustment.id), method: "delete", data: { confirm: t("split_checkout.step2.voucher.confirm_delete") }

- # This might not be true, ie payment method including a fee which wouldn't be covered by voucher or tax implication raising total to be bigger than the voucher amount ?
- if voucher_adjustment.originator.amount > order.pre_discount_total
- if ((voucher_adjustment.originator.amount > order.pre_discount_total) && voucher_adjustment.originator.type_flat?)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need the parenthesis here. And as mentioned in the comment above, the simpler solution is to use is_a?

Suggested change
- if ((voucher_adjustment.originator.amount > order.pre_discount_total) && voucher_adjustment.originator.type_flat?)
- if voucher_adjustment.originator.amount > order.pre_discount_total && voucher_adjustment.originator.is_a?(Vouchers::FlatRate)

Comment on lines 6 to 7
let(:flat_order) { create(:order_with_distributor, total: 10) }
let(:percent_order) { create(:order_with_distributor, total: 10) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Each test should be able to be run independently, ie not depend on each other. This means you could just use the same order for both your test and it will work. Not a blocker though.

@prateek0411999
Copy link
Contributor Author

@rioug thanks for reviewing the MR, will push the necessary changes shortly.

@prateek0411999 prateek0411999 force-pushed the bugfix/11666-warning_forfeit_remaining_amount branch from 0656838 to a113b5b Compare October 23, 2023 05:16
@prateek0411999 prateek0411999 requested a review from rioug October 23, 2023 05:32
Copy link
Collaborator

@rioug rioug 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 now ! 👍

I can see that you rewrote your git history. Whilst it's a good thing to keep the git history clean, it's better no to do it once your code has been reviewed. It results in lost context, other reviewer won't be able to see the process that got us to the current solution.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great spec, thank you!

This will next be manually tested, then merged when successful.

@prateek0411999
Copy link
Contributor Author

@dacook thanks.

@filipefurtad0 filipefurtad0 self-assigned this Oct 26, 2023
@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Oct 26, 2023
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Oct 26, 2023

Hey @prateek0411999 , welcome 🎉

Thanks for the PR, and the spec!

So, the warning is displayed if the order total is less than the voucher value (regardless of being flat or not). Indeed, this way, we can see the warning, for a percentage voucher:

image

After staging this PR:
image

We can see that the warning is not displayed now, within the same scenario.

Regression test - It still is displayed for flat amount vouchers
image

Thanks for this improvement!
Merging.

@filipefurtad0 filipefurtad0 merged commit b67acaa into openfoodfoundation:master Oct 26, 2023
52 checks passed
@filipefurtad0 filipefurtad0 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
4 participants