migrate to Rails 4.0 (closes foodcoops#214)

Conflicts:
	Gemfile.lock
This commit is contained in:
wvengen 2014-02-20 15:04:53 +01:00
parent 12d1221bfc
commit 7841245795
97 changed files with 659 additions and 557 deletions

View File

@ -1,6 +1,6 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
services:
- redis-server
env: COVERALLS=1

31
Gemfile
View File

@ -1,19 +1,17 @@
# A sample Gemfile
source "https://rubygems.org"
ruby "1.9.3"
ruby "2.0.0"
gem "rails", '~> 3.2.9'
gem "rails", '~> 4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'less-rails'
gem 'uglifier', '>= 1.0.3'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'less-rails'
gem 'uglifier', '>= 1.0.3'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
end
gem 'jquery-rails'
gem 'select2-rails'
@ -27,19 +25,20 @@ gem 'prawn'
gem 'haml-rails'
gem 'kaminari'
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
gem 'client_side_validations', git: 'git://github.com/bcardarella/client_side_validations.git', branch: '4-0-beta'
gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git'
gem 'inherited_resources'
gem 'localize_input', git: "git://github.com/bennibu/localize_input.git"
gem 'daemons'
gem 'twitter-bootstrap-rails'
gem 'simple-navigation'
gem 'simple-navigation-bootstrap'
gem 'meta_search'
gem 'ransack'
gem 'acts_as_tree'
gem "rails-settings-cached", "0.2.4"
gem "rails-settings-cached", "0.3.1"
gem 'resque'
gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb
gem 'protected_attributes'
# we use the git version of acts_as_versioned, and need to include it in this Gemfile
gem 'acts_as_versioned', git: 'git://github.com/technoweenie/acts_as_versioned.git'

View File

@ -1,3 +1,10 @@
GIT
remote: git://github.com/bcardarella/client_side_validations.git
revision: 9461cb92e1dfb64895d590c6d435cdf48fcede45
branch: 4-0-beta
specs:
client_side_validations (3.2.2)
GIT
remote: git://github.com/bennibu/localize_input.git
revision: 5eb188d2525a073d09e142cf8b0b04e6ace6e7b0
@ -19,6 +26,14 @@ GIT
i18n-js (2.1.2)
i18n
GIT
remote: git://github.com/saveritemedical/client_side_validations-simple_form.git
revision: b97c938be745de1134169026425aa0c990b8b072
specs:
client_side_validations-simple_form (2.1.0)
client_side_validations (~> 3.2.1)
simple_form (>= 2.1.0, < 4.0)
GIT
remote: git://github.com/technoweenie/acts_as_versioned.git
revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b
@ -33,42 +48,40 @@ PATH
acts_as_versioned
content_for_in_controllers
diffy
rails (~> 3.2.15)
rails
wikicloth
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.17)
actionpack (= 3.2.17)
actionmailer (4.0.3)
actionpack (= 4.0.3)
mail (~> 2.5.4)
actionpack (3.2.17)
activemodel (= 3.2.17)
activesupport (= 3.2.17)
builder (~> 3.0.0)
actionpack (4.0.3)
activesupport (= 4.0.3)
builder (~> 3.1.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.17)
activesupport (= 3.2.17)
builder (~> 3.0.0)
activerecord (3.2.17)
activemodel (= 3.2.17)
activesupport (= 3.2.17)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.17)
activemodel (= 3.2.17)
activesupport (= 3.2.17)
activesupport (3.2.17)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.3)
activesupport (= 4.0.3)
builder (~> 3.1.0)
activerecord (4.0.3)
activemodel (= 4.0.3)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.3)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.3)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
acts_as_tree (1.5.0)
activerecord (>= 3.0.0)
arel (3.0.3)
arel (4.0.2)
atomic (1.1.14)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
@ -76,7 +89,7 @@ GEM
debug_inspector (>= 0.0.1)
bootstrap-datepicker-rails (1.3.0.1)
railties (>= 3.0)
builder (3.0.4)
builder (3.1.4)
bullet (4.8.0)
activesupport
uniform_notifier (>= 1.4.0)
@ -99,14 +112,10 @@ GEM
childprocess (0.5.1)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
client_side_validations (3.2.6)
client_side_validations-simple_form (2.1.0)
client_side_validations (~> 3.2.5)
simple_form (~> 2.1.0)
coderay (1.1.0)
coffee-rails (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
@ -143,11 +152,11 @@ GEM
ffi (1.9.3)
haml (4.0.5)
tilt
haml-rails (0.4)
actionpack (>= 3.1, < 4.1)
activesupport (>= 3.1, < 4.1)
haml (>= 3.1, < 4.1)
railties (>= 3.1, < 4.1)
haml-rails (0.5.3)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0)
railties (>= 4.0.1)
has_scope (0.6.0.rc)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
@ -160,7 +169,6 @@ GEM
responders (~> 1.0.0.rc)
iso (0.2.0)
i18n
journey (1.0.4)
jquery-rails (3.1.0)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
@ -177,73 +185,68 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mailcatcher (0.5.12)
activesupport (~> 3.0)
eventmachine (~> 1.0.0)
haml (>= 3.1, < 5)
mail (~> 2.3)
sinatra (~> 1.2)
skinny (~> 0.2.3)
sqlite3 (~> 1.3)
thin (~> 1.5.0)
meta_search (1.1.3)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
polyamorous (~> 0.5.0)
mailcatcher (0.2.4)
eventmachine
haml
i18n
json
mail
sinatra
skinny (>= 0.1.2)
sqlite3-ruby
thin
mime-types (1.25.1)
mini_portile (0.5.2)
minitest (4.7.5)
mono_logger (1.1.0)
multi_json (1.8.4)
mysql2 (0.3.15)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
net-ssh (2.8.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
pdf-core (0.1.6)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyamorous (0.6.4)
activerecord (>= 3.0)
polyglot (0.3.4)
prawn (0.15.0)
pdf-core (~> 0.1.3)
ttfunk (~> 1.1.0)
protected_attributes (1.0.5)
activemodel (>= 4.0.1, < 5.0)
quiet_assets (1.0.2)
railties (>= 3.1, < 5.0)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack (1.5.2)
rack-protection (1.5.2)
rack
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.17)
actionmailer (= 3.2.17)
actionpack (= 3.2.17)
activerecord (= 3.2.17)
activeresource (= 3.2.17)
activesupport (= 3.2.17)
bundler (~> 1.0)
railties (= 3.2.17)
rails (4.0.3)
actionmailer (= 4.0.3)
actionpack (= 4.0.3)
activerecord (= 4.0.3)
activesupport (= 4.0.3)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.3)
sprockets-rails (~> 2.0.0)
rails-assets-listjs (0.2.0.beta.4)
railties (>= 3.1)
rails-i18n (3.0.0)
i18n (~> 0.5)
rails (>= 3.0.0, < 4.0.0)
rails-settings-cached (0.2.4)
rails (>= 3.0.0)
railties (3.2.17)
actionpack (= 3.2.17)
activesupport (= 3.2.17)
rack-ssl (~> 1.3.2)
rails-i18n (4.0.1)
i18n (~> 0.6)
rails (~> 4.0)
rails-settings-cached (0.3.1)
rails (>= 4.0.0.beta1)
railties (4.0.3)
actionpack (= 4.0.3)
activesupport (= 4.0.3)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
thor (>= 0.18.1, < 2.0)
rake (10.1.1)
rdoc (3.12.2)
json (~> 1.4)
ransack (1.1.0)
actionpack (>= 3.0)
activerecord (>= 3.0)
polyamorous (~> 0.6.0)
redis (3.0.7)
redis-namespace (1.4.1)
redis (~> 3.0.4)
@ -280,10 +283,10 @@ GEM
ruby-prof (0.14.2)
rubyzip (1.1.0)
sass (3.2.14)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets-rails (~> 2.0.0)
select2-rails (3.5.2)
thor (~> 0.14)
selenium-webdriver (2.39.0)
@ -296,9 +299,9 @@ GEM
simple-navigation-bootstrap (1.0.0)
railties (>= 3.1)
simple-navigation (>= 3.7.0)
simple_form (2.1.1)
actionpack (~> 3.0)
activemodel (~> 3.0)
simple_form (3.0.1)
actionpack (>= 4.0.0, < 4.1)
activemodel (>= 4.0.0, < 4.1)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
@ -311,12 +314,18 @@ GEM
skinny (0.2.3)
eventmachine (~> 1.0.0)
thin (~> 1.5.0)
sprockets (2.2.2)
sprockets (2.10.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.8)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
sshkit (1.3.0)
net-scp (>= 1.1.2)
net-ssh
@ -331,6 +340,8 @@ GEM
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
tins (1.0.0)
treetop (1.4.15)
@ -375,9 +386,9 @@ DEPENDENCIES
capistrano-rails
capistrano-rvm!
capybara
client_side_validations
client_side_validations-simple_form
coffee-rails (~> 3.2.1)
client_side_validations!
client_side_validations-simple_form!
coffee-rails (~> 4.0.0)
connection_pool
coveralls
daemons
@ -395,21 +406,22 @@ DEPENDENCIES
less-rails
localize_input!
mailcatcher
meta_search
mysql2
prawn
protected_attributes
quiet_assets
rails (~> 3.2.9)
rails (~> 4.0.0)
rails-assets-listjs (= 0.2.0.beta.4)
rails-i18n
rails-settings-cached (= 0.2.4)
rails-settings-cached (= 0.3.1)
ransack
resque
rspec-core
rspec-expectations
rspec-rails
rspec-rerun
ruby-prof
sass-rails (~> 3.2.3)
sass-rails (~> 4.0.0)
select2-rails
selenium-webdriver
simple-navigation

