Created
June 19, 2009 13:23
-
-
Save rubysolo/132610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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