From c328ee8087f34965186957c8b44d227994c8fead Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 19 Jun 2024 10:42:24 +1000 Subject: [PATCH] Remove stockable_by from Product and Variant It's not used anymore --- app/models/spree/product.rb | 11 ----------- app/models/spree/variant.rb | 11 ----------- spec/models/spree/product_spec.rb | 26 -------------------------- spec/models/spree/variant_spec.rb | 24 ------------------------ 4 files changed, 72 deletions(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index a59f1240c0..a8ae210631 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -165,17 +165,6 @@ module Spree end } - scope :stockable_by, lambda { |enterprise| - return where('1=0') if enterprise.blank? - - permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise.id) - .with_permission(:add_to_order_cycle) - .where(enterprises: { is_primary_producer: true }) - .pluck(:parent_id) - - in_supplier([enterprise.id].union(permitted_producer_ids)) - } - scope :active, lambda { where(spree_products: { deleted_at: nil }) } def self.group_by_products_id diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 5bca9d31df..45a4e993a2 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -143,17 +143,6 @@ module Spree .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) } - scope :stockable_by, lambda { |enterprise| - return where("1=0") if enterprise.blank? - - permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise.id) - .with_permission(:add_to_order_cycle) - .where(enterprises: { is_primary_producer: true }) - .pluck(:parent_id) - - where(supplier: [enterprise.id].union(permitted_producer_ids)) - } - scope :with_properties, lambda { |property_ids| left_outer_joins(:supplier_properties). where(producer_properties: { property_id: property_ids }) diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 0375fcf971..208f4bde81 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -579,32 +579,6 @@ module Spree end end - describe 'stockable_by' do - let(:shop) { create(:distributor_enterprise) } - let(:add_to_oc_producer) { create(:supplier_enterprise) } - let(:other_producer) { create(:supplier_enterprise) } - let(:p1) { create(:simple_product) } - let(:p2) { create(:simple_product) } - let(:p3) { create(:simple_product) } - - before do - create(:variant, product: p1, supplier: shop) - create(:variant, product: p2, supplier: add_to_oc_producer) - create(:variant, product: p3, supplier: other_producer) - - create(:enterprise_relationship, parent: add_to_oc_producer, child: shop, - permissions_list: [:add_to_order_cycle]) - create(:enterprise_relationship, parent: other_producer, child: shop, - permissions_list: [:manage_products]) - end - - it 'shows products produced by the enterprise and any producers granting P-OC' do - stockable_products = Spree::Product.stockable_by(shop) - expect(stockable_products).to include p1, p2 - expect(stockable_products).not_to include p3 - end - end - describe "imported_on" do let!(:v1) { create(:variant, import_date: 1.day.ago) } let!(:v2) { create(:variant, import_date: 2.days.ago) } diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 2252d589e4..c681066ae6 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -448,30 +448,6 @@ RSpec.describe Spree::Variant do end end - describe '.stockable_by' do - let(:shop) { create(:distributor_enterprise) } - let(:add_to_oc_producer) { create(:supplier_enterprise) } - let(:other_producer) { create(:supplier_enterprise) } - let!(:v1) { create(:variant, product: create(:simple_product), supplier: shop ) } - let!(:v2) { - create(:variant, product: create(:simple_product), supplier: add_to_oc_producer ) - } - let!(:v3) { create(:variant, product: create(:simple_product), supplier: other_producer ) } - - before do - create(:enterprise_relationship, parent: add_to_oc_producer, child: shop, - permissions_list: [:add_to_order_cycle]) - create(:enterprise_relationship, parent: other_producer, child: shop, - permissions_list: [:manage_products]) - end - - it 'shows variants produced by the enterprise and any producers granting P-OC' do - stockable_variants = Spree::Variant.stockable_by(shop) - expect(stockable_variants).to include v1, v2 - expect(stockable_variants).not_to include v3 - end - end - describe ".with_properties" do let!(:variant_without_wanted_property_on_supplier) { create(:variant, supplier: supplier_without_wanted_property)