Class: SpreeCmCommissioner::InventoryItems::BulkAdjustQuantities

Inherits:
Object
  • Object
show all
Extended by:
ServiceModuleThrowable
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/inventory_items/bulk_adjust_quantities.rb

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Instance Method Details

#call(inventory_id_and_quantities:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/spree_cm_commissioner/inventory_items/bulk_adjust_quantities.rb', line 7

def call(inventory_id_and_quantities:)
  ActiveRecord::Base.transaction do
    inventory_items(inventory_id_and_quantities).each do |inventory_item|
      quantity = inventory_id_and_quantities.select { |item| item[:inventory_id] == inventory_item.id }
                                            .sum { |item| item[:quantity] }
      adjust_quantity_available(inventory_item, quantity)
    end
  end

  success(nil)
end