Skip to content

Instantly share code, notes, and snippets.

@swallowstalker
Created December 23, 2019 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swallowstalker/acc77fcbfd94c2f78c0853344b03ba10 to your computer and use it in GitHub Desktop.
Save swallowstalker/acc77fcbfd94c2f78c0853344b03ba10 to your computer and use it in GitHub Desktop.
Match lancelot stock > 0 with product data
ProductSkuWarehouseStock.where('available_qty', '>', 0).where.not(warehouse_id: 81).find_in_batches(batch_size: 500) do |stocks|
stocks.each do |stock|
p_list_inactive = Product.where(sku_id: stock[:product_sku_id], state: 0).pluck(:id)
p_list_active = Product.where(sku_id: stock[:product_sku_id], state: 1).pluck(:id)
if p_list_active.size == 0
puts "For SKU ID #{stock[:product_sku_id]}, warehouse ID: #{stock[:warehouse_id]} found inactive product ID: #{p_list_inactive}"
end
if p_list_inactive.size == 0
puts "For SKU ID #{stock[:product_sku_id]}, warehouse ID: #{stock[:warehouse_id]} inactive product not found"
end
if p_list_active.size > 1
puts "For SKU ID #{stock[:product_sku_id]}, warehouse ID: #{stock[:warehouse_id]} found multiple active product: #{p_list_active}"
end
end
sleep(0.1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment