mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Capping line item quantity at stock takes overrides into account
This commit is contained in:
@@ -47,6 +47,7 @@ Spree::LineItem.class_eval do
|
||||
|
||||
|
||||
def cap_quantity_at_stock!
|
||||
scoper.scope(variant)
|
||||
update_attributes!(quantity: variant.on_hand) if quantity > variant.on_hand
|
||||
end
|
||||
|
||||
@@ -129,7 +130,7 @@ Spree::LineItem.class_eval do
|
||||
def scoper
|
||||
return @scoper unless @scoper.nil?
|
||||
@scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_final_weight_volume
|
||||
if final_weight_volume.present? && quantity_was > 0
|
||||
|
||||
@@ -75,6 +75,19 @@ module Spree
|
||||
li.quantity.should == 10
|
||||
li.max_quantity.should == 10
|
||||
end
|
||||
|
||||
context "when a variant override is in place" do
|
||||
let!(:hub) { create(:distributor_enterprise) }
|
||||
|
||||
before { li.order.update_attributes(distributor_id: hub.id) }
|
||||
|
||||
let!(:vo) { create(:variant_override, hub: hub, variant: v, count_on_hand: 2) }
|
||||
|
||||
it "caps quantity to override stock level" do
|
||||
li.cap_quantity_at_stock!
|
||||
li.quantity.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "tracking stock when quantity is changed" do
|
||||
|
||||
Reference in New Issue
Block a user