mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
Merge pull request #13001 from chahmedejaz/bugfix/12973-product-import-never-completes
Bulk product import stalling at 66% when missing info
This commit is contained in:
@@ -30,13 +30,13 @@ module Admin
|
||||
def validate_data
|
||||
return unless process_data('validate')
|
||||
|
||||
render json: @importer.import_results, response: 200
|
||||
render json: @importer.import_results
|
||||
end
|
||||
|
||||
def save_data
|
||||
return unless process_data('save')
|
||||
|
||||
render json: @importer.save_results, response: 200
|
||||
render json: @importer.save_results
|
||||
end
|
||||
|
||||
def reset_absent_products
|
||||
@@ -76,7 +76,7 @@ module Admin
|
||||
begin
|
||||
@importer.public_send("#{method}_entries")
|
||||
rescue StandardError => e
|
||||
render json: e.message, response: 500
|
||||
render plain: e.message, status: :internal_server_error
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@@ -79,10 +79,9 @@ module ProductImport
|
||||
if entry.attributes['on_hand'].present?
|
||||
new_variant.on_hand = entry.attributes['on_hand']
|
||||
end
|
||||
check_on_hand_nil(entry, new_variant)
|
||||
end
|
||||
|
||||
check_on_hand_nil(entry, new_variant)
|
||||
|
||||
if new_variant.valid?
|
||||
entry.product_object = new_variant
|
||||
entry.validates_as = 'new_variant' unless entry.errors?
|
||||
|
||||
@@ -1012,6 +1012,30 @@ RSpec.describe ProductImport::ProductImporter do
|
||||
expect(lettuce.count_on_hand).to eq 96 # In different enterprise; unchanged
|
||||
end
|
||||
end
|
||||
|
||||
# Fix https://github.com/openfoodfoundation/openfoodnetwork/issues/12973
|
||||
describe 'update existing product with units and on_hand/on_demand is empty' do
|
||||
let(:csv_data) do
|
||||
CSV.generate do |csv|
|
||||
csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
|
||||
"shipping_category", "on_demand"]
|
||||
csv << ["Beetroot", enterprise3.name, "Vegetables", "", "6.50", "", "g",
|
||||
shipping_category.name, "1"]
|
||||
end
|
||||
end
|
||||
let(:importer) { import_data csv_data }
|
||||
|
||||
it "returns the units error due to invalid data" do
|
||||
importer.validate_entries
|
||||
entries = JSON.parse(importer.entries_json)
|
||||
|
||||
expect(entries.dig('2', 'errors')).to eq(
|
||||
{
|
||||
"units" => "Units can't be blank",
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user