From d2dbe6c738d3a3328009dcd8a22ce8655d641445 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 10 Nov 2021 14:49:19 +0100 Subject: [PATCH 1/2] Use distinct to return unique product - Product were displayed twice (or more) in certain condition under order cycle incoming products admin interface --- app/models/spree/product.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 658549e3eef..d5e9c5f929c 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -159,7 +159,8 @@ class Product < ApplicationRecord joins(' LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)'). - where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true) + where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true). + distinct } # -- Scopes From fff2c3ae741caa834b825f2048bd3674f3d4d3f7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 12 Nov 2021 10:55:47 +0100 Subject: [PATCH 2/2] Update spec to take into account the non-duplication of product in inventory --- spec/models/spree/product_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 91cb6cec6bd..3e7f4f02a8f 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -617,18 +617,26 @@ module Spree let(:enterprise) { create(:distributor_enterprise) } let!(:new_variant) { create(:variant) } let!(:hidden_variant) { create(:variant) } - let!(:visible_variant) { create(:variant) } + + let!(:product) { create(:product) } + let!(:visible_variant1) { create(:variant, product: product) } + let!(:visible_variant2) { create(:variant, product: product) } + let!(:hidden_inventory_item) { create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false ) } - let!(:visible_inventory_item) { - create(:inventory_item, enterprise: enterprise, variant: visible_variant, visible: true ) + let!(:visible_inventory_item1) { + create(:inventory_item, enterprise: enterprise, variant: visible_variant1, visible: true ) + } + let!(:visible_inventory_item2) { + create(:inventory_item, enterprise: enterprise, variant: visible_variant2, visible: true ) } let!(:products) { Spree::Product.visible_for(enterprise) } it "lists any products with variants that are listed as visible=true" do - expect(products).to include visible_variant.product + expect(products.length).to eq(1) + expect(products).to include product expect(products).to_not include new_variant.product, hidden_variant.product end end