Add download for articles
This commit is contained in:
parent
b6f5295267
commit
5a9cc811c9
5 changed files with 52 additions and 0 deletions
|
@ -21,6 +21,12 @@ class ArticlesController < ApplicationController
|
|||
end
|
||||
|
||||
@articles = Article.undeleted.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort)
|
||||
|
||||
if request.format.csv?
|
||||
send_data ArticlesCsv.new(@articles, encoding: 'utf-8').to_csv, filename: 'articles.csv', type: 'text/csv'
|
||||
return
|
||||
end
|
||||
|
||||
@articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
|
||||
|
||||
@articles = @articles.page(params[:page]).per(@per_page)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
= link_to t('.new'), new_supplier_article_path(@supplier), remote: true, class: "btn #{'btn-primary' unless @supplier.shared_supplier}"
|
||||
= link_to t('.edit_all'), edit_all_supplier_articles_path(@supplier), class: 'btn'
|
||||
= link_to t('.upload'), upload_supplier_articles_path(@supplier), class: 'btn'
|
||||
= link_to t('.download'), supplier_articles_path(@supplier, format: :csv), class: 'btn'
|
||||
- if current_user.role_orders?
|
||||
= link_to t('.new_order'), new_order_path(supplier_id: @supplier), class: 'btn'
|
||||
|
||||
|
|
|
@ -455,6 +455,7 @@ de:
|
|||
not_found: Keine Artikel gefunden
|
||||
index:
|
||||
change_supplier: Lieferant wechseln ...
|
||||
download: Artikel herunterladen
|
||||
edit_all: Alle bearbeiten
|
||||
ext_db:
|
||||
import: Suchen/Importieren
|
||||
|
|
|
@ -474,6 +474,7 @@ en:
|
|||
not_found: No articles found
|
||||
index:
|
||||
change_supplier: Change supplier ...
|
||||
download: Download articles
|
||||
edit_all: Edit all
|
||||
ext_db:
|
||||
import: Import article
|
||||
|
|
43
lib/articles_csv.rb
Normal file
43
lib/articles_csv.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
class ArticlesCsv < RenderCSV
|
||||
include ApplicationHelper
|
||||
|
||||
def header
|
||||
[
|
||||
'',
|
||||
Article.human_attribute_name(:order_number),
|
||||
Article.human_attribute_name(:name),
|
||||
Article.human_attribute_name(:note),
|
||||
Article.human_attribute_name(:manufacturer),
|
||||
Article.human_attribute_name(:origin),
|
||||
Article.human_attribute_name(:unit),
|
||||
Article.human_attribute_name(:price),
|
||||
Article.human_attribute_name(:tax),
|
||||
Article.human_attribute_name(:deposit),
|
||||
Article.human_attribute_name(:unit_quantity),
|
||||
'',
|
||||
'',
|
||||
Article.human_attribute_name(:article_category),
|
||||
]
|
||||
end
|
||||
|
||||
def data
|
||||
@object.each do |o|
|
||||
yield [
|
||||
'',
|
||||
o.order_number,
|
||||
o.name,
|
||||
o.note,
|
||||
o.manufacturer,
|
||||
o.origin,
|
||||
o.unit,
|
||||
o.price,
|
||||
o.tax,
|
||||
o.deposit,
|
||||
o.unit_quantity,
|
||||
'',
|
||||
'',
|
||||
o.article_category.try(:name),
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue