Allow synchronising units when uploading

This commit is contained in:
wvengen 2015-04-10 20:05:42 +02:00
parent 4d1e102f47
commit c30ec67548
6 changed files with 37 additions and 11 deletions

View file

@ -60,6 +60,7 @@ class Supplier < ActiveRecord::Base
# @param file [File] Spreadsheet file to parse
# @param options [Hash] Options passed to {FoodsoftFile#parse} except when listed here.
# @option options [Boolean] :outlist_absent Set to +true+ to remove articles not in spreadsheet.
# @option options [Boolean] :convert_units Omit or set to +true+ to keep current units, recomputing unit quantity and price.
def sync_from_file(file, options={})
all_order_numbers = []
updated_article_pairs, outlisted_articles, new_articles = [], [], []
@ -73,7 +74,7 @@ class Supplier < ActiveRecord::Base
if article.nil?
new_articles << new_article
else
unequal_attributes = article.unequal_attributes(new_article)
unequal_attributes = article.unequal_attributes(new_article, options.slice(:convert_units))
unless unequal_attributes.empty?
article.attributes = unequal_attributes
updated_article_pairs << [article, unequal_attributes]