mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Merge pull request #8876 from SarvarKh/product-import-validation
Fix product import on existing, empty unit_type and variant_unit
This commit is contained in:
@@ -73,11 +73,13 @@ module ProductImport
|
||||
'variant_unit_scale', 'primary_taxon_id')
|
||||
)
|
||||
new_variant.save
|
||||
if entry.attributes['on_demand'].present?
|
||||
new_variant.on_demand = entry.attributes['on_demand']
|
||||
end
|
||||
if entry.attributes['on_hand'].present?
|
||||
new_variant.on_hand = entry.attributes['on_hand']
|
||||
if new_variant.persisted?
|
||||
if entry.attributes['on_demand'].present?
|
||||
new_variant.on_demand = entry.attributes['on_demand']
|
||||
end
|
||||
if entry.attributes['on_hand'].present?
|
||||
new_variant.on_hand = entry.attributes['on_hand']
|
||||
end
|
||||
end
|
||||
|
||||
new_variant.product_id = product_id
|
||||
|
||||
@@ -55,6 +55,54 @@ describe ProductImport::EntryValidator do
|
||||
)
|
||||
end
|
||||
|
||||
describe "variant validation" do
|
||||
let(:potatoes) {
|
||||
create(
|
||||
:simple_product,
|
||||
supplier: enterprise,
|
||||
on_hand: '100',
|
||||
name: 'Potatoes',
|
||||
unit_value: 1000,
|
||||
variant_unit_scale: 1000,
|
||||
variant_unit: 'weight'
|
||||
)
|
||||
}
|
||||
|
||||
let(:potato_variant) do
|
||||
ProductImport::SpreadsheetEntry.new(
|
||||
unscaled_units: "1",
|
||||
units: "1",
|
||||
unit_type: "",
|
||||
variant_unit_name: "",
|
||||
name: potatoes.name,
|
||||
display_name: 'Potatoes',
|
||||
enterprise: enterprise,
|
||||
enterprise_id: enterprise.id,
|
||||
producer: enterprise,
|
||||
producer_id: enterprise.id,
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
allow(import_settings).to receive(:dig)
|
||||
allow(spreadsheet_data).to receive(:tax_index)
|
||||
allow(spreadsheet_data).to receive(:shipping_index)
|
||||
allow(spreadsheet_data).to receive(:categories_index)
|
||||
allow(entry_validator).to receive(:enterprise_validation)
|
||||
allow(entry_validator).to receive(:tax_and_shipping_validation)
|
||||
allow(entry_validator).to receive(:variant_of_product_validation)
|
||||
allow(entry_validator).to receive(:category_validation)
|
||||
allow(entry_validator).to receive(:shipping_presence_validation)
|
||||
allow(entry_validator).to receive(:product_validation)
|
||||
end
|
||||
|
||||
it "validates a product" do
|
||||
entries = [potato_variant]
|
||||
entry_validator.validate_all(entries)
|
||||
expect(potato_variant.errors.count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "inventory validation" do
|
||||
before do
|
||||
allow(entry_validator).to receive(:import_into_inventory?) { true }
|
||||
|
||||
Reference in New Issue
Block a user