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: # if somebody uses the search field:
conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil? conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
@total = @supplier.articles.count(:conditions => conditions) @total = @supplier.articles.not_in_stock.count(:conditions => conditions)
@articles = @supplier.articles.paginate(:order => sort, @articles = @supplier.articles.not_in_stock.paginate(:order => sort,
:conditions => conditions, :conditions => conditions,
:page => params[:page], :page => params[:page],
:per_page => @per_page, :per_page => @per_page,
@ -136,7 +136,7 @@ class ArticlesController < ApplicationController
# Renders a form for editing all articles from a supplier # Renders a form for editing all articles from a supplier
def edit_all def edit_all
@articles = @supplier.articles.find :all, @articles = @supplier.articles.not_in_stock.find :all,
:order => 'article_categories.name, articles.name', :order => 'article_categories.name, articles.name',
:include => [:article_category] :include => [:article_category]

View file

@ -35,6 +35,7 @@ class Article < ActiveRecord::Base
has_many :article_prices, :order => "created_at" has_many :article_prices, :order => "created_at"
named_scope :available, :conditions => {:availability => true} named_scope :available, :conditions => {:availability => true}
named_scope :not_in_stock, :conditions => {:type => nil}
# Validations # Validations
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id

View file

@ -21,7 +21,7 @@
%tbody %tbody
- for supplier in @suppliers - for supplier in @suppliers
%tr{:class => cycle('even','odd', :name => '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.phone
%td=h supplier.customer_number %td=h supplier.customer_number
%td= link_to "Anzeigen", supplier %td= link_to "Anzeigen", supplier