From a1ca9f368d1a7b3d8ee48b5ea25294a95bee29e4 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 7 Sep 2009 10:57:49 +0200 Subject: [PATCH] Fixed bug when adding new article to a stock order (balancing controller) --- .../finance/balancing_controller.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 0616c190..4bde9cf9 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -79,15 +79,18 @@ class Finance::BalancingController < ApplicationController def auto_complete_for_article_name order = Order.find(params[:order_id]) - type = order.stockit? ? "type = 'StockArticle'" : "type IS NULL" - @articles = Article.find(:all, - :conditions => [ "supplier_id = ? AND #{type} AND LOWER(name) LIKE ?", - order.supplier_id, - '%' + params[:article][:name].downcase + '%' ], - :order => 'name ASC', - :limit => 8) + find_params = { + :conditions => ["LOWER(articles.name) LIKE ?", "%#{params[:article][:name].downcase}%" ], + :order => 'articles.name ASC', + :limit => 8 + } + @articles = if order.stockit? + StockArticle.all find_params + else + order.supplier.articles.all find_params + end + render :partial => 'shared/auto_complete_articles' - end def create_order_article