allow import of files with categories that do not exist (map to no category)
This commit is contained in:
parent
a6688b3b43
commit
3da27734c7
1 changed files with 4 additions and 1 deletions
|
@ -145,14 +145,17 @@ class ArticlesController < ApplicationController
|
||||||
begin
|
begin
|
||||||
@articles = Array.new
|
@articles = Array.new
|
||||||
articles, outlisted_articles = FoodsoftFile::parse(params[:articles]["file"])
|
articles, outlisted_articles = FoodsoftFile::parse(params[:articles]["file"])
|
||||||
|
no_category = ArticleCategory.new
|
||||||
articles.each do |row|
|
articles.each do |row|
|
||||||
|
# fallback to Others category
|
||||||
|
category = (ArticleCategory.find_by_name(row[:category]) or no_category)
|
||||||
# creates a new article and price
|
# creates a new article and price
|
||||||
article = Article.new( :name => row[:name],
|
article = Article.new( :name => row[:name],
|
||||||
:note => row[:note],
|
:note => row[:note],
|
||||||
:manufacturer => row[:manufacturer],
|
:manufacturer => row[:manufacturer],
|
||||||
:origin => row[:origin],
|
:origin => row[:origin],
|
||||||
:unit => row[:unit],
|
:unit => row[:unit],
|
||||||
:article_category => ArticleCategory.find_by_name(row[:category]),
|
:article_category => category,
|
||||||
:price => row[:price],
|
:price => row[:price],
|
||||||
:unit_quantity => row[:unit_quantity],
|
:unit_quantity => row[:unit_quantity],
|
||||||
:order_number => row[:number],
|
:order_number => row[:number],
|
||||||
|
|
Loading…
Reference in a new issue