diff --git a/app/services/order_tax_adjustments_fetcher.rb b/app/services/order_tax_adjustments_fetcher.rb index 686efff9a4..103953947b 100644 --- a/app/services/order_tax_adjustments_fetcher.rb +++ b/app/services/order_tax_adjustments_fetcher.rb @@ -20,24 +20,11 @@ class OrderTaxAdjustmentsFetcher attr_reader :order def all - Spree::Adjustment - .where(order_adjustments.or(line_item_adjustments).or(shipment_adjustments)) - .order('created_at ASC') - end + tax_adjustments = order.all_adjustments.tax + enterprise_fees_with_tax = order.all_adjustments.enterprise_fee.with_tax + admin_adjustments_with_tax = order.adjustments.admin.with_tax - def order_adjustments - table[:adjustable_id].eq(order.id) - .and(table[:adjustable_type].eq('Spree::Order')) - end - - def line_item_adjustments - table[:adjustable_id].eq_any(order.line_item_ids) - .and(table[:adjustable_type].eq('Spree::LineItem')) - end - - def shipment_adjustments - table[:order_id].eq(order.id) - .and(table[:adjustable_type].eq('Spree::Shipment')) + tax_adjustments | enterprise_fees_with_tax | admin_adjustments_with_tax end def table @@ -66,10 +53,9 @@ class OrderTaxAdjustmentsFetcher end def no_tax_adjustments?(adjustment) - # Enterprise Fees, Admin Adjustments, and Shipping Fees currently do not have tax adjustments. + # Enterprise Fees and Admin Adjustments currently do not have tax adjustments. # The tax amount is stored in the included_tax attribute. adjustment.originator_type == "EnterpriseFee" || - adjustment.originator_type == "Spree::ShippingMethod" || (adjustment.source_type.nil? && adjustment.originator_type.nil?) end end diff --git a/spec/services/order_tax_adjustments_fetcher_spec.rb b/spec/services/order_tax_adjustments_fetcher_spec.rb index f5edd0d848..ba908dc83b 100644 --- a/spec/services/order_tax_adjustments_fetcher_spec.rb +++ b/spec/services/order_tax_adjustments_fetcher_spec.rb @@ -66,14 +66,9 @@ describe OrderTaxAdjustmentsFetcher do distributor: coordinator ) end - - before do - allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true) - allow(Spree::Config).to receive(:shipping_tax_rate).and_return(tax_rate15.amount) - end - let(:shipping_method) do - create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 46.0)) + create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 46.0), + tax_category: tax_category15) end let!(:shipment) do create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order)