View File

@ -3,8 +3,8 @@ class Admin::BaseController < ApplicationController
def index
@user = self.current_user
@groups = Group.find(:all, :limit => 10, :order => 'created_on DESC', :conditions => {:deleted_at => nil})
@users = User.find(:all, :limit => 10, :order => 'created_on DESC')
@groups = Group.where(deleted_at: nil).order('created_on DESC').limit(10)
@users = User.order('created_on DESC').limit(10)
end
end

View File

@ -15,6 +15,6 @@ class Admin::WorkgroupsController < Admin::BaseController
@workgroup.destroy
redirect_to admin_workgroups_url, notice: t('admin.workgroups.destroy.notice')
rescue => error
redirect_to admin_workgroups_url, alert: t('admin.workgroups.destroy.error')
redirect_to admin_workgroups_url, alert: t('admin.workgroups.destroy.error', error: error.message)
end
end

View File

@ -199,11 +199,11 @@ class ArticlesController < ApplicationController
# renders a view to import articles in local database
#
def shared
# build array of keywords, required for meta search _all suffix
params[:search][:name_contains_all] = params[:search][:name_contains_all].split(' ') if params[:search]
# build array of keywords, required for ransack _all suffix
params[:q][:name_cont_all] = params[:q][:name_cont_all].split(' ') if params[:q]
# Build search with meta search plugin
@search = @supplier.shared_supplier.shared_articles.search(params[:search])
@articles = @search.page(params[:page]).per(10)
@search = @supplier.shared_supplier.shared_articles.search(params[:q])
@articles = @search.result.page(params[:page]).per(10)
render :layout => false
end

