diff --git a/app/helpers/admin/orders_helper.rb b/app/helpers/admin/orders_helper.rb index 72a414bfd6..4e82a41739 100644 --- a/app/helpers/admin/orders_helper.rb +++ b/app/helpers/admin/orders_helper.rb @@ -2,12 +2,30 @@ module Admin module OrdersHelper + AdjustmentData = Struct.new(:label, :amount) + # Adjustments to display under "Order adjustments". # # 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.adjustments + order.all_adjustments.payment_fee.eligible + order.adjustments + + voucher_included_tax_representations(order) + + order.all_adjustments.payment_fee.eligible + end + + def voucher_included_tax_representations(order) + return [] unless VoucherAdjustmentsService.new(order).voucher_included_tax.negative? + + adjustment = order.voucher_adjustments.first + + [ + AdjustmentData.new( + I18n.t("admin.orders.edit.voucher_tax_included_in_price", + label: adjustment.label), + adjustment.included_tax + ) + ] end end end diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index b9b5ce8d40..dabbf3d4a6 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -53,7 +53,9 @@ module CheckoutHelper end def display_checkout_tax_total(order) - Spree::Money.new order.total_tax, currency: order.currency + total_tax = order.total_tax + VoucherAdjustmentsService.new(order).voucher_included_tax + + Spree::Money.new(total_tax, currency: order.currency) end def display_checkout_taxes_hash(order) diff --git a/config/locales/en.yml b/config/locales/en.yml index 95ea7a2e0a..a0eb7aa5c0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -982,6 +982,7 @@ en: orders: edit: order_sure_want_to: Are you sure you want to %{event} this order? + voucher_tax_included_in_price: "%{label} (tax included in voucher)" invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' bulk_management: diff --git a/spec/helpers/admin/orders_helper_spec.rb b/spec/helpers/admin/orders_helper_spec.rb index 07d3ca5035..ff00b73dc7 100644 --- a/spec/helpers/admin/orders_helper_spec.rb +++ b/spec/helpers/admin/orders_helper_spec.rb @@ -5,6 +5,12 @@ require "spec_helper" describe Admin::OrdersHelper, type: :helper do describe "#order_adjustments_for_display" do let(:order) { create(:order) } + let(:service) { instance_double(VoucherAdjustmentsService, voucher_included_tax:) } + let(:voucher_included_tax) { 0.0 } + + before do + allow(VoucherAdjustmentsService).to receive(:new).and_return(service) + end it "selects eligible adjustments" do adjustment = create(:adjustment, order:, adjustable: order, amount: 1) @@ -32,5 +38,22 @@ describe Admin::OrdersHelper, type: :helper do expect(helper.order_adjustments_for_display(order)).to eq [] end + + context "with a voucher with tax included in price" do + let(:enterprise) { build(:enterprise) } + let(:voucher) do + create(:voucher_flat_rate, code: 'new_code', enterprise:, amount: 10) + end + let(:voucher_included_tax) { -0.5 } + + it "includes a fake tax voucher adjustment" do + voucher_adjustment = voucher.create_adjustment(voucher.code, order) + voucher_adjustment.update(included_tax: voucher_included_tax) + + fake_adjustment = helper.order_adjustments_for_display(order).last + expect(fake_adjustment.label).to eq("new_code (tax included in voucher)") + expect(fake_adjustment.amount).to eq(-0.5) + end + end end end diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index 31ad004106..f52b611d9b 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -15,12 +15,27 @@ describe CheckoutHelper, type: :helper do helper.validated_input("test", "foo", type: :email) end - describe "displaying the tax total for an order" do - let(:order) { double(:order, total_tax: 123.45, currency: 'AUD') } + describe "#display_checkout_tax_total" do + subject(:display_checkout_tax_total) { helper.display_checkout_tax_total(order) } + + let(:order) { instance_double(Spree::Order, total_tax: 123.45, currency: 'AUD') } + let(:service) { instance_double(VoucherAdjustmentsService, voucher_included_tax: ) } + let(:voucher_included_tax) { 0.0 } + + before do + allow(VoucherAdjustmentsService).to receive(:new).and_return(service) + end it "retrieves the total tax on the order" do - expect(helper.display_checkout_tax_total(order)).to eq(Spree::Money.new(123.45, - currency: 'AUD')) + expect(display_checkout_tax_total).to eq(Spree::Money.new(123.45, currency: 'AUD')) + end + + context "with a voucher" do + let(:voucher_included_tax) { -0.45 } + + it "displays the discounted total tax" do + expect(display_checkout_tax_total).to eq(Spree::Money.new(123.00, currency: 'AUD')) + end end end diff --git a/spec/system/consumer/checkout/tax_incl_spec.rb b/spec/system/consumer/checkout/tax_incl_spec.rb index c1657070e1..2c74c738aa 100644 --- a/spec/system/consumer/checkout/tax_incl_spec.rb +++ b/spec/system/consumer/checkout/tax_incl_spec.rb @@ -131,7 +131,7 @@ describe "As a consumer, I want to see adjustment breakdown" do # UI checks expect(page).to have_content("Confirmed") expect(page).to have_selector('#order_total', text: with_currency(0.00)) - expect(page).to have_selector('#tax-row', text: with_currency(1.15)) + expect(page).to have_selector('#tax-row', text: with_currency(0.00)) # Voucher within "#line-items" do