Merge pull request #11184 from rioug/11183-fix-delete-voucher-tax-excl-price

[vouchers] fix delete voucher when tax excluded from price
This commit is contained in:
Filipe
2023-07-19 11:24:25 +01:00
committed by GitHub
2 changed files with 26 additions and 1 deletions

View File

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

View File

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