diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index b9cb0d07f1..b23bd7266f 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -15,13 +15,14 @@ module Spree end end - # The shipment manifest is built by loading inventory units and variants from the DB - # These variants come unscoped - # So, we need to scope the variants just after the manifest is built - def manifest_with_scoping - manifest_without_scoping.each { |item| scoper.scope(item.variant) } + 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 - alias_method_chain :manifest, :scoping def scoper @scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)