@@ -144,15 +144,10 @@ def handle_stock_counts?
144144 end
145145
146146 def get_available_quantity
147- positive_stock = -> ( shipment ) do
148- on_hand = shipment . stock_location . count_on_hand ( variant )
149- on_hand . positive? ? on_hand : 0
150- end
151-
152147 if current_stock_location != desired_stock_location
153- positive_stock . call ( desired_shipment )
148+ desired_location_quantifier . positive_stock
154149 else
155- sl_availability = positive_stock . call ( current_shipment )
150+ sl_availability = current_location_quantifier . positive_stock
156151 shipment_availability = current_shipment . inventory_units . where ( variant : variant ) . on_hand . count
157152 sl_availability + shipment_availability
158153 end
@@ -174,11 +169,19 @@ def current_shipment_not_already_shipped
174169 end
175170
176171 def enough_stock_at_desired_location
177- unless Spree :: Stock :: Quantifier . new ( variant , desired_stock_location ) . can_supply? ( quantity )
172+ unless desired_location_quantifier . can_supply? ( quantity )
178173 errors . add ( :desired_shipment , :not_enough_stock_at_desired_location )
179174 end
180175 end
181176
177+ def desired_location_quantifier
178+ @desired_location_quantifier ||= Spree ::Stock ::Quantifier . new ( variant , desired_stock_location )
179+ end
180+
181+ def current_location_quantifier
182+ @current_location_quantifier ||= Spree ::Stock ::Quantifier . new ( variant , current_stock_location )
183+ end
184+
182185 def desired_shipment_different_from_current
183186 if desired_shipment . id == current_shipment . id
184187 errors . add ( :desired_shipment , :can_not_transfer_within_same_shipment )
0 commit comments