fix order article add + test

This commit is contained in:
wvengen 2014-02-24 11:37:06 +01:00
parent 775137f7c0
commit f8fca4d630
4 changed files with 28 additions and 16 deletions

View file

@ -1,19 +1,8 @@
module OrderArticlesHelper
def new_order_articles_collection(&block)
if @order.stockit?
articles = StockArticle.undeleted.reorder('articles.name')
else
articles = @order.supplier.articles.undeleted.reorder('articles.name')
end
unless block_given?
block = Proc.new do |a|
pkg_info = pkg_helper(a, plain: true)
a.name + ' ' +
"(#{a.unit}" +
(pkg_info.blank? ? '' : " #{pkg_info}") + ")"
end
end
articles.map {|a| block.call(a)}
def article_label_with_unit(article)
pkg_info = pkg_helper(article, plain: true)
"#{article.name} (#{[article.unit, pkg_info].reject(&:blank?).join(' ')})"
end
end

View file

@ -52,6 +52,14 @@ class Order < ActiveRecord::Base
end
end
def supplier_articles
if stockit?
StockArticle.undeleted.reorder('articles.name')
else
supplier.articles.undeleted.reorder('articles.name')
end
end
# Save ids, and create/delete order_articles after successfully saved the order
def article_ids=(ids)
@article_ids = ids

View file

@ -3,7 +3,7 @@
= link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'}
%h3= t '.title'
.modal-body
= form.association :article, collection: new_order_articles_collection
= form.association :article, collection: @order.supplier_articles, label_method: lambda {|a| article_label_with_unit(a)}
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= form.submit class: 'btn btn-primary'