Fix product import entry validation

This commit is contained in:
Gaetan Craig-Riou
2024-02-28 10:35:13 +11:00
parent a87f10b2a6
commit b86d8e1603
2 changed files with 7 additions and 9 deletions

View File

@@ -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',

View File

@@ -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)]
)
}