From d8a92eec4b419669de7b498f2085777c9d76964d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 16:37:00 +0000 Subject: [PATCH 1/3] Bring Shipment#manifest from spree as is --- app/models/spree/shipment_decorator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index b9cb0d07f1..a6f9e724ba 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -15,6 +15,14 @@ module Spree end end + def manifest + inventory_units.joins(:variant).includes(:variant).group_by(&:variant).map do |variant, units| + states = {} + units.group_by(&:state).each { |state, iu| states[state] = iu.count } + OpenStruct.new(variant: variant, quantity: units.length, states: states) + 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 From 5688de4936124ae5266dcdcd606c0bcf95a0bd60 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 16:38:03 +0000 Subject: [PATCH 2/3] Make Shipment#manifest work with deleted variants again This makes the default variant scope in inventory_unit being used which includes deleted variants --- app/models/spree/shipment_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index a6f9e724ba..540a327268 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -16,7 +16,7 @@ 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 } OpenStruct.new(variant: variant, quantity: units.length, states: states) From 3b37fa88722981a152d3e9ee0ee8e504f2761367 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 16:40:31 +0000 Subject: [PATCH 3/3] Move variant scoping from alias method into manifest method --- app/models/spree/shipment_decorator.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index 540a327268..b23bd7266f 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -19,18 +19,11 @@ module Spree 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 - # 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) } - end - alias_method_chain :manifest, :scoping - def scoper @scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(order.distributor) end