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

@ -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
- total_net += sum

View file

@ -24,4 +24,4 @@
class: 'btn btn-mini'
%td
= link_to t('ui.delete'), order_order_article_path(order_article.order, order_article), method: :delete,
remote: true, confirm: t('.confirm'), class: 'btn btn-danger btn-mini'
remote: true, data: {confirm: t('.confirm')}, class: 'btn btn-danger btn-mini'

View file

@ -26,6 +26,6 @@
= link_to t('orders.index.action_receive'), '#', class: 'btn btn-mini disabled'
= link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary'
= link_to t('.close'), close_direct_finance_order_path(order),
:confirm => t('.confirm'), :method => :put, class: 'btn btn-mini'
:data => {:confirm => t('.confirm')}, :method => :patch, class: 'btn btn-mini'
- else
%i= t('.no_closed_orders')

View file

@ -6,5 +6,5 @@
%td= group_order.ordergroup.name
%td.numeric= number_to_currency(group_order.price)
.form-actions
= link_to t('.clear'), close_finance_order_path(@order), method: :put, class: 'btn btn-primary'
= link_to t('.clear'), close_finance_order_path(@order), method: :patch, class: 'btn btn-primary'
= link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id)

View file

@ -1,7 +1,7 @@
%tr.transaction
%td
= select_tag 'financial_transactions[][ordergroup_id]',
options_for_select(Ordergroup.order(:name).all.map { |g| [ g.name, g.id ] })
options_for_select(Ordergroup.order(:name).map { |g| [ g.name, g.id ] })
%td= text_field_tag 'financial_transactions[][amount]', nil, class: 'input-small'
%td= link_to t('.remove'), "#", :title => t('.remove_group'), 'data-remove-transaction' => true,
class: 'btn btn-small'
class: 'btn btn-small'

View file

@ -27,5 +27,5 @@
%td= link_to format_date(invoice.order.ends), new_finance_order_path(order_id: invoice.order_id) if invoice.order
%td= truncate(invoice.note)
%td= link_to t('ui.edit'), edit_finance_invoice_path(invoice), class: 'btn btn-mini'
%td= link_to t('ui.delete'), finance_invoice_path(invoice), :confirm => t('.confirm_delete'), :method => :delete,
%td= link_to t('ui.delete'), finance_invoice_path(invoice), :data => {:confirm => t('.confirm_delete')}, :method => :delete,
class: 'btn btn-danger btn-mini'

View file

@ -34,6 +34,6 @@
- unless Order.closed.empty?
%section
%h2= t '.closed_orders.title'
= render :partial => "orders", :locals => {:orders => Order.closed.all(:limit => 5), :pagination => false}
= render :partial => "orders", :locals => {:orders => Order.closed.limit(5), :pagination => false}
%br/
= link_to t('.closed_orders.more'), archive_group_orders_path

View file

@ -19,5 +19,5 @@
remote: true, class: 'btn btn-success btn-small'
- if membership.group.type != 'Ordergroup'
%td= link_to t('.groups.cancel'), cancel_membership_path(membership_id: membership),
confirm: t('.groups.cancel_confirm'), method: :post,
:data => {confirm: t('.groups.cancel_confirm')}, method: :post,
class: 'btn btn-danger btn-small'

View file

@ -36,8 +36,8 @@
= t('.list.mail', email: mail_to(FoodsoftConfig[:mailing_list_subscribe])).html_safe
#recipients
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map(&:token_attributes).to_json }
= f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC, name ASC').all.reject { |g| g.memberships.empty? }
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
= f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC, name ASC').reject { |g| g.memberships.empty? }
= f.input :private
= f.input :subject, input_html: {class: 'input-xxlarge'}
= f.input :body, input_html: {class: 'input-xxlarge'}

View file

@ -33,13 +33,13 @@
%td= format_time(order.ends) unless order.ends.nil?
%td= truncate(order.note)
%td= link_to t('.action_end'), finish_order_path(order),
confirm: t('.confirm_end', order: order.name), method: :post,
data: {confirm: t('.confirm_end', order: order.name)}, method: :post,
class: 'btn btn-small btn-success'
%td
= link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small'
= link_to t('ui.show'), order, class: 'btn btn-small'
= link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete,
= link_to t('ui.delete'), order, data: {confirm: t('.confirm_delete')}, method: :delete,
class: 'btn btn-small btn-danger'
- unless @finished_orders.empty?
@ -60,7 +60,7 @@
%td
= link_to t('ui.edit'), '#', class: 'btn btn-small disabled', tabindex: -1
= link_to t('ui.show'), order, class: 'btn btn-small'
= link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete,
= link_to t('ui.delete'), order, data: {confirm: t('.confirm_delete')}, method: :delete,
class: 'btn btn-small btn-danger'
%h2= t '.orders_settled'

