Checkbox to remove articles not in upload
This commit is contained in:
parent
6ce1b7f928
commit
4d1e102f47
5 changed files with 32 additions and 14 deletions
|
|
@ -138,7 +138,8 @@ class ArticlesController < ApplicationController
|
|||
# Update articles from a spreadsheet
|
||||
def parse_upload
|
||||
uploaded_file = params[:articles]['file']
|
||||
options = {filename: uploaded_file.original_filename}
|
||||
outlist_absent = (params[:articles]['outlist_absent'] == '1')
|
||||
options = {filename: uploaded_file.original_filename, outlist_absent: outlist_absent}
|
||||
@updated_article_pairs, @outlisted_articles, @new_articles = @supplier.sync_from_file uploaded_file.tempfile, options
|
||||
if @updated_article_pairs.empty? && @outlisted_articles.empty? && @new_articles.empty?
|
||||
redirect_to supplier_articles_path(@supplier), :notice => I18n.t('articles.controller.parse_upload.notice')
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class Supplier < ActiveRecord::Base
|
|||
# @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.
|
||||
def sync_from_file(file, options={})
|
||||
all_order_numbers = []
|
||||
updated_article_pairs, outlisted_articles, new_articles = [], [], []
|
||||
FoodsoftFile::parse file, options do |status, new_attrs, line|
|
||||
article = articles.undeleted.where(order_number: new_attrs[:order_number]).first
|
||||
|
|
@ -86,6 +87,11 @@ class Supplier < ActiveRecord::Base
|
|||
# @todo move I18n key to model
|
||||
raise I18n.t('articles.model.error_parse', :msg => status, :line => line.to_s)
|
||||
end
|
||||
|
||||
all_order_numbers << article.order_number if article
|
||||
end
|
||||
if options[:outlist_absent]
|
||||
outlisted_articles += articles.undeleted.where.not(id: all_order_numbers+[nil])
|
||||
end
|
||||
return [updated_article_pairs, outlisted_articles, new_articles]
|
||||
end
|
||||
|
|
@ -126,4 +132,3 @@ class Supplier < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,17 @@
|
|||
%p= t '.text_2'
|
||||
|
||||
= form_for :articles, :url => parse_upload_supplier_articles_path(@supplier),
|
||||
:html => { :multipart => true } do |f|
|
||||
%label(for="articles_file")= t '.file_label'
|
||||
= f.file_field "file"
|
||||
:html => { multipart: true, class: "form-horizontal" } do |f|
|
||||
|
||||
.control-group
|
||||
%label(for="articles_file")= t '.file_label'
|
||||
= f.file_field "file"
|
||||
|
||||
.control-group
|
||||
%label(for="articles_outlist_absent")
|
||||
= f.check_box "outlist_absent"
|
||||
= t '.outlist_absent'
|
||||
|
||||
.form-actions
|
||||
= submit_tag t('.submit'), class: 'btn btn-primary'
|
||||
= link_to t('ui.or_cancel'), supplier_articles_path(@supplier)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue