Use more boolean comparators where it makes sense
This commit is contained in:
parent
1063aea4af
commit
7e0aa66936
8 changed files with 15 additions and 15 deletions
|
@ -41,7 +41,7 @@ class Admin::ConfigsController < Admin::BaseController
|
|||
def parse_recurring_selects!(config)
|
||||
if config
|
||||
for k in [:pickup, :ends] do
|
||||
if config[k] and config[k][:recurr]
|
||||
if config[k] && config[k][:recurr]
|
||||
config[k][:recurr] = ActiveSupport::JSON.decode(config[k][:recurr])
|
||||
config[k][:recurr] = FoodsoftDateUtil.rule_from(config[k][:recurr]).to_ical if config[k][:recurr]
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def current_user
|
||||
# check if there is a valid session and return the logged-in user (its object)
|
||||
if session[:user_id] and params[:foodcoop]
|
||||
if session[:user_id] && params[:foodcoop]
|
||||
# for shared-host installations. check if the cookie-subdomain fits to request.
|
||||
@current_user ||= User.find_by_id(session[:user_id]) if session[:scope] == FoodsoftConfig.scope
|
||||
end
|
||||
|
@ -99,7 +99,7 @@ class ApplicationController < ActionController::Base
|
|||
# if fails the user will redirected to startpage
|
||||
def authenticate_membership_or_admin(group_id = params[:id])
|
||||
@group = Group.find(group_id)
|
||||
unless @group.member?(@current_user) or @current_user.role_admin?
|
||||
unless @group.member?(@current_user) || @current_user.role_admin?
|
||||
redirect_to root_path, alert: I18n.t('application.controller.error_members_only')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ class ArticlesController < ApplicationController
|
|||
|
||||
def create
|
||||
@article = Article.new(params[:article])
|
||||
if @article.valid? and @article.save
|
||||
if @article.valid? && @article.save
|
||||
render :layout => false
|
||||
else
|
||||
render :action => 'new', :layout => false
|
||||
|
@ -148,7 +148,7 @@ class ArticlesController < ApplicationController
|
|||
no_category = ArticleCategory.new
|
||||
articles.each do |row|
|
||||
# fallback to Others category
|
||||
category = (ArticleCategory.find_match(row[:category]) or no_category)
|
||||
category = (ArticleCategory.find_match(row[:category]) || no_category)
|
||||
# creates a new article and price
|
||||
article = @supplier.articles.build(:name => row[:name],
|
||||
:note => row[:note],
|
||||
|
@ -160,7 +160,7 @@ class ArticlesController < ApplicationController
|
|||
:unit_quantity => row[:unit_quantity],
|
||||
:order_number => row[:number],
|
||||
:deposit => row[:deposit],
|
||||
:tax => (row[:tax] or FoodsoftConfig[:tax_default]))
|
||||
:tax => (row[:tax] || FoodsoftConfig[:tax_default]))
|
||||
# stop parsing, when an article isn't valid
|
||||
unless article.valid?
|
||||
raise I18n.t('articles.controller.error_parse', :msg => article.errors.full_messages.join(", "), :line => (articles.index(row) + 2).to_s)
|
||||
|
@ -212,7 +212,7 @@ class ArticlesController < ApplicationController
|
|||
def import
|
||||
@article = SharedArticle.find(params[:shared_article_id]).build_new_article(@supplier)
|
||||
@article.article_category_id = params[:article_category_id] unless params[:article_category_id].blank?
|
||||
if params[:direct] and not params[:article_category_id].blank? and @article.valid? and @article.save
|
||||
if params[:direct] && !params[:article_category_id].blank? && @article.valid? && @article.save
|
||||
render :action => 'create', :layout => false
|
||||
else
|
||||
render :action => 'new', :layout => false
|
||||
|
|
|
@ -20,7 +20,7 @@ class GroupOrderArticlesController < ApplicationController
|
|||
goa = GroupOrderArticle.where(group_order_id: @group_order_article.group_order_id,
|
||||
order_article_id: @order_article.id).first
|
||||
|
||||
if goa and goa.update_attributes(params[:group_order_article])
|
||||
if goa && goa.update_attributes(params[:group_order_article])
|
||||
@group_order_article = goa
|
||||
|
||||
update_summaries(@group_order_article)
|
||||
|
@ -50,7 +50,7 @@ class GroupOrderArticlesController < ApplicationController
|
|||
def destroy
|
||||
# only destroy if quantity and tolerance was zero already, so that we don't
|
||||
# lose what the user ordered, if any
|
||||
if @group_order_article.quantity > 0 or @group_order_article.tolerance >0
|
||||
if @group_order_article.quantity > 0 || @group_order_article.tolerance >0
|
||||
@group_order_article.update_attribute(:result, 0)
|
||||
else
|
||||
@group_order_article.destroy
|
||||
|
|
|
@ -15,7 +15,7 @@ class OrderArticlesController < ApplicationController
|
|||
# If order_article is ordered and a new order_article is created, an error message will be
|
||||
# given mentioning that the article already exists, which is desired.
|
||||
@order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first
|
||||
unless (@order_article and @order_article.units_to_order == 0)
|
||||
unless @order_article && @order_article.units_to_order == 0
|
||||
@order_article = @order.order_articles.build(params[:order_article])
|
||||
end
|
||||
@order_article.save!
|
||||
|
|
|
@ -29,7 +29,7 @@ class OrdersController < ApplicationController
|
|||
# Renders also the pdf
|
||||
def show
|
||||
@order= Order.find(params[:id])
|
||||
@view = (params[:view] or 'default').gsub(/[^-_a-zA-Z0-9]/, '')
|
||||
@view = (params[:view] || 'default').gsub(/[^-_a-zA-Z0-9]/, '')
|
||||
@partial = case @view
|
||||
when 'default' then 'articles'
|
||||
when 'groups' then 'shared/articles_by/groups'
|
||||
|
@ -170,14 +170,14 @@ class OrdersController < ApplicationController
|
|||
notice << I18n.t('orders.update_order_amounts.msg1', count: counts[0], units: cunits[0])
|
||||
notice << I18n.t('orders.update_order_amounts.msg2', count: counts[1], units: cunits[1]) if params[:rest_to_tolerance]
|
||||
notice << I18n.t('orders.update_order_amounts.msg3', count: counts[2], units: cunits[2]) if params[:rest_to_stock]
|
||||
if counts[3]>0 or cunits[3]>0
|
||||
if counts[3]>0 || cunits[3]>0
|
||||
notice << I18n.t('orders.update_order_amounts.msg4', count: counts[3], units: cunits[3])
|
||||
end
|
||||
notice.join(', ')
|
||||
end
|
||||
|
||||
def remove_empty_article
|
||||
params[:order][:article_ids].reject!(&:blank?) if params[:order] and params[:order][:article_ids]
|
||||
params[:order][:article_ids].reject!(&:blank?) if params[:order] && params[:order][:article_ids]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ class StockitController < ApplicationController
|
|||
|
||||
def create
|
||||
@stock_article = StockArticle.new(params[:stock_article])
|
||||
if @stock_article.valid? and @stock_article.save
|
||||
if @stock_article.valid? && @stock_article.save
|
||||
render :layout => false
|
||||
else
|
||||
render :action => 'new', :layout => false
|
||||
|
|
|
@ -46,7 +46,7 @@ class TasksController < ApplicationController
|
|||
@task.attributes=(params[:task])
|
||||
if @task.errors.empty? && @task.save
|
||||
flash[:notice] = I18n.t('tasks.update.notice')
|
||||
if was_periodic and not @task.periodic?
|
||||
if was_periodic && !@task.periodic?
|
||||
flash[:notice] = I18n.t('tasks.update.notice_converted')
|
||||
end
|
||||
if @task.workgroup
|
||||
|
|
Loading…
Reference in a new issue