Merge pull request #12538 from cyrillefr/UpdateAndRecalculateFeesAfterOrderAdjustedInBackend

Update and Recalculate Fees after Order Adjusted in Backoffice
This commit is contained in:
Filipe
2024-06-13 08:53:43 -06:00
committed by GitHub
3 changed files with 21 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,25 @@ 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)
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
expect(page).to have_css("#order_adjustments",
text: adjustment_for_transaction_fee.reload.amount)
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."