- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] RAILS_DEFAULT_LOGGER.info(“Line Items: #{order_line_items.inspect}”) order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) RAILS_DEFAULT_LOGGER.info("Build shipments found item: #{item.inspect} from store #{item.store_id}") ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 RAILS_DEFAULT_LOGGER.debug("Attempting to consolidate in_stocks and drop_ships.") # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 RAILS_DEFAULT_LOGGER.debug("Consolidating in_stocks and drop_ships.") #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end set_consolidate_flags( shipments ) RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "Shipments" RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "#{shipments.inspect}" RAILS_DEFAULT_LOGGER.info "=====================================================" return shipments end
of writing. Few writers are so expert that they can produce what they are after on the first try. Quite often you will discover, on examining the completed work, that there are serious flaws in the arrangement of the material, calling for transpositions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] RAILS_DEFAULT_LOGGER.info(“Line Items: #{order_line_items.inspect}”) order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) RAILS_DEFAULT_LOGGER.info("Build shipments found item: #{item.inspect} from store #{item.store_id}") ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 RAILS_DEFAULT_LOGGER.debug("Attempting to consolidate in_stocks and drop_ships.") # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 RAILS_DEFAULT_LOGGER.debug("Consolidating in_stocks and drop_ships.") #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end set_consolidate_flags( shipments ) RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "Shipments" RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "#{shipments.inspect}" RAILS_DEFAULT_LOGGER.info "=====================================================" return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] RAILS_DEFAULT_LOGGER.info(“Line Items: #{order_line_items.inspect}”) order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) RAILS_DEFAULT_LOGGER.info("Build shipments found item: #{item.inspect} from store #{item.store_id}") ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 RAILS_DEFAULT_LOGGER.debug("Attempting to consolidate in_stocks and drop_ships.") # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 RAILS_DEFAULT_LOGGER.debug("Consolidating in_stocks and drop_ships.") #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "Shipments" RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "#{shipments.inspect}" RAILS_DEFAULT_LOGGER.info "=====================================================" return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] RAILS_DEFAULT_LOGGER.info(“Line Items: #{order_line_items.inspect}”) order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) RAILS_DEFAULT_LOGGER.info("Build shipments found item: #{item.inspect} from store #{item.store_id}") ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 RAILS_DEFAULT_LOGGER.debug("Attempting to consolidate in_stocks and drop_ships.") # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 RAILS_DEFAULT_LOGGER.debug("Consolidating in_stocks and drop_ships.") #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "Shipments" RAILS_DEFAULT_LOGGER.info "=====================================================" RAILS_DEFAULT_LOGGER.info "#{shipments.inspect}" RAILS_DEFAULT_LOGGER.info "=====================================================" return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
cost of clarity Many shortcuts are self-defeating; they waste the reader’s time instead of conserving it. The one truly reliable shortcut in writing is to choose words that are strong and surefooted to carry readers on their way.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
This principle, that of parallel construction, requires that expressions similar in content and function be outwardly similar. The likeness of form enables the reader to recognize more readily the likeness of content and function.
Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it “executes when consolidate is false" do assert ShipmentBuilder.new([order_line_item_double]) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it “executes when consolidate is false" do assert ShipmentBuilder.new([order_line_item_double]) end it "executes when consolidate is true" do assert ShipmentBuilder.new([order_line_item_double], true) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Determine the groups in which items will be shipped. This is necessary for # non-consolidated shipments when some items are out of stock or are being # drop-shipped from a vendors warehouse. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_shipments( order_line_items, consolidate=false ) shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it “executes when consolidate is false" do assert ShipmentBuilder.new([order_line_item_double]) end it "executes when consolidate is true" do assert ShipmentBuilder.new([order_line_item_double], true) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "executes when consolidate is true" do assert ShipmentBuilder.new([order_line_item_double], true) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "executes when consolidate is true" do assert ShipmentBuilder.new([order_line_item_double], true) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "executes when consolidate is true" do assert ShipmentBuilder.new([order_line_item_double], true) end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "returns a single consolidated shipment when consolidate is true" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double], true).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :consolidated end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
in 0.001944s, 1028.8066 runs/s, 0.0000 assertions/s. 1) Error: ShipmentBuilder#test_0001_returns a single in_stock shipment: ArgumentError: wrong number of arguments (0 for 2) shipment_builder.rb:16:in `build_shipments' 2) Error: ShipmentBuilder#test_0002_returns a single consolidated shipment when consolidate is true: ArgumentError: wrong number of arguments (0 for 2) shipment_builder.rb:16:in `build_shipments' 2 runs, 0 assertions, 0 failures, 2 errors, 0 skips
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "returns a single consolidated shipment when consolidate is true" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double], true).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :consolidated end end def order_line_item_double OpenStruct.new(:item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
{ Object.send(:const_set, :Shipment, ShipmentDouble) } after { Object.send(:remove_const, :Shipment) } it "returns a single consolidated shipment when consolidate is true" do order_line_items = [ order_line_item_double(ship_status_symbol: :in_stock), order_line_item_double(ship_status_symbol: :drop_ship), order_line_item_double(ship_status_symbol: :order_in), ] shipments = ShipmentBuilder.new(order_line_items, true).build_shipments shipments.length.must_equal 1 end it "returns a single in_stock shipment" do shipments = ShipmentBuilder.new([order_line_item_double, order_line_item_double]).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :in_stock end it "returns multiple shipments when types and vendors differ" do order_line_items = [ order_line_item_double(ship_status_symbol: :in_stock), order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 9), order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 10), order_line_item_double(ship_status_symbol: :order_in), ] shipments = ShipmentBuilder.new(order_line_items).build_shipments shipments.length.must_equal 4 shipments.count{|s| s.shipment_type == :drop_ship}.must_equal 2 end it "consolidates drop ship items from the same vendor" do order_line_items = [ order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 9), order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 9), ] shipments = ShipmentBuilder.new(order_line_items).build_shipments shipments.length.must_equal 1 end it "consolidates in_stock to drop_ship if all in_stock items can be consolidated" do order_line_items = [ order_line_item_double(ship_status_symbol: :in_stock, vendor_id: 9), order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 9), ] shipments = ShipmentBuilder.new(order_line_items).build_shipments shipments.length.must_equal 1 shipments.first.shipment_type.must_equal :drop_ship end it "does not consolidate in_stock to drop ship if any in_stock items are not consolidatable" do order_line_items = [ order_line_item_double(ship_status_symbol: :in_stock, vendor_id: 9), order_line_item_double(ship_status_symbol: :drop_ship, vendor_id: 9), order_line_item_double(ship_status_symbol: :in_stock, vendor_id: 10), ] shipments = ShipmentBuilder.new(order_line_items).build_shipments shipments.length.must_equal 2 shipments.find{|s| s.shipment_type == :drop_ship}.line_items.length.must_equal 1 end end def order_line_item_double(overrides = {}) line_item_params = { :item_id => 1, :store_id => 1, :vendor_id => 1, :drop_shippable? => true, :ship_status_symbol => :in_stock }.merge(overrides) OpenStruct.new(line_item_params) end class ShipmentDouble < OpenStruct def initialize(*) super self.line_items = [] end end
@order_line_items = order_line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) found = false shipments.each do |shipment| if shipment.shipment_type == key && shipment.shipper_id == shipper_id && shipment.store_id == store_id shipment.line_items << order_line_item found = true end end if found == false shipment = Shipment.new shipment.shipment_type = key shipment.shipper_id = shipper_id shipment.store_id = store_id shipment.line_items << order_line_item shipments << shipment end end
concise. A sentence should contain no unnecessary words, a paragraph no unnecessary sentences, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts.
@order_line_items = order_line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) found = false shipments.each do |shipment| if shipment.shipment_type == key && shipment.shipper_id == shipper_id && shipment.store_id == store_id shipment.line_items << order_line_item found = true end end if found == false shipment = Shipment.new shipment.shipment_type = key shipment.shipper_id = shipper_id shipment.store_id = store_id shipment.line_items << order_line_item shipments << shipment end end
@order_line_items = order_line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) found = false shipments.each do |shipment| if shipment.shipment_type == key && shipment.shipper_id == shipper_id && shipment.store_id == store_id shipment.line_items << order_line_item found = true end end if found == false shipment = Shipment.new shipment.shipment_type = key shipment.shipper_id = shipper_id shipment.store_id = store_id shipment.line_items << order_line_item shipments << shipment end end
hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| line_items << OpenStruct.new( :ship_status_symbol => order_line_item.ship_status_symbol, :store_id => order_line_item.store_id, :vendor_id => order_line_item.vendor_id, :line_item => order_line_item, :drop_shippable => order_line_item.drop_shippable :consolidatable => order_line_item.consolidatable) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end
# MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end
# MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end
# MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end
@order_line_items = order_line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate line_items = order_line_items # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@order_line_items = order_line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate line_items = order_line_items # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate line_items = order_line_items # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate line_items = order_line_items # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else order_line_items.each do |order_line_item| create_group_if_necessary_and_insert( shipments, :consolidated, order_line_item.store_id, order_line_item.store_id, order_line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
composition [A] subject requires division into topics, each of which should be dealt with in a paragraph. The object of treating each topic in a paragraph by itself is, of course, to aid the reader.
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
@line_items = line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def create_group_if_necessary_and_insert( shipments, key, store_id, shipper_id, order_line_item) ... end end
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
in 0.003601s, 1666.2038 runs/s, 2499.3057 assertions/s. 1) Error: ShipmentBuilder#test_0001_returns a single consolidated shipment when consolidate is true: NameError: undefined local variable or method `shipments' for #<ShipmentBuilder:0x007fa621902da0> /Users/nmeans/Projects/krw_talk/shipment_builder.rb:54:in `block in build_consolidated_shipment' 6 runs, 9 assertions, 0 failures, 1 errors, 0 skips
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
line_items @consolidate = consolidate end def build_shipments shipments = [] unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li ) end else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_sym line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end line_items_by_sym end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_sym line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end line_items_by_sym end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_sym line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end line_items_by_sym end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_sym line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status == ship_sym} end line_items_by_sym end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status = :drop_ship if li.ship_status == :in_stock} in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if in_stock_items.count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.count{|li| !li.consolidatable} < 1 end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? #Woo-hoo! Let's consolidate in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.count{|li| !li.consolidatable} < 1 end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.count{|li| !li.consolidatable} < 1 end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.count{|li| !li.consolidatable} < 1 end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.count{|li| !li.consolidatable} < 1 end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == li.vendor_id} li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |li| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == li.vendor_id} li.consolidatable = (matching_ds && li.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds && in_stock_item.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds && in_stock_item.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds && in_stock_item.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds && in_stock_item.drop_shippable) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.each do |in_stock_item| matching_ds = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} in_stock_item.consolidatable = (matching_ds) end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.each do |in_stock_item| in_stock_item.consolidatable = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.map(&:vendor_id) in_stock_items.each do |in_stock_item| in_stock_item.consolidatable = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id) in_stock_items.each do |in_stock_item| in_stock_item.consolidatable = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? in_stock_items.each do |in_stock_item| in_stock_item.consolidatable = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? in_stock_items.each do |in_stock_item| in_stock_item.consolidatable = drop_ship_items.any?{|drop_ship_item| drop_ship_item.vendor_id == in_stock_item.vendor_id} end in_stock_items.all?(&:consolidatable) end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
# If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. if consolidate_to_drop_ships? in_stock_items.each{|li| li.ship_status = :drop_ship} end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status, li.store_id, li.ship_status == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end end def consolidate_to_drop_ships? return false unless in_stock_items.all?(&:drop_shippable) (in_stock_items.map(&:vendor_id) - drop_ship_items.map(&:vendor_id)).empty? end def in_stock_items line_items_by_ship_status(:in_stock) end def drop_ship_items line_items_by_ship_status(:drop_ship) end def line_items_by_ship_status(status) line_items.select{|li| li.ship_status == status} end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| create_group_if_necessary_and_insert( shipments, :consolidated, line_item.store_id, line_item.store_id, line_item) end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| line_item.ship_status = :consolidated end end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| line_item.ship_status = :consolidated end assign_items_to_shipments end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
= line_items @consolidate = consolidate @shipments = [] end def build_shipments unless consolidate build_shipments_by_ship_status else build_consolidated_shipment end return shipments end def build_consolidated_shipment line_items.each do |line_item| line_item.ship_status = :consolidated end assign_items_to_shipments end def build_shipments_by_ship_status consolidate_to_drop_ships if consolidate_to_drop_ships? assign_items_to_shipments end
in 0.014991s, 400.2401 runs/s, 600.3602 assertions/s. 1) Failure: ShipmentBuilder#test_0006_does not consolidate in_stock to drop_ship if any in_stock items are not consolidatable [shipment_builder_spec.rb:65]: Expected: 1 Actual: 2 2) Failure: ShipmentBuilder#test_0005_consolidates in_stock to drop_ship if all in_stock items can be consolidated [shipment_builder_spec.rb:53]: Expected: 1 Actual: 2 6 runs, 9 assertions, 2 failures, 0 errors, 0 skips
# Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end
# Build a hash of line items with associated data we can use without having to re-query the database for all the iterations. line_items = [] order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) ship_status_symbol = item.shipping_status_symbol_for_quantity(order_line_item.quantity) ship_status_symbol = :in_stock if [:closeout_instock,:from_stock_only_instock].include?(ship_status_symbol) line_items << OpenStruct.new( :ship_status_symbol => ship_status_symbol, :store_id => item.instance_of?(Item) ? item.product.store_id : 1, :vendor_id => item.instance_of?(Item) ? item.product.vendor_id : nil, :line_item => order_line_item, :drop_shippable => item.drop_shippable?, :consolidatable => false) end # MAGIC GOES HERE TO DO THE CONSOLIDATION line_items_by_sym = {} [:in_stock,:drop_ship,:order_in].each do |ship_sym| line_items_by_sym[ship_sym] = line_items.select{|li| li.ship_status_symbol == ship_sym} end if line_items_by_sym[:in_stock].length > 0 && line_items_by_sym[:drop_ship].length > 0 # If we've got us some in_stocks and some drop_ships, let's see if # we can do some consolidating. It only makes sense to consolidate if we can completely # get rid of in_stocks. line_items_by_sym[:in_stock].each do |li| matching_ds = line_items_by_sym[:drop_ship].count{|dsli| dsli.vendor_id == li.vendor_id} > 0 li.consolidatable = (matching_ds && li.drop_shippable) end if line_items_by_sym[:in_stock].count{|li| !li.consolidatable} < 1 #Woo-hoo! Let's consolidate line_items.each{|li| li.ship_status_symbol = :drop_ship if li.ship_status_symbol == :in_stock} end end line_items.each do |li| create_group_if_necessary_and_insert( shipments, li.ship_status_symbol, li.store_id, li.ship_status_symbol == :drop_ship ? li.vendor_id : li.store_id, li.line_item ) end else order_line_items.each do |order_line_item| item = order_line_item.item_id ? Item.find(order_line_item.item_id, :include => :product) : UsedItem.find(order_line_item.used_item_id) create_group_if_necessary_and_insert( shipments, :consolidated, item.store_id, item.store_id, order_line_item) end end return shipments end def build_shipments optimize_consolidation assign_items_to_shipments return shipments end "
The cowboy went off to have a spare tire patched, and Eddie and I sat down in a kind of homemade diner. I heard a great laugh, the greatest laugh in the world, and here came this rawhide oldtimer Nebraska farmer with a bunch of other boys into the diner; you could hear his raspy cries clear across the plains, across the whole gray world of them that day. Everybody else laughed with him. He didn’t have a care in the world and had the hugest regard for everybody. I said to myself, Wham, listen to that man laugh. That’s the West, here I am in the West.
the Deans might be predisposed to weigh what he avers as coming from his possible appearance as a kind of cheerleader for E.T.A., he can assure the assembled Deans that all this is true, and that the Academy has presently in residence no fewer than a third of the continent’s top thirty junior, in age brackets all across the board, and that I here, who go by ‘Hal,’ usually, am ‘right up there among the very cream.’
while he turned and looked at the man. His face in the small light streaked with black from the rain like some old world thespian. Can I ask you something? he said. Yes. Of course. Are we going to die? Sometime. Not now. And we’re still going south. Yes. So we’ll be warm. Yes. Okay. Okay what? Nothing. Just okay. Go to sleep. Okay. I’m going to blow out the lamp. Is that okay? Yes. Thats okay. And then later in the darkness: Can I ask you something? Yes. Of course you can. What would you do if I died? If you died I would want to die too. So you could be with me? Yes. So I could be with you. Okay.
the truth is I write by ear, always with difficulty and seldom with any exact notion of what is taking place under the hood.” – E. B. White Introduction to “Will Strunk”, 1957