Don't show line item adjustments in Admin::OrdersHelper#order_adjustments_for_display

Line item adjustments are displayed separately, if we don't filter them here they get displayed twice.
This commit is contained in:
Matt-Yorkley
2021-04-14 15:17:38 +01:00
parent 0c182c4606
commit d29c0cdcb7
3 changed files with 13 additions and 8 deletions

View File

@@ -5,9 +5,7 @@ module Admin
# We exclude shipping method adjustments because they are displayed in a
# separate table together with the order line items.
def order_adjustments_for_display(order)
order.all_adjustments.enterprise_fee +
order.all_adjustments.payment_fee.eligible +
order.adjustments.admin
order.adjustments + order.all_adjustments.payment_fee.eligible
end
end
end

View File

@@ -22,7 +22,7 @@ describe Spree::Admin::OrdersController, type: :controller do
it "does not show ineligible payment adjustments" do
adjustment = create(
:adjustment,
adjustable: order,
adjustable: build(:payment),
originator_type: "Spree::PaymentMethod",
label: "invalid adjustment",
eligible: false,

View File

@@ -13,15 +13,22 @@ describe Admin::OrdersHelper, type: :helper do
end
it "filters shipping method adjustments" do
create(:adjustment, order: order, adjustable: order, amount: 1,
create(:adjustment, order: order, adjustable: build(:shipment), amount: 1,
originator_type: "Spree::ShippingMethod")
expect(helper.order_adjustments_for_display(order)).to eq []
end
it "filters ineligible adjustments" do
create(:adjustment, adjustable: order, amount: 0, eligible: false,
originator_type: "Spree::TaxRate")
it "filters ineligible payment adjustments" do
create(:adjustment, adjustable: build(:payment), amount: 0, eligible: false,
originator_type: "Spree::PaymentMethod", order: order)
expect(helper.order_adjustments_for_display(order)).to eq []
end
it "filters out line item adjustments" do
create(:adjustment, adjustable: build(:line_item), amount: 0, eligible: false,
originator_type: "EnterpriseFee", order: order)
expect(helper.order_adjustments_for_display(order)).to eq []
end