mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Merge shipment decorator with class brought from spree_core
This commit is contained in:
@@ -166,7 +166,7 @@ module Spree
|
||||
# recalculates the shipment taxes
|
||||
def update_totals_and_taxes
|
||||
@order.updater.update_totals
|
||||
@order.shipment&.ensure_correct_adjustment_with_included_tax
|
||||
@order.shipment&.ensure_correct_adjustment
|
||||
end
|
||||
|
||||
# Sets the adjustments to open to perform the block's action and restores
|
||||
|
||||
@@ -159,13 +159,18 @@ module Spree
|
||||
end
|
||||
|
||||
def manifest
|
||||
inventory_units.joins(:variant).includes(:variant).group_by(&:variant).map do |variant, units|
|
||||
inventory_units.group_by(&:variant).map do |variant, units|
|
||||
states = {}
|
||||
units.group_by(&:state).each { |state, iu| states[state] = iu.count }
|
||||
scoper.scope(variant)
|
||||
OpenStruct.new(variant: variant, quantity: units.length, states: states)
|
||||
end
|
||||
end
|
||||
|
||||
def scoper
|
||||
@scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
|
||||
end
|
||||
|
||||
def line_items
|
||||
if order.complete? && Spree::Config[:track_inventory_levels]
|
||||
order.line_items.select { |li| inventory_units.pluck(:variant_id).include?(li.variant_id) }
|
||||
@@ -295,10 +300,28 @@ module Spree
|
||||
"open")
|
||||
reload # ensure adjustment is present on later saves
|
||||
end
|
||||
|
||||
update_adjustment_included_tax if adjustment
|
||||
end
|
||||
|
||||
def update_adjustment_included_tax
|
||||
if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax)
|
||||
adjustment.set_included_tax! Config.shipping_tax_rate
|
||||
else
|
||||
adjustment.set_included_tax! 0
|
||||
end
|
||||
end
|
||||
|
||||
def update_order
|
||||
order.update!
|
||||
end
|
||||
|
||||
# NOTE: This is an override of spree's method, needed to allow orders
|
||||
# without line items (ie. user invoices) to not have inventory units
|
||||
def require_inventory
|
||||
return false unless line_items.count > 0 # This line altered
|
||||
|
||||
order.completed? && !order.canceled?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
module Spree
|
||||
Shipment.class_eval do
|
||||
def ensure_correct_adjustment_with_included_tax
|
||||
ensure_correct_adjustment_without_included_tax
|
||||
|
||||
update_adjustment_included_tax if adjustment
|
||||
end
|
||||
alias_method_chain :ensure_correct_adjustment, :included_tax
|
||||
|
||||
def update_adjustment_included_tax
|
||||
if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax)
|
||||
adjustment.set_included_tax! Config.shipping_tax_rate
|
||||
else
|
||||
adjustment.set_included_tax! 0
|
||||
end
|
||||
end
|
||||
|
||||
def manifest
|
||||
inventory_units.group_by(&:variant).map do |variant, units|
|
||||
states = {}
|
||||
units.group_by(&:state).each { |state, iu| states[state] = iu.count }
|
||||
scoper.scope(variant)
|
||||
OpenStruct.new(variant: variant, quantity: units.length, states: states)
|
||||
end
|
||||
end
|
||||
|
||||
def scoper
|
||||
@scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# NOTE: This is an override of spree's method, needed to allow orders
|
||||
# without line items (ie. user invoices) to not have inventory units
|
||||
def require_inventory
|
||||
return false unless line_items.count > 0 # This line altered
|
||||
|
||||
order.completed? && !order.canceled?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user