Merge pull request #3537 from Matt-Yorkley/pi/on_demand_error

Fix nil values in on_hand column
This commit is contained in:
Pau Pérez Fabregat
2019-04-03 11:56:06 +02:00
committed by GitHub
2 changed files with 4 additions and 2 deletions

View File

@@ -254,6 +254,7 @@ module ProductImport
new_product = Spree::Product.new
new_product.assign_attributes(entry.attributes.except('id'))
new_product.supplier_id = entry.producer_id
entry.on_hand = 0 if entry.on_hand.nil?
if new_product.valid?
entry.validates_as = 'new_product' unless entry.errors?

View File

@@ -50,7 +50,7 @@ describe ProductImport::ProductImporter do
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "2", "kg", "", ""]
csv << ["Pea Soup", "User Enterprise", "Vegetables", "8", "5.50", "750", "ml", "", "0"]
csv << ["Salad", "User Enterprise", "Vegetables", "7", "4.50", "1", "", "bags", ""]
csv << ["Hot Cross Buns", "User Enterprise", "Cake", "7", "3.50", "1", "", "buns", "1"]
csv << ["Hot Cross Buns", "User Enterprise", "Cake", nil, "3.50", "1", "", "buns", "1"]
end
File.write('/tmp/test-m.csv', csv_data)
file = File.new('/tmp/test-m.csv')
@@ -122,7 +122,8 @@ describe ProductImport::ProductImporter do
buns = Spree::Product.find_by_name('Hot Cross Buns')
expect(buns.supplier).to eq enterprise
# buns.on_hand).to eq Infinity
expect(buns.on_hand).to eq Float::INFINITY
expect(buns.count_on_hand).to eq 0
expect(buns.price).to eq 3.50
expect(buns.unit_value).to eq 1
expect(buns.variant_unit).to eq 'items'