From 073dfc4ab6d2096f9a7e8056a3a7a069df56e280 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Fri, 31 May 2024 16:04:48 +0200 Subject: [PATCH 1/2] Update and Recalculate Fees after Order Adjusted in Backend - when update on adjustment in payment, recalculation of correct adjustment was not done - the corresponding spec - an id to easy the finding of the change of fees in the spec --- app/models/spree/payment.rb | 1 + .../admin/orders/_form/_adjustments.html.haml | 2 +- spec/system/admin/order_spec.rb | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 6479694df9..e10920d4b8 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -155,6 +155,7 @@ module Spree if adjustment adjustment.originator = payment_method adjustment.label = adjustment_label + adjustment.amount = payment_method.compute_amount(self) adjustment.save elsif !processing_refund? && payment_method.present? payment_method.create_adjustment(adjustment_label, self, true) diff --git a/app/views/spree/admin/orders/_form/_adjustments.html.haml b/app/views/spree/admin/orders/_form/_adjustments.html.haml index 5f3e9f215e..771723c99e 100644 --- a/app/views/spree/admin/orders/_form/_adjustments.html.haml +++ b/app/views/spree/admin/orders/_form/_adjustments.html.haml @@ -6,7 +6,7 @@ %tr %th= Spree.t('name') %th= Spree.t('amount') - %tbody.with-border + %tbody.with-border#order_adjustments - adjustments.each do |adjustment| %tr.total %td.strong= adjustment.label + ":" diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 5a0ff97a0b..7fa035713b 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -172,6 +172,27 @@ RSpec.describe ' expect(order.line_items.reload.map(&:product)).to include product end + context "When adding a product on an order with transaction fee" do + let(:order_with_fees) { create(:completed_order_with_fees, user:, distributor:, order_cycle: ) } + + it 'recalculates transaction fee' do + login_as_admin + visit spree.edit_admin_order_path(order_with_fees) + + transaction_fee = order_with_fees.all_adjustments.payment_fee.eligible.first.amount + expect(page.find("#order_adjustments").text).to have_content(transaction_fee) + + select2_select product.name, from: 'add_variant_id', search: true + find('button.add_variant').click + sleep(1) + + new_transaction_fee = order_with_fees.all_adjustments.payment_fee.eligible.first.amount + + expect(new_transaction_fee).to be > transaction_fee + expect(page.find("#order_adjustments").text).to have_content(new_transaction_fee) + end + end + shared_examples_for "Cancelling the order" do it "shows a modal about order cancellation" do expect(page).to have_content "This will cancel the current order." From 9495d6223609b20a243053606055fe4fbb8a2e1e Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 3 Jun 2024 16:27:57 +0200 Subject: [PATCH 2/2] Requested changes on spec - if possible no sleep in spec --- spec/system/admin/order_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 7fa035713b..55d91e9ef2 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -179,17 +179,15 @@ RSpec.describe ' login_as_admin visit spree.edit_admin_order_path(order_with_fees) - transaction_fee = order_with_fees.all_adjustments.payment_fee.eligible.first.amount + adjustment_for_transaction_fee = order_with_fees.all_adjustments.payment_fee.eligible.first + transaction_fee = adjustment_for_transaction_fee.amount + expect(page.find("#order_adjustments").text).to have_content(transaction_fee) select2_select product.name, from: 'add_variant_id', search: true find('button.add_variant').click - sleep(1) - - new_transaction_fee = order_with_fees.all_adjustments.payment_fee.eligible.first.amount - - expect(new_transaction_fee).to be > transaction_fee - expect(page.find("#order_adjustments").text).to have_content(new_transaction_fee) + expect(page).to have_css("#order_adjustments", + text: adjustment_for_transaction_fee.reload.amount) end end