Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created June 19, 2009 13:23
Show Gist options
  • Select an option

  • Save rubysolo/132610 to your computer and use it in GitHub Desktop.

Select an option

Save rubysolo/132610 to your computer and use it in GitHub Desktop.
@incoming_items.each do |item|
# find all pending orders with this item
pending_shipments = Shipments.in_status('waiting to ship').with_item(item).sorted_by_date
allocated_quantity = 0
# ship the allocated
pending_shipments.each do |shipment|
quantity = shipment.line_items.find_all_by_item_id(item.id).inject(0) {|sum, line| sum += line }
if quantity + allocated_quantity < item.quantity
# ship this shipment
allocated_quantity += quantity
end
last if allocated_quantity >= item.quantity
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment