Since there are StockArticles for each supplier, the StockArticles has

to be excluded in normal articles-view.
This commit is contained in:
Benjamin Meichsner 2009-02-07 15:19:07 +01:00
parent 24b66ee8d4
commit 4d796b8e73
3 changed files with 5 additions and 4 deletions

View File

@ -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]

View File

@ -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

View File

@ -21,7 +21,7 @@
%tbody
- for supplier in @suppliers
%tr{:class => cycle('even','odd', :name => 'suppliers')}
%td= link_to "<b>#{h(supplier.name)}</b> (#{supplier.articles.count})", supplier_articles_path(supplier)
%td= link_to "<b>#{h(supplier.name)}</b> (#{supplier.articles.not_in_stock.count})", supplier_articles_path(supplier)
%td=h supplier.phone
%td=h supplier.customer_number
%td= link_to "Anzeigen", supplier