Sha256: bb5cebaa15dfd92fc993908ecdb87013b6285e22b2ad1b2c8e025aeaf49a5297

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module SolidusProductAssembly
  module Spree
    module Stock
      module InventoryUnitsFinalizerDecorator
        private

        def unstock_inventory_units
          inventory_units.group_by(&:shipment_id).each_value do |inventory_units_for_shipment|
            inventory_units_for_shipment.group_by(&:line_item_id).each_value do |units|
              shipment = units.first.shipment
              line_item = units.first.line_item

              if line_item.product.assembly?
                units.group_by(&:variant_id).each_value do |units_for_part|
                  part = units_for_part.first.variant
                  shipment.stock_location.unstock part, units_for_part.count, shipment
                end
              else
                shipment.stock_location.unstock line_item.variant, units.count, shipment
              end
            end
          end
        end

        if ::Spree.solidus_gem_version >= Gem::Version.new('2.8')
          ::Spree::Stock::InventoryUnitsFinalizer.prepend self
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_product_assembly-1.4.0 app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb
solidus_product_assembly-1.3.0 app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb
solidus_product_assembly-1.2.0 app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb
solidus_product_assembly-1.1.0 app/decorators/models/solidus_product_assembly/spree/stock/inventory_units_finalizer_decorator.rb