Skip to content

Commit

Permalink
Remove lambda in favor of quantifier.positive_stock
Browse files Browse the repository at this point in the history
  • Loading branch information
spaghetticode committed Mar 7, 2024
1 parent d0a348a commit 2a82493
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/app/models/spree/fulfilment_changer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,10 @@ def handle_stock_counts?
end

def get_available_quantity
positive_stock = ->(shipment) do
on_hand = shipment.stock_location.count_on_hand(variant)
on_hand.positive? ? on_hand : 0
end

if current_stock_location != desired_stock_location
positive_stock.call(desired_shipment)
desired_location_quantifier.positive_stock
else
sl_availability = positive_stock.call(current_shipment)
sl_availability = current_location_quantifier.positive_stock
shipment_availability = current_shipment.inventory_units.where(variant: variant).on_hand.count
sl_availability + shipment_availability
end
Expand All @@ -174,11 +169,19 @@ def current_shipment_not_already_shipped
end

def enough_stock_at_desired_location
unless Spree::Stock::Quantifier.new(variant, desired_stock_location).can_supply?(quantity)
unless desired_location_quantifier.can_supply?(quantity)
errors.add(:desired_shipment, :not_enough_stock_at_desired_location)
end
end

def desired_location_quantifier
@desired_location_quantifier ||= Spree::Stock::Quantifier.new(variant, desired_stock_location)
end

def current_location_quantifier
@current_location_quantifier ||= Spree::Stock::Quantifier.new(variant, current_stock_location)
end

def desired_shipment_different_from_current
if desired_shipment.id == current_shipment.id
errors.add(:desired_shipment, :can_not_transfer_within_same_shipment)
Expand Down

0 comments on commit 2a82493

Please sign in to comment.