View File

@ -4,7 +4,7 @@ class DeliveriesController < ApplicationController
before_filter :find_supplier, :exclude => :fill_new_stock_article_form
def index
@deliveries = @supplier.deliveries.all :order => 'delivered_on DESC'
@deliveries = @supplier.deliveries.order('delivered_on DESC')
end
def show

View File

@ -16,13 +16,13 @@ class Finance::BalancingController < Finance::BaseController
sort_param = params['sort'] || 'name'
@articles = case sort_param
when 'name' then
OrderArticle.sort_by_name(@articles)
@articles.order('articles.name ASC')
when 'name_reverse' then
OrderArticle.sort_by_name(@articles).reverse
@articles.order('articles.name DESC')
when 'order_number' then
OrderArticle.sort_by_order_number(@articles)
@articles.order('articles.order_number ASC')
when 'order_number_reverse' then
OrderArticle.sort_by_order_number(@articles).reverse
@articles.order('articles.order_number DESC')
else
@articles
end

View File

@ -4,7 +4,7 @@ class Foodcoop::WorkgroupsController < ApplicationController
:except => [:index]
def index
@workgroups = Workgroup.all :order => "name"
@workgroups = Workgroup.order("name")
end
def edit

View File

@ -74,8 +74,7 @@ class GroupOrdersController < ApplicationController
end
def ensure_open_order
@order = Order.find((params[:order_id] || params[:group_order][:order_id]),
:include => [:supplier, :order_articles])
@order = Order.includes([:supplier, :order_articles]).find(params[:order_id] || params[:group_order][:order_id])
unless @order.open?
flash[:notice] = I18n.t('group_orders.errors.closed')
redirect_to :action => 'index'

View File

@ -21,7 +21,7 @@ class OrdersController < ApplicationController
else
sort = "ends DESC"
end
@orders = Order.closed.page(params[:page]).per(@per_page).includes(:supplier).order(sort)
@orders = Order.closed.includes(:supplier).order(sort).page(params[:page]).per(@per_page)
end
# Gives a view for the results to a specific order
@ -145,7 +145,7 @@ class OrdersController < ApplicationController
text += "****** " + I18n.t('orders.fax.articles') + "\n\n"
text += I18n.t('orders.fax.number') + " " + I18n.t('orders.fax.amount') + " " + I18n.t('orders.fax.name') + "\n"
# now display all ordered articles
@order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa|
@order.order_articles.ordered.includes([:article, :article_price]).each do |oa|
number = oa.article.order_number
(8 - number.size).times { number += " " }
quantity = oa.units_to_order.to_i.to_s

View File

@ -58,7 +58,7 @@ class OrderFax < OrderPdf
# Articles
total = 0
data = [I18n.t('documents.order_fax.rows')]
data += @order.order_articles.ordered.all(include: :article).collect do |a|
data += @order.order_articles.ordered.includes(:article).collect do |a|
subtotal = a.units_to_order * a.price.unit_quantity * a.price.price
total += subtotal
[a.article.order_number,

View File

@ -60,13 +60,13 @@ class OrderMatrix < OrderPdf
# Collect group results
groups_data = [header]
@order.group_orders.includes(:ordergroup).all.each do |group_order|
@order.group_orders.includes(:ordergroup).each do |group_order|
group_result = [group_order.ordergroup.name.truncate(20)]
for order_article in current_order_articles
# get the Ordergroup result for this order_article
goa = order_article.group_order_articles.first conditions: { group_order_id: group_order.id }
goa = order_article.group_order_articles.where(group_order_id: group_order.id).first
group_result << ((goa.nil? || goa.result == 0) ? "" : goa.result.to_i)
end
groups_data << group_result

View File

@ -14,6 +14,6 @@ module ArticlesHelper
# Flatten search params, used in import from external database
def search_params
Hash[params[:search].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }]
Hash[params[:q].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }]
end
end
end

View File

@ -13,7 +13,7 @@ module OrdersHelper
def options_for_suppliers_to_select
options = [[I18n.t('helpers.orders.option_choose')]]
options += Supplier.all.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] }
options += Supplier.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] }
options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]]
options_for_select(options)
end
@ -98,7 +98,7 @@ module OrdersHelper
if group_orders.count == 0
return txt
else
desc = group_orders.all.map {|g| g.ordergroup.name}.join(', ')
desc = group_orders.includes(:ordergroup).map {|g| g.ordergroup.name}.join(', ')
content_tag(:abbr, txt, title: desc).html_safe
end
end

View File

@ -3,6 +3,7 @@
class DeltaInput < SimpleForm::Inputs::StringInput
# for now, need to pass id or it won't work
def input
@input_html_options[:type] = 'text'
@input_html_options[:data] ||= {}
@input_html_options[:data][:delta] ||= 1
@input_html_options[:autocomplete] ||= 'off'

View File

@ -7,11 +7,11 @@ class Article < ActiveRecord::Base
# Associations
belongs_to :supplier
belongs_to :article_category
has_many :article_prices, :order => "created_at DESC"
has_many :article_prices, -> { order("created_at DESC") }
scope :undeleted, -> { where(deleted_at: nil) }
scope :available, -> { undeleted.where(availability: true) }
scope :not_in_stock, :conditions => {:type => nil}
scope :not_in_stock, -> { where(type: nil) }
# Validations
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category
@ -44,7 +44,7 @@ class Article < ActiveRecord::Base
# If the article is used in an open Order, the Order will be returned.
def in_open_order
@in_open_order ||= begin
order_articles = OrderArticle.all(:conditions => ['order_id IN (?)', Order.open.collect(&:id)])
order_articles = OrderArticle.where(order_id: Order.open.collect(&:id))
order_article = order_articles.detect {|oa| oa.article_id == id }
order_article ? order_article.order : nil
end

View File

@ -2,12 +2,9 @@ class Delivery < ActiveRecord::Base
belongs_to :supplier
has_one :invoice
has_many :stock_changes,
:dependent => :destroy,
:include => 'stock_article',
:order => 'articles.name ASC'
has_many :stock_changes, -> { includes(:stock_article).order('articles.name ASC') }, :dependent => :destroy
scope :recent, :order => 'created_at DESC', :limit => 10
scope :recent, -> { order('created_at DESC').limit(10) }
validates_presence_of :supplier_id, :delivered_on
validate :stock_articles_must_be_unique

View File

@ -17,7 +17,7 @@ class Group < ActiveRecord::Base
# Returns all NONmembers and a checks for possible multiple Ordergroup-Memberships
def non_members
User.natural_order.all.reject { |u| users.include?(u) }
User.natural_order.reject { |u| users.include?(u) }
end
def user_tokens=(ids)

View File

@ -14,10 +14,10 @@ class GroupOrder < ActiveRecord::Base
validates_numericality_of :price
validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order
scope :in_open_orders, joins(:order).merge(Order.open)
scope :in_finished_orders, joins(:order).merge(Order.finished_not_closed)
scope :in_open_orders, -> { joins(:order).merge(Order.open) }
scope :in_finished_orders, -> { joins(:order).merge(Order.finished_not_closed) }
scope :ordered, :include => :ordergroup, :order => 'groups.name'
scope :ordered, -> { includes(:ordergroup).order('groups.name') }
# Generate some data for the javascript methods in ordering view
def load_data
@ -55,7 +55,7 @@ class GroupOrder < ActiveRecord::Base
def save_group_order_articles
for order_article in order.order_articles
# Find the group_order_article, create a new one if necessary...
group_order_article = group_order_articles.find_or_create_by_order_article_id(order_article.id)
group_order_article = group_order_articles.where(order_article_id: order_article.id).first_or_create
# Get ordered quantities and update group_order_articles/_quantities...
quantities = group_order_articles_attributes.fetch(order_article.id.to_s, {:quantity => 0, :tolerance => 0})

View File

@ -13,18 +13,18 @@ class GroupOrderArticle < ActiveRecord::Base
validates_inclusion_of :tolerance, :in => 0..99
validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order
scope :ordered, :conditions => 'group_order_articles.result > 0 OR group_order_articles.quantity > 0 OR group_order_articles.tolerance > 0', :include => {:group_order => :ordergroup}, :order => 'groups.name'
scope :ordered, -> { includes(:group_order => :ordergroup).where('group_order_articles.result > 0 OR group_order_articles.quantity > 0 OR group_order_articles.tolerance > 0').order('groups.name') }
localize_input_of :result
# Setter used in group_order_article#new
# We have to create an group_order, if the ordergroup wasn't involved in the order yet
def ordergroup_id=(id)
self.group_order = GroupOrder.find_or_initialize_by_order_id_and_ordergroup_id(order_article.order_id, id)
self.group_order = GroupOrder.where(order_id: order_article.order_id, ordergroup_id: id).first_or_initialize
end
def ordergroup_id
group_order.try(:ordergroup_id)
group_order.try!(:ordergroup_id)
end
# Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties
@ -36,7 +36,7 @@ class GroupOrderArticle < ActiveRecord::Base
logger.debug("Current quantity = #{self.quantity}, tolerance = #{self.tolerance}")
# Get quantities ordered with the newest item first.
quantities = group_order_article_quantities.find(:all, :order => 'created_on desc')
quantities = group_order_article_quantities.order('created_on DESC').to_a
logger.debug("GroupOrderArticleQuantity items found: #{quantities.size}")
if (quantities.size == 0)
@ -120,8 +120,7 @@ class GroupOrderArticle < ActiveRecord::Base
# In total there are enough units ordered. Now check the individual result for the ordergroup (group_order).
#
# Get all GroupOrderArticleQuantities for this OrderArticle...
order_quantities = GroupOrderArticleQuantity.all(
:conditions => ["group_order_article_id IN (?)", order_article.group_order_article_ids], :order => 'created_on')
order_quantities = GroupOrderArticleQuantity.where(group_order_article_id: order_article.group_order_article_ids).order('created_on')
logger.debug "GroupOrderArticleQuantity records found: #{order_quantities.size}"
# Determine quantities to be ordered...

View File

@ -5,7 +5,7 @@ class Invite < ActiveRecord::Base
belongs_to :user
belongs_to :group
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
validates_presence_of :user
validates_presence_of :group
validates_presence_of :token

View File

@ -7,7 +7,7 @@ class Invoice < ActiveRecord::Base
validates_presence_of :supplier_id
validates_numericality_of :amount, :deposit, :deposit_credit
scope :unpaid, :conditions => { :paid_on => nil }
scope :unpaid, -> { where(paid_on: nil) }
# Replace numeric seperator with database format
localize_input_of :amount, :deposit, :deposit_credit

View File

@ -5,14 +5,12 @@ class Membership < ActiveRecord::Base
before_destroy :check_last_admin
# messages
ERR_NO_ADMIN_MEMBER_DELETE = I18n.t('model.membership.no_admin_delete')
protected
# check if this is the last admin-membership and deny
def check_last_admin
raise ERR_NO_ADMIN_MEMBER_DELETE if self.group.role_admin? && self.group.memberships.size == 1 && Group.find_all_by_role_admin(true).size == 1
raise I18n.t('model.membership.no_admin_delete') if self.group.role_admin? && self.group.memberships.size == 1 && Group.where(role_admin: true).count == 1
end
end

View File

