diff --git a/app/models/spree/stock/quantifier.rb b/app/models/spree/stock/quantifier.rb index 889f210ca3..0cc7fa2f35 100644 --- a/app/models/spree/stock/quantifier.rb +++ b/app/models/spree/stock/quantifier.rb @@ -7,7 +7,7 @@ module Spree def initialize(variant) @variant = variant - @stock_items = fetch_stock_items + @stock_items = @variant.stock_items end def total_on_hand @@ -25,16 +25,6 @@ module Spree def can_supply?(required) total_on_hand >= required || backorderable? end - - private - - def fetch_stock_items - # Don't re-fetch associated stock items from the DB if we've already eager-loaded them - return @variant.stock_items if @variant.stock_items.loaded? - - Spree::StockItem.joins(:stock_location). - where(:variant_id => @variant, Spree::StockLocation.table_name => { active: true }) - end end end end diff --git a/app/models/spree/stock_location.rb b/app/models/spree/stock_location.rb index 77b08e5855..268e3b084c 100644 --- a/app/models/spree/stock_location.rb +++ b/app/models/spree/stock_location.rb @@ -3,7 +3,7 @@ module Spree class StockLocation < ApplicationRecord self.belongs_to_required_by_default = false - self.ignored_columns += [:backorderable_default] + self.ignored_columns += [:backorderable_default, :active] has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location has_many :stock_movements, through: :stock_items @@ -13,8 +13,6 @@ module Spree validates :name, presence: true - scope :active, -> { where(active: true) } - after_create :create_stock_items # Wrapper for creating a new stock item respecting the backorderable config diff --git a/app/views/spree/admin/return_authorizations/_form.html.haml b/app/views/spree/admin/return_authorizations/_form.html.haml index 6d98940471..abea543359 100644 --- a/app/views/spree/admin/return_authorizations/_form.html.haml +++ b/app/views/spree/admin/return_authorizations/_form.html.haml @@ -44,5 +44,5 @@ = f.field_container :stock_location do = f.label :stock_location, t('.stock_location') - = f.select :stock_location_id, Spree::StockLocation.active.all.collect{ |l| [l.name, l.id] }, { style: 'height:100px;', class: 'fullwidth' } + = f.select :stock_location_id, Spree::StockLocation.all.collect{ |l| [l.name, l.id] }, { style: 'height:100px;', class: 'fullwidth' } = f.error_message_on :reason diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb index 7722310478..466c4549a2 100644 --- a/spec/factories/stock_location_factory.rb +++ b/spec/factories/stock_location_factory.rb @@ -9,7 +9,6 @@ FactoryBot.define do city { 'Washington' } zipcode { '20500' } phone { '(202) 456-1111' } - active { true } country { |stock_location| Spree::Country.first || stock_location.association(:country) } state do |stock_location|