Changed behaviour of acts_as_paraniod. Finder wrapper removed an replaced by simple named_scope 'without_deleted'.
This commit is contained in:
parent
cd9636a650
commit
325d47b22f
18 changed files with 218 additions and 136 deletions
|
|
@ -11,8 +11,8 @@ class Admin::OrdergroupsController < ApplicationController
|
|||
# if the search field is used
|
||||
conditions = "name LIKE '%#{params[:query]}%'" unless params[:query].nil?
|
||||
|
||||
@total = Ordergroup.count(:conditions => conditions )
|
||||
@ordergroups = Ordergroup.paginate(:conditions => conditions, :page => params[:page],
|
||||
@total = Ordergroup.without_deleted.count(:conditions => conditions )
|
||||
@ordergroups = Ordergroup.without_deleted.paginate(:conditions => conditions, :page => params[:page],
|
||||
:per_page => @per_page, :order => 'name')
|
||||
|
||||
respond_to do |format|
|
||||
|
|
@ -60,7 +60,7 @@ class Admin::OrdergroupsController < ApplicationController
|
|||
@ordergroup = Ordergroup.find(params[:id])
|
||||
@ordergroup.destroy
|
||||
|
||||
redirect_to(admin_Ordergroups_url)
|
||||
redirect_to(admin_ordergroups_url)
|
||||
end
|
||||
|
||||
def memberships
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ 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,
|
||||
:conditions => conditions,
|
||||
:page => params[:page],
|
||||
:per_page => @per_page,
|
||||
:include => :article_category)
|
||||
@total = @supplier.articles.without_deleted.count(:conditions => conditions)
|
||||
@articles = @supplier.articles.without_deleted.paginate(
|
||||
:order => sort,
|
||||
:conditions => conditions,
|
||||
:page => params[:page],
|
||||
:per_page => @per_page,
|
||||
:include => :article_category
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # list.haml
|
||||
|
|
@ -136,7 +138,7 @@ class ArticlesController < ApplicationController
|
|||
|
||||
# Renders a form for editing all articles from a supplier
|
||||
def edit_all
|
||||
@articles = @supplier.articles.all
|
||||
@articles = @supplier.articles.without_deleted
|
||||
end
|
||||
|
||||
# Updates all article of specific supplier
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
|
||||
def auto_complete_for_article_name
|
||||
@articles = @supplier.articles.find(:all,
|
||||
@articles = @supplier.articles.without_deleted.find(:all,
|
||||
:conditions => [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ],
|
||||
:limit => 8)
|
||||
render :partial => 'shared/auto_complete_articles'
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ class Finance::TransactionsController < ApplicationController
|
|||
|
||||
conditions = "name LIKE '%#{params[:query]}%'" unless params[:query].nil?
|
||||
|
||||
@total = Ordergroup.count(:conditions => conditions)
|
||||
@groups = Ordergroup.paginate :conditions => conditions, :page => params[:page],
|
||||
:per_page => @per_page, :order => sort
|
||||
@total = Ordergroup.without_deleted.count(:conditions => conditions)
|
||||
@groups = Ordergroup.without_deleted.paginate :conditions => conditions,
|
||||
:page => params[:page], :per_page => @per_page, :order => sort
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class SuppliersController < ApplicationController
|
|||
helper :deliveries
|
||||
|
||||
def index
|
||||
@suppliers = Supplier.all :order => 'name'
|
||||
@suppliers = Supplier.without_deleted :order => 'name'
|
||||
@deliveries = Delivery.recent
|
||||
end
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class SuppliersController < ApplicationController
|
|||
flash[:notice] = "Lieferant wurde gelöscht"
|
||||
redirect_to suppliers_path
|
||||
rescue => e
|
||||
flash[:error] = _("An error has occurred: ") + e.message
|
||||
flash[:error] = "Ein Fehler ist aufgetreten: " + e.message
|
||||
redirect_to @supplier
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module MessagesHelper
|
|||
[g.name, g.id]
|
||||
end
|
||||
groups += [[" -- Bestellgruppen -- ", ""]]
|
||||
groups += Ordergroup.find(:all, :order => 'name', :include => :memberships).reject{ |g| g.memberships.empty? }.collect do |g|
|
||||
groups += Ordergroup.without_deleted(:order => 'name', :include => :memberships).reject{ |g| g.memberships.empty? }.collect do |g|
|
||||
[g.name, g.id]
|
||||
end
|
||||
groups
|
||||
|
|
|
|||
|
|
@ -10,4 +10,10 @@ module OrdersHelper
|
|||
link_to image_tag("save_pdf.png", :size => "16x16", :border => "0", :alt => "PDF erstellen"),
|
||||
{ :action => action, :id => order, :format => :pdf }, { :title => "PDF erstellen" }
|
||||
end
|
||||
|
||||
def options_for_suppliers_to_select
|
||||
suppliers = Supplier.without_deleted.collect {|s| [ s.name, url_for(:action => "new", :supplier_id => s)] }
|
||||
stockit = [["Lager", url_for(:action => 'new', :supplier_id => 0)]]
|
||||
options_for_select(stockit + suppliers)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#
|
||||
|
||||
class Article < ActiveRecord::Base
|
||||
acts_as_paranoid # Avoid deleting the article for consistency of order-results
|
||||
acts_as_paranoid # Avoid deleting the article for consistency of order-results
|
||||
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
||||
|
||||
# Associations
|
||||
|
|
@ -46,7 +46,7 @@ class Article < ActiveRecord::Base
|
|||
# Callbacks
|
||||
before_save :update_price_history
|
||||
before_destroy :check_article_in_use
|
||||
|
||||
|
||||
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
||||
def price=(price)
|
||||
self[:price] = String.delocalized_decimal(price)
|
||||
|
|
@ -176,7 +176,7 @@ class Article < ActiveRecord::Base
|
|||
|
||||
# Checks if the article is in use before it will deleted
|
||||
def check_article_in_use
|
||||
raise self.name.to_s + _(" cannot be deleted. The article is used in a current order!") if self.in_open_order
|
||||
raise self.name.to_s + " kann nicht gelöscht werden. Der Artikel befindet sich in einer laufenden Bestellung!" if self.in_open_order
|
||||
end
|
||||
|
||||
# Create an ArticlePrice, when the price-attr are changed.
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ class Order < ActiveRecord::Base
|
|||
|
||||
def articles_for_ordering
|
||||
if stockit?
|
||||
StockArticle.available.all(:include => :article_category,
|
||||
StockArticle.available.without_deleted(:include => :article_category,
|
||||
:order => 'article_categories.name, articles.name').reject{ |a|
|
||||
a.quantity_available == 0
|
||||
}.group_by { |a| a.article_category.name }
|
||||
else
|
||||
supplier.articles.available.all.group_by { |a| a.article_category.name }
|
||||
supplier.articles.available.without_deleted.group_by { |a| a.article_category.name }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class Supplier < ActiveRecord::Base
|
|||
has_many :orders
|
||||
has_many :deliveries
|
||||
has_many :invoices
|
||||
belongs_to :shared_supplier # for the sharedLists-App
|
||||
|
||||
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number, :delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity
|
||||
|
||||
|
|
@ -38,17 +39,14 @@ class Supplier < ActiveRecord::Base
|
|||
|
||||
validates_length_of :phone, :in => 8..20
|
||||
validates_length_of :address, :in => 8..50
|
||||
|
||||
# for the sharedLists-App
|
||||
belongs_to :shared_supplier
|
||||
|
||||
|
||||
# sync all articles with the external database
|
||||
# returns an array with articles(and prices), which should be updated (to use in a form)
|
||||
# also returns an array with outlisted_articles, which should be deleted
|
||||
def sync_all
|
||||
updated_articles = Array.new
|
||||
outlisted_articles = Array.new
|
||||
for article in articles
|
||||
for article in articles.without_deleted
|
||||
# try to find the associated shared_article
|
||||
shared_article = article.shared_article
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
require 'digest/sha1'
|
||||
# specific user rights through memberships (see Group)
|
||||
class User < ActiveRecord::Base
|
||||
#TODO: acts_as_paraniod ??
|
||||
|
||||
has_many :memberships, :dependent => :destroy
|
||||
has_many :groups, :through => :memberships
|
||||
has_one :ordergroup, :through => :memberships, :source => :group, :class_name => "Ordergroup"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
Neue Bestellung anlegen für
|
||||
%select{:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;"}
|
||||
%option{:selected => 'selected'}=_ "Choose a supplier..."
|
||||
= options_for_select(Supplier.find(:all).collect {|s| [ s.name, url_for(:action => "new", :supplier_id => s)] })
|
||||
= options_for_suppliers_to_select
|
||||
%br/
|
||||
.left_column{:style => "width:55em"}
|
||||
.box_title
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
- form_tag do
|
||||
Neue Lieferung anlegen für:
|
||||
= select_tag :new_delivery, |
|
||||
options_for_select([" -- Lieferantin wählen --", ""] + |
|
||||
Supplier.find(:all).collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), |
|
||||
options_for_select([[" -- Lieferantin wählen --", ""]] + |
|
||||
Supplier.without_deleted.collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), |
|
||||
:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" |
|
||||
%p
|
||||
= link_to "Lagerbestellung online stellen", new_order_path(:supplier_id => 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue