Removed monkeypatchs to scope variants on inventory_unit and line_item decorators. We need to make the scoping somewhere else in spree2, see #2559

This commit is contained in:
luisramos0
2018-08-19 20:23:31 +01:00
parent f04903bca0
commit 898e41acfb
2 changed files with 0 additions and 44 deletions

View File

@@ -1,16 +0,0 @@
module Spree
InventoryUnit.class_eval do
def self.assign_opening_inventory(order)
return [] unless order.completed?
#increase inventory to meet initial requirements
scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
order.line_items.each do |line_item|
# Scope variant to hub so that stock levels may be subtracted from VariantOverride.
scoper.scope(line_item.variant)
increase(order, line_item.variant, line_item.quantity)
end
end
end
end

View File

@@ -110,34 +110,6 @@ Spree::LineItem.class_eval do
final_weight_volume / quantity
end
# MONKEYPATCH of Spree method
# Enables scoping of variant to hub/shop, stock drawn down from inventory
def update_inventory
return true unless order.completed?
scoper.scope(variant) # this line added
if new_record?
Spree::InventoryUnit.increase(order, variant, quantity)
elsif old_quantity = self.changed_attributes['quantity']
if old_quantity < quantity
Spree::InventoryUnit.increase(order, variant, (quantity - old_quantity))
elsif old_quantity > quantity
Spree::InventoryUnit.decrease(order, variant, (old_quantity - quantity))
end
end
end
# MONKEYPATCH of Spree method
# Enables scoping of variant to hub/shop, stock replaced to inventory
def remove_inventory
return true unless order.completed?
scoper.scope(variant) # this line added
Spree::InventoryUnit.decrease(order, variant, quantity)
end
# MONKEYPATCH of Spree method
# Enables scoping of variant to hub/shop, so we check stock against relevant overrides if they exist
# Also skips stock check if requested quantity is zero