View file

@ -59,16 +59,15 @@
- if @order.open?
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
confirm: t('.confirm_end', order: @order.name)
data: {confirm: t('.confirm_end', order: @order.name)}
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
- elsif not @order.closed? and not @order.stockit?
-# TODO btn-success class only if not received before
= link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success'
- unless @order.closed?
= link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete,
= link_to t('ui.delete'), @order, data_confirm: t('.confirm_delete'), method: :delete,
class: 'btn btn-danger'
%section#articles_table
= render @partial, order: @order

View file

@ -19,7 +19,7 @@
= number_to_currency(f.object.fc_price) rescue nil
-# do this inline, since it's being used in ajax forms only
- field = f.object.class.model_name.underscore
- field = f.object.class.model_name.to_s.underscore
:javascript
var form = $('#article_fc_price').closest('form');
$('##{field}_price, ##{field}_tax, ##{field}_deposit', form).on('change keyup', function() {

View file

@ -8,7 +8,7 @@
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
%th= t 'shared.articles_by.price'
- for order_article in order.order_articles.ordered.all(:include => [:article, :article_price])
- for order_article in order.order_articles.ordered.includes([:article, :article_price])
= render 'shared/articles_by/article_single', order_article: order_article, edit: (edit rescue nil)
%tr
%td{colspan: 4}

View file

@ -4,7 +4,7 @@
%th{colspan: 9}
%h4.name= group_order.ordergroup.name
- total = 0
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
- for goa in group_order.group_order_articles.ordered.includes(:order_article)
- total += goa.total_price
= render 'shared/articles_by/group_single_goa', goa: goa, edit: (edit rescue nil)
%tr{class: cycle('even', 'odd', :name => 'articles')}

View file

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

View file

@ -13,7 +13,7 @@
%th= t '.supplier'
%th= t '.unit'
%th= t '.amount'
- for stock_change in @stock_taking.stock_changes.all
- for stock_change in @stock_taking.stock_changes
%tr
%td= stock_change.stock_article.name
%td= stock_change.stock_article.supplier.name
@ -23,5 +23,5 @@
.btn-group
= link_to t('ui.edit'), edit_stock_taking_path(@stock_taking), class: 'btn'
= link_to t('.overview'), stock_takings_path, class: 'btn'
= link_to t('ui.delete'), @stock_taking, :method => :delete, :confirm => t('.confirm_delete'),
= link_to t('ui.delete'), @stock_taking, :method => :delete, :data => {:confirm => t('.confirm_delete')},
class: 'btn btn-danger'

View file

@ -10,5 +10,5 @@
%td= stock_article.article_category.name
%td
= link_to t('ui.edit'), edit_stock_article_path(stock_article), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), stock_article, :method => :delete, :confirm => t('.confirm_delete', :name => stock_article.name),
= link_to t('ui.delete'), stock_article, :method => :delete, :data => {:confirm => t('.confirm_delete', :name => stock_article.name)},
class: 'btn btn-mini btn-danger', :remote => true

View file

@ -24,4 +24,4 @@
%td
= link_to t('ui.edit'), edit_supplier_path(supplier), class: 'btn btn-mini'
= link_to t('ui.delete'), supplier_path(supplier), method: :delete,
confirm: t('.confirm_del', name: supplier.name), class: 'btn btn-mini btn-danger'
:data => {confirm: t('.confirm_del', name: supplier.name)}, class: 'btn btn-mini btn-danger'

View file

@ -36,7 +36,7 @@
- if @current_user.role_suppliers?
.form-actions
= link_to t('ui.edit'), edit_supplier_path(@supplier), class: 'btn'
= link_to t('ui.delete'), @supplier, :confirm => t('.confirm_delete'), :method => :delete, class: 'btn btn-danger'
= link_to t('ui.delete'), @supplier, :data => {:confirm => t('.confirm_delete')}, :method => :delete, class: 'btn btn-danger'
.span6
%h2= t '.last_deliveries'

View file

@ -30,8 +30,8 @@
- unless @task.done?
= link_to t('.mark_done'), set_done_task_path(@task), method: :post, class: 'btn'
= link_to t('ui.edit'), edit_task_path(@task), class: 'btn'
= link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => t('.confirm_delete_single'),
= link_to t('ui.delete'), task_path(@task), :method => :delete, :data => {:confirm => t('.confirm_delete_single')},
class: 'btn btn-danger'
- if @task.periodic?
= link_to t('.delete_group'), task_path(@task, periodic: true), method: :delete,
confirm: t('.confirm_delete_group'), class: 'btn btn-danger'
:data => {confirm: t('.confirm_delete_group')}, class: 'btn btn-danger'