mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Update OrderTaxAdjustmentsFetcher
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user