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

[vouchers] error moving between summary and cart pages #11117

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
04bbea5
Move voucher processing out of checkout controller
Matt-Yorkley Jun 1, 2023
60c0c54
Update create_adjustment to create with an amount of 0
rioug Jun 26, 2023
87790b2
Fix VoucherAdjustmentsService.calculate so we can call it mutiple time
rioug Jun 26, 2023
366cca7
Prevent voucher adjustment from bein updated when update is called
rioug Jun 26, 2023
ca7dcb8
Apply voucher after transitionning to the confirmation step
rioug Jun 26, 2023
edabc56
Add voucher calculation after updating an order
rioug Jun 26, 2023
a8062e9
Add a scenario to make sure voucher adjustment a recalculated
rioug Jun 26, 2023
789ce39
Fixing Rubocop errors
rioug Jun 26, 2023
751056b
As per review comment, spell out voucher code when entering a voucher
rioug Jun 30, 2023
4127119
Per review, Makes quantity change more explicit
rioug Jun 30, 2023
3d9542f
Per review, rename amount to adjustment_amount
rioug Jun 30, 2023
5a59396
Remove call to VoucherAdjustmentService when creating a voucher
rioug Jun 30, 2023
0e0850e
Add specs to cover re calculation
rioug Jun 30, 2023
a584f9a
Refactor VoucherAdjustmentsService
rioug Jul 18, 2023
a5b2bc6
Per review, Refactor VoucherAdjustmentsService
rioug Jul 18, 2023
895f534
Remove unnecessary extra page load
dacook Jul 27, 2023
be1a727
Pending spec: vouchers should not require payment
dacook Jul 27, 2023
ef62fb8
Check if record actually saved
dacook Jul 27, 2023
f35001d
Update voucher adjustment and order total when adding a voucher
rioug Jul 28, 2023
33ef8de
Update order total after removing a voucher
rioug Jul 28, 2023
089d2b9
Clear any existing payment and payment fees when adding a voucher
rioug Jul 31, 2023
2857930
Fix voucher adjustment request spec
rioug Jul 31, 2023
85adb9f
Fix rubocop warning
rioug Jul 31, 2023
6ed35f4
Per review, delete only incomplete payments
rioug Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/voucher_adjustments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def add_voucher
return false
end

# Clear payments and payment_fee, to not affect voucher adjustment calculation
@order.all_adjustments.payment_fee.destroy_all
@order.payments.clear
Copy link
Member

Choose a reason for hiding this comment

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

Sorry but I have to ask, is this potentially clearing records of actual payments?
I'm guessing at this point the payments (and indeed order) are in an "incomplete" state, so it's ok to delete. But perhaps we should add a scope just in case? Eg:

    @order.payments.incomplete.clear

I looked at the Payment model and expected to see a before_destroy for this but didn't. Maybe it should be there..
@mkllnk do you have any insights?


VoucherAdjustmentsService.new(@order).update
@order.update_totals_and_states

Expand Down
25 changes: 24 additions & 1 deletion spec/requests/voucher_adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:order_cycle) { create(:order_cycle, distributors: [distributor]) }
let(:exchange) { order_cycle.exchanges.outgoing.first }
let(:order) do
let!(:order) do
create(
:order_with_line_items,
line_items_count: 1,
Expand Down Expand Up @@ -66,6 +66,29 @@
)
end
end

context "when the order has a payment and payment feed" do
let(:payment_method) { create(:payment_method, calculator: calculator) }
let(:calculator) do
::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
end

before do
create(:payment, order: order, payment_method: payment_method, amount: order.total)
end

it "removes existing payments" do
expect do
post "/voucher_adjustments", params: params
end.to change { order.reload.payments.count }.from(1).to(0)
end

it "removes existing payment fees" do
expect do
post "/voucher_adjustments", params: params
end.to change { order.reload.all_adjustments.payment_fee.count }.from(1).to(0)
end
end
end

describe "DELETE voucher_adjustments/:id" do
Expand Down