Bring changes to stock_item from spree 2.1, the previous version was from spree 2.0.4

This commit is contained in:
Luis Ramos
2020-06-22 18:19:05 +01:00
parent e12e50aa84
commit 34207fc20f

View File

@@ -2,24 +2,23 @@
module Spree
class StockItem < ActiveRecord::Base
acts_as_paranoid
belongs_to :stock_location, class_name: 'Spree::StockLocation'
belongs_to :variant, class_name: 'Spree::Variant'
has_many :stock_movements, dependent: :destroy
validates :stock_location, :variant, presence: true
validates :variant_id, uniqueness: { scope: :stock_location_id }
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0, unless: :backorderable? }
attr_accessible :count_on_hand, :variant, :stock_location, :backorderable, :variant_id
delegate :weight, to: :variant
delegate :name, to: :variant, prefix: true
def backordered_inventory_units
Spree::InventoryUnit.backordered_for_stock_item(self)
end
delegate :name, to: :variant, prefix: true
def adjust_count_on_hand(value)
with_lock do
self.count_on_hand = count_on_hand + value
@@ -38,6 +37,10 @@ module Spree
in_stock? || backorderable?
end
def variant
Spree::Variant.unscoped { super }
end
private
def count_on_hand=(value)