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
This commit is contained in:
cyrillefr
2024-05-31 16:04:48 +02:00
committed by zanetagebka
parent 56398d4d0f
commit fb712be430
3 changed files with 23 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 + ":"

View File

@@ -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."