From d5ff1f5c71fd8779baec8fa493471478e47b63da Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 21 Jan 2025 16:08:45 +1100 Subject: [PATCH] Remove StockItem#stock_location --- app/models/spree/stock_item.rb | 12 +++--------- app/serializers/api/admin/variant_serializer.rb | 14 +------------- .../app/services/catalog_item_builder.rb | 1 - .../api/admin/variant_serializer_spec.rb | 6 ------ 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/app/models/spree/stock_item.rb b/app/models/spree/stock_item.rb index fa586a0741..4879d13354 100644 --- a/app/models/spree/stock_item.rb +++ b/app/models/spree/stock_item.rb @@ -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 diff --git a/app/serializers/api/admin/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb index 516351a3e4..7099207433 100644 --- a/app/serializers/api/admin/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -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 diff --git a/engines/dfc_provider/app/services/catalog_item_builder.rb b/engines/dfc_provider/app/services/catalog_item_builder.rb index 11aff59e40..3af8c0e4f4 100644 --- a/engines/dfc_provider/app/services/catalog_item_builder.rb +++ b/engines/dfc_provider/app/services/catalog_item_builder.rb @@ -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 diff --git a/spec/serializers/api/admin/variant_serializer_spec.rb b/spec/serializers/api/admin/variant_serializer_spec.rb index 7c496d721d..60f8ad45d4 100644 --- a/spec/serializers/api/admin/variant_serializer_spec.rb +++ b/spec/serializers/api/admin/variant_serializer_spec.rb @@ -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