@ -4,9 +4,9 @@ class Message < ActiveRecord::Base
serialize :recipients_ids, Array
attr_accessor :sent_to_all, :group_id, :recipient_tokens, :reply_to
scope :pending, where(:email_state => 0)
scope :sent, where(:email_state => 1)
scope :public, where(:private => false)
scope :pending, -> { where(:email_state => 0) }
scope :sent, -> { where(:email_state => 1) }
scope :public, -> { where(:private => false) }
# Values for the email_state attribute: :none, :pending, :sent, :failed
EMAIL_STATE = {

View File

@ -10,7 +10,7 @@ class Order < ActiveRecord::Base
has_many :group_orders, :dependent => :destroy
has_many :ordergroups, :through => :group_orders
has_one :invoice
has_many :comments, :class_name => "OrderComment", :order => "created_at"
has_many :comments, -> { order('created_at') }, :class_name => "OrderComment"
has_many :stock_changes
belongs_to :supplier
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
@ -25,11 +25,11 @@ class Order < ActiveRecord::Base
after_save :save_order_articles, :update_price_of_group_orders
# Finders
scope :open, where(state: 'open').order('ends DESC')
scope :finished, where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC')
scope :finished_not_closed, where(state: 'finished').order('ends DESC')
scope :closed, where(state: 'closed').order('ends DESC')
scope :stockit, where(supplier_id: 0).order('ends DESC')
scope :open, -> { where(state: 'open').order('ends DESC') }
scope :finished, -> { where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC') }
scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') }
scope :closed, -> { where(state: 'closed').order('ends DESC') }
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') }
def stockit?
supplier_id == 0
@ -43,12 +43,12 @@ class Order < ActiveRecord::Base
if stockit?
# make sure to include those articles which are no longer available
# but which have already been ordered in this stock order
StockArticle.available.all(:include => :article_category,
:order => 'article_categories.name, articles.name').reject{ |a|
StockArticle.available.includes(:article_category).
order('article_categories.name, articles.name').reject{ |a|
a.quantity_available <= 0 and not a.ordered_in_order?(self)
}.group_by { |a| a.article_category.name }
else
supplier.articles.available.all.group_by { |a| a.article_category.name }
supplier.articles.available.group_by { |a| a.article_category.name }
end
end
@ -107,7 +107,7 @@ class Order < ActiveRecord::Base
end
def articles_sort_by_category
order_articles.all(:include => [:article], :order => 'articles.name').sort do |a,b|
order_articles.includes(:article).order('articles.name').sort do |a,b|
a.article.article_category.name <=> b.article.article_category.name
end
end
@ -168,7 +168,7 @@ class Order < ActiveRecord::Base
# Update order_articles. Save the current article_price to keep price consistency
# Also save results for each group_order_result
# Clean up
order_articles.all(:include => :article).each do |oa|
order_articles.includes(:article).each do |oa|
oa.update_attribute(:article_price, oa.article.article_prices.first)
oa.group_order_articles.each do |goa|
goa.save_results!
@ -199,7 +199,7 @@ class Order < ActiveRecord::Base
transaction_note = I18n.t('orders.model.notice_close', :name => name,
:ends => ends.strftime(I18n.t('date.formats.default')))
gos = group_orders.all(:include => :ordergroup) # Fetch group_orders
gos = group_orders.includes(:ordergroup) # Fetch group_orders
gos.each { |group_order| group_order.update_price! } # Update prices of group_orders
transaction do # Start updating account balances
@ -209,7 +209,7 @@ class Order < ActiveRecord::Base
end
if stockit? # Decreases the quantity of stock_articles
for oa in order_articles.all(:include => :article)
for oa in order_articles.includes(:article)
oa.update_results! # Update units_to_order of order_article
stock_changes.create! :stock_article => oa.article, :quantity => oa.units_to_order*-1
end
@ -236,7 +236,7 @@ class Order < ActiveRecord::Base
end
def keep_ordered_articles
chosen_order_articles = order_articles.find_all_by_article_id(article_ids)
chosen_order_articles = order_articles.where(article_id: article_ids)
to_be_removed = order_articles - chosen_order_articles
to_be_removed_but_ordered = to_be_removed.select { |a| a.quantity > 0 or a.tolerance > 0 }
unless to_be_removed_but_ordered.empty? or ignore_warnings

View File

@ -19,17 +19,6 @@ class OrderArticle < ActiveRecord::Base
before_create :init_from_balancing
after_destroy :update_ordergroup_prices
def self.sort_by_name(order_articles)
order_articles.sort { |a,b| a.article.name <=> b.article.name }
end
def self.sort_by_order_number(order_articles)
order_articles.sort do |a,b|
a.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i <=>
b.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i
end
end
# This method returns either the ArticlePrice or the Article
# The first will be set, when the the order is finished
def price

View File

@ -62,9 +62,9 @@ class Ordergroup < Group
def update_stats!
# Get hours for every job of each user in period
jobs = users.sum { |u| u.tasks.done.sum(:duration, :conditions => ["updated_on > ?", APPLE_MONTH_AGO.month.ago]) }
jobs = users.to_a.sum { |u| u.tasks.done.where('updated_on > ?', APPLE_MONTH_AGO.month.ago).sum(:duration) }
# Get group_order.price for every finished order in this period
orders_sum = group_orders.includes(:order).merge(Order.finished).where('orders.ends >= ?', APPLE_MONTH_AGO.month.ago).sum(:price)
orders_sum = group_orders.includes(:order).merge(Order.finished).where('orders.ends >= ?', APPLE_MONTH_AGO.month.ago).references(:orders).sum(:price)
@readonly = false # Dirty hack, avoid getting RecordReadOnly exception when called in task after_save callback. A rails bug?
update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum})
@ -113,8 +113,8 @@ class Ordergroup < Group
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
def uniqueness_of_name
group = Ordergroup.where('groups.name = ?', name)
group = group.where('groups.id != ?', self.id) unless new_record?
group = Ordergroup.where(name: name)
group = group.where.not(id: self.id) unless new_record?
if group.exists?
message = group.first.deleted? ? :taken_with_deleted : :taken
errors.add :name, message

View File

@ -3,7 +3,7 @@ class StockArticle < Article
has_many :stock_changes
scope :available, -> { undeleted.where'quantity > 0' }
scope :available, -> { undeleted.where('quantity > 0') }
before_destroy :check_quantity
@ -19,7 +19,7 @@ class StockArticle < Article
def quantity_ordered
OrderArticle.where(article_id: id).
joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order)
joins(:order).where(orders: {state: ['open', 'finished']}).sum(:units_to_order)
end
def quantity_history

View File

@ -1,14 +1,13 @@
# encoding: utf-8
class Supplier < ActiveRecord::Base
has_many :articles, :conditions => {:type => nil},
:include => [:article_category], :order => 'article_categories.name, articles.name'
has_many :stock_articles, :include => [:article_category], :order => 'article_categories.name, articles.name'
has_many :articles, -> { where(:type => nil).includes(:article_category).order('article_categories.name', 'articles.name') }
has_many :stock_articles, -> { includes(:article_category).order('article_categories.name', 'articles.name') }
has_many :orders
has_many :deliveries
has_many :invoices
belongs_to :shared_supplier # for the sharedLists-App
include ActiveModel::MassAssignmentSecurity
attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number,
:delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity
@ -82,8 +81,8 @@ class Supplier < ActiveRecord::Base
# Make sure, the name is uniq, add usefull message if uniq group is already deleted
def uniqueness_of_name
supplier = Supplier.where('suppliers.name = ?', name)
supplier = supplier.where('suppliers.id != ?', self.id) unless new_record?
supplier = Supplier.where(name: name)
supplier = supplier.where.not(id: self.id) unless new_record?
if supplier.exists?
message = supplier.first.deleted? ? :taken_with_deleted : :taken
errors.add :name, message

