app/models/shipment.rb
def new_inventory_transaction
    tran = InventoryTransaction.new
    skus = Product.where(id: items.map(&:order_item).map(&:product_id)).pluck(:sku).uniq

    skus.each do |sku|
      quantity = items.select { |x| x.order_item.product.sku == sku }.sum(&:quantity)
      tran.items << InventoryItem.get(sku, quantity) unless quantity == 0
    end

    tran
  end
# creates a new transaction without saving to DB
creates a new transaction without saving to DB
creates a new transaction without saving to DB
def new_inventory_transaction
    tran = InventoryTransaction.new
    skus = Product.where(id: items.map(&:order_item).map(&:product_id)).pluck(:sku).uniq
    skus.each do |sku|
      quantity = items.select { |x| x.order_item.product.sku == sku }.sum(&:quantity)
      tran.items << InventoryItem.get(sku, quantity) unless quantity == 0
    end
    tran
  end
def new_inventory_transaction tran = InventoryTransaction . new skus = Product . where ( id : items . map ( & :order_item ) . map ( & :product_id ) ) . pluck ( :sku ) . uniq skus . each do | sku | quantity = items . select { | x | x . order_item . product . sku == sku } . sum ( & :quantity ) tran . items << InventoryItem . get ( sku , quantity ) unless quantity == 0 end tran end
creates a new transaction without saving to DB
creates a new transaction without saving to DB