From 4d796b8e7391539b40bcb5408bb0bab455e8a248 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sat, 7 Feb 2009 15:19:07 +0100 Subject: [PATCH] Since there are StockArticles for each supplier, the StockArticles has to be excluded in normal articles-view. --- app/controllers/articles_controller.rb | 6 +++--- app/models/article.rb | 1 + app/views/suppliers/index.haml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 2a4833be..0d7a7a84 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -28,8 +28,8 @@ class ArticlesController < ApplicationController # if somebody uses the search field: conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil? - @total = @supplier.articles.count(:conditions => conditions) - @articles = @supplier.articles.paginate(:order => sort, + @total = @supplier.articles.not_in_stock.count(:conditions => conditions) + @articles = @supplier.articles.not_in_stock.paginate(:order => sort, :conditions => conditions, :page => params[:page], :per_page => @per_page, @@ -136,7 +136,7 @@ class ArticlesController < ApplicationController # Renders a form for editing all articles from a supplier def edit_all - @articles = @supplier.articles.find :all, + @articles = @supplier.articles.not_in_stock.find :all, :order => 'article_categories.name, articles.name', :include => [:article_category] diff --git a/app/models/article.rb b/app/models/article.rb index e2ab03c2..bc538973 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -35,6 +35,7 @@ class Article < ActiveRecord::Base has_many :article_prices, :order => "created_at" named_scope :available, :conditions => {:availability => true} + named_scope :not_in_stock, :conditions => {:type => nil} # Validations validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id diff --git a/app/views/suppliers/index.haml b/app/views/suppliers/index.haml index 62c6bbfe..e7909b60 100644 --- a/app/views/suppliers/index.haml +++ b/app/views/suppliers/index.haml @@ -21,7 +21,7 @@ %tbody - for supplier in @suppliers %tr{:class => cycle('even','odd', :name => 'suppliers')} - %td= link_to "#{h(supplier.name)} (#{supplier.articles.count})", supplier_articles_path(supplier) + %td= link_to "#{h(supplier.name)} (#{supplier.articles.not_in_stock.count})", supplier_articles_path(supplier) %td=h supplier.phone %td=h supplier.customer_number %td= link_to "Anzeigen", supplier