View File

@ -5,13 +5,14 @@ class Task < ActiveRecord::Base
belongs_to :workgroup
belongs_to :periodic_task_group
scope :non_group, where(workgroup_id: nil, done: false)
scope :done, where(done: true)
scope :undone, where(done: false)
scope :non_group, -> { where(workgroup_id: nil, done: false) }
scope :done, -> { where(done: true) }
scope :undone, -> { where(done: false) }
attr_accessor :current_user_id
# form will send user in string. responsibilities will added later
include ActiveModel::MassAssignmentSecurity
attr_protected :users
validates :name, :presence => true, :length => { :minimum => 3 }

View File

@ -26,7 +26,7 @@ class User < ActiveRecord::Base
validates_presence_of :email
validates_presence_of :password, :on => :create
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
validates_uniqueness_of :email, :case_sensitive => false
validates_presence_of :first_name # for simple_form validations
validates_length_of :first_name, :in => 2..50
@ -157,7 +157,7 @@ class User < ActiveRecord::Base
#Returns an array with the users groups (but without the Ordergroups -> because tpye=>"")
def member_of_groups()
self.groups.find(:all, :conditions => {:type => ""})
self.groups.where(type: '')
end
def self.authenticate(login, password)

View File

@ -3,7 +3,7 @@ class Workgroup < Group
has_many :tasks
# returns all non-finished tasks
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], order: 'due_date ASC, name ASC'
has_many :open_tasks, -> { where(:done => false).order('due_date ASC, name ASC') }, :class_name => 'Task'
validates_uniqueness_of :name
validate :last_admin_on_earth, :on => :update
@ -13,7 +13,7 @@ class Workgroup < Group
# Check before destroy a group, if this is the last group with admin role
def check_last_admin_group
if role_admin && Workgroup.where(:role_admin => true).size == 1
if role_admin && Workgroup.where(role_admin: true).size == 1
raise I18n.t('workgroups.error_last_admin_group')
end
end
@ -21,7 +21,7 @@ class Workgroup < Group
# add validation check on update
# Return an error if this is the last group with admin role and role_admin should set to false
def last_admin_on_earth
if !role_admin && !Workgroup.where('role_admin = ? AND id != ?', true, id).exists?
if !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists?
errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role'))
end
end

View File

@ -18,5 +18,5 @@
%td= ordergroup.users.size
%td
= link_to t('ui.edit'), edit_admin_ordergroup_path(ordergroup), class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, ordergroup], :confirm => t('admin.confirm', name: ordergroup.name),
= link_to t('ui.delete'), [:admin, ordergroup], :data => {:confirm => t('admin.confirm', name: ordergroup.name)},
:method => :delete, class: 'btn btn-mini btn-danger'

View File

@ -2,5 +2,5 @@
%section= render 'shared/group', group: @ordergroup
= link_to t('ui.edit'), edit_admin_ordergroup_path(@ordergroup), class: 'btn'
= link_to t('ui.delete'), [:admin, @ordergroup], :confirm => t('.confirm'), :method => :delete, class: 'btn btn-danger'
= link_to t('ui.delete'), [:admin, @ordergroup], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger'
= link_to t('.send_message'), new_message_path(:message => {:group_id => @ordergroup.id}), class: 'btn'

View File

@ -21,5 +21,5 @@
%td= format_roles(user)
%td= format_time(user.last_login)
%td= link_to t('ui.edit'), edit_admin_user_path(user), class: 'btn btn-mini'
%td= link_to t('ui.delete'), [:admin, user], :confirm => t('admin.confirm', name: user.name),
%td= link_to t('ui.delete'), [:admin, user], :data => {:confirm => t('admin.confirm', name: user.name)},
:method => :delete, class: 'btn btn-danger btn-mini'

View File

@ -29,12 +29,12 @@
.well
%h4= t '.groupabos'
%ul.unstyled
- for membership in Membership.find_all_by_user_id(@user.id)
- for membership in Membership.where(user: @user)
%li= link_to(membership.group.name, [:admin, membership.group])
%hr/
%p
= link_to t('ui.edit'), edit_admin_user_path(@user), class: 'btn'
= link_to t('ui.delete'), [:admin, @user], :confirm => t('.confirm', user: @user.first_name),
= link_to t('ui.delete'), [:admin, @user], :data => {:confirm => t('.confirm', user: @user.first_name)},
:method => :delete, class: 'btn btn-danger'
= link_to t('.send_message'), new_message_path(:message => {:mail_to => @user.id}), class: 'btn'

View File

