Class: SpreeCmCommissioner::InventoryItems::BulkAdjustQuantitiesOnHold

Inherits:
Object
  • Object
show all
Extended by:
ServiceModuleThrowable
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/inventory_items/bulk_adjust_quantities_on_hold.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
# File 'app/services/spree_cm_commissioner/inventory_items/bulk_adjust_quantities_on_hold.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.find { |item| item[:inventory_id] == inventory_item.id }&.dig(:quantity) || 0
      adjust_quantity_on_hold(inventory_item, quantity)
    end
  end

  success(nil)
end