Class: Spree::OrderRouting::Rules::MinimizeSplits
- Inherits:
-
Spree::OrderRoutingRule
- Object
- Spree::OrderRoutingRule
- Spree::OrderRouting::Rules::MinimizeSplits
- Defined in:
- app/models/spree/order_routing/rules/minimize_splits.rb
Overview
Prefers locations that can fulfill more demand on their own. Higher coverage → lower (better) rank, so the location that single-handedly covers the most variants wins. Coverage is counted per distinct variant so a variant repeated across multiple line items isn’t double-counted.
Instance Method Summary collapse
Instance Method Details
#rank(order, locations) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/spree/order_routing/rules/minimize_splits.rb', line 9 def rank(order, locations) demand = required_quantity_by_variant(order) counts = stock_item_counts(demand.keys, locations) locations.map do |loc| coverage = demand.count do |variant_id, qty| (counts[[loc.id, variant_id]] || 0) >= qty end LocationRanking.new(location: loc, rank: -coverage) end end |