mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user