Capping line item quantity at stock takes overrides into account

This commit is contained in:
Rob Harrington
2016-11-11 15:50:12 +11:00
parent 2aad722b4b
commit a8928a0ccc
2 changed files with 15 additions and 1 deletions

View File

@@ -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

View File

@@ -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