mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove StockItem#stock_location
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
module Spree
|
||||
class StockItem < ApplicationRecord
|
||||
self.ignored_columns += [:stock_location_id]
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
has_many :stock_movements, dependent: :destroy
|
||||
|
||||
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }
|
||||
validates :variant_id, uniqueness: { scope: [:deleted_at] }
|
||||
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0, unless: :backorderable? }
|
||||
|
||||
delegate :weight, to: :variant
|
||||
@@ -39,14 +41,6 @@ module Spree
|
||||
self[:count_on_hand] = value
|
||||
end
|
||||
|
||||
# Other code still calls this.
|
||||
# TODO: remove usage
|
||||
def stock_location
|
||||
@stock_location ||= DefaultStockLocation.find_or_create
|
||||
end
|
||||
|
||||
attr_writer :stock_location
|
||||
|
||||
private
|
||||
|
||||
def process_backorders
|
||||
|
||||
@@ -6,7 +6,7 @@ module Api
|
||||
attributes :id, :name, :producer_name, :image, :sku, :import_date, :tax_category_id,
|
||||
:options_text, :unit_value, :unit_description, :unit_to_display,
|
||||
:display_as, :display_name, :name_to_display, :variant_overrides_count,
|
||||
:price, :on_demand, :on_hand, :in_stock, :stock_location_id, :stock_location_name,
|
||||
:price, :on_demand, :on_hand, :in_stock,
|
||||
:variant_unit, :variant_unit_scale, :variant_unit_name, :variant_unit_with_scale
|
||||
|
||||
has_one :primary_taxon, key: :category_id, embed: :id
|
||||
@@ -44,18 +44,6 @@ module Api
|
||||
object.in_stock?
|
||||
end
|
||||
|
||||
def stock_location_id
|
||||
return if object.stock_items.empty?
|
||||
|
||||
options[:stock_location]&.id || object.stock_items.first.stock_location.id
|
||||
end
|
||||
|
||||
def stock_location_name
|
||||
return if object.stock_items.empty?
|
||||
|
||||
options[:stock_location]&.name || object.stock_items.first.stock_location.name
|
||||
end
|
||||
|
||||
def variant_overrides_count
|
||||
object.variant_overrides.count
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ class CatalogItemBuilder < DfcBuilder
|
||||
|
||||
if variant.stock_items.empty?
|
||||
variant.stock_items << Spree::StockItem.new(
|
||||
stock_location: DefaultStockLocation.find_or_create,
|
||||
variant:,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -22,10 +22,4 @@ RSpec.describe Api::Admin::VariantSerializer do
|
||||
|
||||
expect(serializer.to_json).to match variant.full_name
|
||||
end
|
||||
|
||||
it "serializes the variant stock location id" do
|
||||
serializer = Api::Admin::VariantSerializer.new variant
|
||||
|
||||
expect(serializer.to_json).to match variant.stock_items.first.stock_location.id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user