From 34207fc20ffbd5a5463366e573daf4fd06d4ff3d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 22 Jun 2020 18:19:05 +0100 Subject: [PATCH] Bring changes to stock_item from spree 2.1, the previous version was from spree 2.0.4 --- app/models/spree/stock_item.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/spree/stock_item.rb b/app/models/spree/stock_item.rb index cf86103453..e6df19b03a 100644 --- a/app/models/spree/stock_item.rb +++ b/app/models/spree/stock_item.rb @@ -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)