From d8a92eec4b419669de7b498f2085777c9d76964d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 3 Mar 2020 16:37:00 +0000 Subject: [PATCH] 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