Simplify helper with extracted method

This commit is contained in:
Maikel Linke
2023-10-12 14:17:41 +11:00
parent 7f2c1feaf8
commit 74c8f06e80

View File

@@ -7,17 +7,23 @@ 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)
adjustments_for_display = order.adjustments + order.all_adjustments.payment_fee.eligible
order.adjustments +
voucher_included_tax_representations(order) +
order.all_adjustments.payment_fee.eligible
end
if VoucherAdjustmentsService.new(order).voucher_included_tax.negative?
adjustment = order.voucher_adjustments.first
adjustments_for_display << Spree::Adjustment.new(
label: I18n.t("admin.orders.edit.voucher_tax_included_in_price", label: adjustment.label),
def voucher_included_tax_representations(order)
return [] unless VoucherAdjustmentsService.new(order).voucher_included_tax.negative?
adjustment = order.voucher_adjustments.first
[
Spree::Adjustment.new(
label: I18n.t("admin.orders.edit.voucher_tax_included_in_price",
label: adjustment.label),
amount: adjustment.included_tax
)
end
adjustments_for_display
]
end
end
end