@ -16,5 +16,5 @@
%td= format_roles(workgroup)
%td
= link_to t('ui.edit'), edit_admin_workgroup_path(workgroup), class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, workgroup], :confirm => t('admin.confirm', name: workgroup.name),
= link_to t('ui.delete'), [:admin, workgroup], :data => {:confirm => t('admin.confirm', name: workgroup.name)},
:method => :delete, class: 'btn btn-mini btn-danger'

View File

@ -2,5 +2,5 @@
%section= render 'shared/group', group: @workgroup
= link_to t('ui.edit'), edit_admin_workgroup_path(@workgroup), class: 'btn'
= link_to t('ui.delete'), [:admin, @workgroup], :confirm => t('.confirm'), :method => :delete, class: 'btn btn-danger'
= link_to t('ui.delete'), [:admin, @workgroup], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger'
= link_to_new_message(message_params: {group_id: @workgroup.id})

View File

@ -15,5 +15,5 @@
%td= article_category.description
%td
= link_to t('ui.edit'), edit_article_category_path(article_category), class: 'btn btn-mini'
= link_to t('ui.delete'), article_category, :method => :delete, :confirm => t('.confirm_delete'),
= link_to t('ui.delete'), article_category, :method => :delete, :data => {:confirm => t('.confirm_delete')},
class: 'btn btn-mini btn-danger'

View File

@ -14,4 +14,4 @@
%td= link_to t('ui.edit'), edit_supplier_article_path(@supplier, article),
:remote => true, class: 'btn btn-mini'
%td= link_to t('ui.delete'), [@supplier, article],
:method => :delete, :confirm => t('.confirm_delete'), :remote => true, class: 'btn btn-mini btn-danger'
:method => :delete, :data => {:confirm => t('.confirm_delete')}, :remote => true, class: 'btn btn-mini btn-danger'

View File

@ -28,7 +28,7 @@
= check_box_tag :checkall, 1, false, 'data-check-all' => '#articlesInListForm', 'data-ignore-onchange' => true
%select{:name => "selected_action", 'data-submit-onchange' => true}
%option{:value => '', :selected => 'selected'}= t '.option_select'
%option{:value => "destroy", 'data-confirm' => t('.confirm_delete')}= t '.option_delete'
%option{:value => "destroy", :data => {:confirm => t('.confirm_delete')}}= t '.option_delete'
%option{:value => "setNotAvailable"}= t '.option_not_available'
%option{:value => "setAvailable"}= t '.option_available'
= hidden_field_tag 'supplier_id', @supplier.id

View File

@ -1,7 +1,7 @@
- if @articles.empty?
%p= t '.not_found'
- else
= pagination_links_remote @articles, :params => {:search => search_params}
= pagination_links_remote @articles, :params => {:q => search_params}
%table.table.table-striped
%thead
%tr
@ -16,7 +16,7 @@
%tbody
- for article in @articles
%tr
%td= highlight article.name, params[:search][:name_contains_all]
%td= highlight article.name, params[:q][:name_cont_all]
%td= article.origin
%td= article.manufacturer
%td= article.note

View File

@ -28,7 +28,7 @@
= t '.change_supplier'
%span.caret
%ul.dropdown-menu
- Supplier.undeleted.where('id != ?', @supplier.id).order('suppliers.name ASC').each do |supplier|
- Supplier.undeleted.where.not(id: @supplier.id).order('suppliers.name ASC').each do |supplier|
%li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1
- unless @supplier.shared_supplier.nil?
@ -36,10 +36,10 @@
= form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
'data-submit-onchange' => true do
%h3= t '.import.title'
= text_field_tag "search[name_contains_all]", "", class: 'input-medium search-query',
= text_field_tag "q[name_cont_all]", "", class: 'input-medium search-query',
placeholder: t('.import.placeholder')
%label.checkbox
= check_box_tag "search[origin_equals]", "REG", false
= check_box_tag "q[origin_eq]", "REG", false
= t '.import.restrict_region'
#search_results.clearfix
= link_to t('ui.close'), "#import", 'data-toggle-this' => '#import'

View File

@ -15,7 +15,7 @@
%td
= link_to t('ui.show'), [@supplier, delivery], class: 'btn btn-mini'
= link_to t('ui.edit'), edit_supplier_delivery_path(@supplier,delivery), class: 'btn btn-mini'
= link_to t('ui.delete'), [@supplier,delivery], :confirm => t('.confirm_delete'), :method => :delete,
= link_to t('ui.delete'), [@supplier,delivery], :data => {:confirm => t('.confirm_delete')}, :method => :delete,
class: 'btn btn-mini btn-danger'
= link_to t('.new_delivery', supplier: @supplier.name), new_supplier_delivery_path(@supplier), class: 'btn btn-primary'

View File

@ -24,7 +24,7 @@
%th.numeric= t '.sum'
%tbody
- total_net, total_gross = 0,0
- @delivery.stock_changes.all.each do |stock_change|
- @delivery.stock_changes.each do |stock_change|
- quantity = stock_change.quantity
- sum = quantity * stock_change.stock_article.price