From 82f40de96b035f4327ed9749987da01b83601c9f Mon Sep 17 00:00:00 2001 From: Edin Dazdarevic Date: Sat, 11 Apr 2015 13:51:11 +0200 Subject: [PATCH] when importing first do a lookup by code before creating a new item --- back-office/lib/tasks/ribica.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/back-office/lib/tasks/ribica.rake b/back-office/lib/tasks/ribica.rake index 7732c74..63ca6b7 100644 --- a/back-office/lib/tasks/ribica.rake +++ b/back-office/lib/tasks/ribica.rake @@ -185,9 +185,11 @@ def import_single_item(row, index, logger) succes = true begin lookup = get_column_lookup - item = Item.new + code = row[lookup[:code]] + + item = (Item.find_by code: code) || Item.new item.name = row[lookup[:name_on_ribica]] - item.code = row[lookup[:code]] + item.code = code item.current_input_price = row[lookup[:current_input_price]] || 11.00 item.list_price = row[lookup[:list_price]] || 12.00 item.units_in_pack = row[lookup[:units_in_pack]] @@ -252,6 +254,7 @@ def do_import(validate_only) if validate_only || should_rollback if should_rollback + puts "Import failed, please check the import log file for error details." logger.info "Rolling back because of errors" end