diff --git a/app/controllers/voucher_adjustments_controller.rb b/app/controllers/voucher_adjustments_controller.rb index c34570269c..59e3feddc3 100644 --- a/app/controllers/voucher_adjustments_controller.rb +++ b/app/controllers/voucher_adjustments_controller.rb @@ -15,7 +15,11 @@ class VoucherAdjustmentsController < BaseController end def destroy - @order.voucher_adjustments.find_by(id: params[:id])&.destroy + # An order can have more than one adjustment linked to one voucher + adjustment = @order.voucher_adjustments.find_by(id: params[:id]) + if adjustment.present? + @order.voucher_adjustments.where(originator_id: adjustment.originator_id)&.destroy_all + end update_payment_section end diff --git a/spec/requests/voucher_adjustments_spec.rb b/spec/requests/voucher_adjustments_spec.rb index 8c93fb3f69..2730d0884f 100644 --- a/spec/requests/voucher_adjustments_spec.rb +++ b/spec/requests/voucher_adjustments_spec.rb @@ -96,5 +96,26 @@ describe VoucherAdjustmentsController, type: :request do expect(response).to be_successful end end + + context "when tax excluded from price" do + it "deletes all voucher adjustment" do + # Add a tax adjustment + adjustment_attributes = { + amount: 2.00, + originator: adjustment.originator, + order: order, + label: "Tax #{adjustment.label}", + mandatory: false, + state: 'closed', + tax_category: nil, + included_tax: 0 + } + order.adjustments.create(adjustment_attributes) + + delete "/voucher_adjustments/#{adjustment.id}" + + expect(order.voucher_adjustments.reload.length).to eq(0) + end + end end end