Ignore StockLocation#active, it's always active

This commit is contained in:
Maikel Linke
2024-10-02 16:31:19 +10:00
parent 4b1d7d8a41
commit 99c098f567
4 changed files with 3 additions and 16 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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|