diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 6763de4712b..84c717a8190 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -249,8 +249,11 @@ def inventory_units_for(variant) def to_package package = OrderManagement::Stock::Package.new(stock_location, order) - inventory_units.includes(:variant).each do |inventory_unit| - package.add inventory_unit.variant, 1, inventory_unit.state_name + grouped_inventory_units = inventory_units.includes(:variant).group_by do |iu| + [iu.variant, iu.state_name] + end + grouped_inventory_units.each do |(variant, state_name), inventory_units| + package.add variant, inventory_units.count, state_name end package end