mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user