From b86d8e1603efd224a59747cfa1848ec369cdc5e3 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 28 Feb 2024 10:35:13 +1100 Subject: [PATCH] Fix product import entry validation --- app/models/product_import/entry_validator.rb | 4 +--- spec/models/product_import/entry_validator_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 34369fe44d..5e7172948b 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -287,9 +287,7 @@ module ProductImport end def inventory_validation(entry) - products = Spree::Product.where(supplier_id: entry.producer_id, - name: entry.name, - deleted_at: nil) + products = Spree::Product.in_supplier(entry.producer_id).where(name: entry.name) if products.empty? mark_as_invalid(entry, attribute: 'name', diff --git a/spec/models/product_import/entry_validator_spec.rb b/spec/models/product_import/entry_validator_spec.rb index 3f9ef97209..47512e5a78 100644 --- a/spec/models/product_import/entry_validator_spec.rb +++ b/spec/models/product_import/entry_validator_spec.rb @@ -63,12 +63,12 @@ RSpec.describe ProductImport::EntryValidator do let(:potatoes) { create( :simple_product, - supplier: enterprise, on_hand: '100', name: 'Potatoes', unit_value: 1000, variant_unit_scale: 1000, - variant_unit: 'weight' + variant_unit: 'weight', + variants: [create(:variant, supplier: enterprise)] ) } @@ -119,24 +119,24 @@ RSpec.describe ProductImport::EntryValidator do let!(:product_g) { create( :simple_product, - supplier: enterprise, on_hand: '100', name: 'Tomato', unit_value: 500, variant_unit_scale: 1, - variant_unit: 'weight' + variant_unit: 'weight', + variants: [create(:variant, supplier: enterprise, unit_value: 500)] ) } let!(:product_kg) { create( :simple_product, - supplier: enterprise, on_hand: '100', name: 'Potatoes', unit_value: 1000, variant_unit_scale: 1000, - variant_unit: 'weight' + variant_unit: 'weight', + variants: [create(:variant, supplier: enterprise, unit_value: 1000)] ) }