chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -1,6 +1,6 @@
|
|||
class CurrentOrders::ArticlesController < ApplicationController
|
||||
before_action :authenticate_orders
|
||||
before_action :find_order_and_order_article, only: [:index, :show]
|
||||
before_action :find_order_and_order_article, only: %i[index show]
|
||||
|
||||
def index
|
||||
# sometimes need to pass id as parameter for forms
|
||||
|
|
@ -26,11 +26,11 @@ class CurrentOrders::ArticlesController < ApplicationController
|
|||
|
||||
def find_order_and_order_article
|
||||
@current_orders = Order.finished_not_closed
|
||||
unless params[:order_id].blank?
|
||||
if params[:order_id].blank?
|
||||
@order_articles = OrderArticle.where(order_id: @current_orders.all.map(&:id))
|
||||
else
|
||||
@order = Order.find(params[:order_id])
|
||||
@order_articles = @order.order_articles
|
||||
else
|
||||
@order_articles = OrderArticle.where(order_id: @current_orders.all.map(&:id))
|
||||
end
|
||||
@q = OrderArticle.ransack(params[:q])
|
||||
@order_articles = @order_articles.ordered.merge(@q.result).includes(:article, :article_price)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class CurrentOrders::GroupOrdersController < ApplicationController
|
|||
|
||||
def index
|
||||
# XXX code duplication lib/foodsoft_current_orders/app/controllers/current_orders/ordergroups_controller.rb
|
||||
@order_ids = Order.where(state: ['open', 'finished']).all.map(&:id)
|
||||
@goas = GroupOrderArticle.includes(:group_order => :ordergroup).includes(:order_article)
|
||||
@order_ids = Order.where(state: %w[open finished]).all.map(&:id)
|
||||
@goas = GroupOrderArticle.includes(group_order: :ordergroup).includes(:order_article)
|
||||
.where(group_orders: { order_id: @order_ids, ordergroup_id: @ordergroup.id }).ordered
|
||||
@articles_grouped_by_category = @goas.includes(:order_article => { :article => :article_category })
|
||||
@articles_grouped_by_category = @goas.includes(order_article: { article: :article_category })
|
||||
.order('articles.name')
|
||||
.group_by { |a| a.order_article.article.article_category.name }
|
||||
.sort { |a, b| a[0] <=> b[0] }
|
||||
|
|
@ -18,8 +18,8 @@ class CurrentOrders::GroupOrdersController < ApplicationController
|
|||
# XXX code duplication from GroupOrdersController
|
||||
def ensure_ordergroup_member
|
||||
@ordergroup = @current_user.ordergroup
|
||||
if @ordergroup.nil?
|
||||
redirect_to root_url, :alert => I18n.t('group_orders.errors.no_member')
|
||||
end
|
||||
return unless @ordergroup.nil?
|
||||
|
||||
redirect_to root_url, alert: I18n.t('group_orders.errors.no_member')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class CurrentOrders::OrdergroupsController < ApplicationController
|
||||
before_action :authenticate_orders
|
||||
before_action :find_group_orders, only: [:index, :show]
|
||||
before_action :find_group_orders, only: %i[index show]
|
||||
|
||||
def index
|
||||
# sometimes need to pass id as parameter for forms
|
||||
|
|
@ -34,8 +34,11 @@ class CurrentOrders::OrdergroupsController < ApplicationController
|
|||
@all_ordergroups.sort_by! { |o| @ordered_group_ids.include?(o.id) ? o.name : "ZZZZZ#{o.name}" }
|
||||
|
||||
@ordergroup = Ordergroup.find(params[:id]) unless params[:id].nil?
|
||||
@goas = GroupOrderArticle.includes(:group_order, :order_article => [:article, :article_price])
|
||||
.where(group_orders: { order_id: @order_ids, ordergroup_id: @ordergroup.id }).ordered.all unless @ordergroup.nil?
|
||||
return if @ordergroup.nil?
|
||||
|
||||
@goas = GroupOrderArticle.includes(:group_order, order_article: %i[article article_price])
|
||||
.where(group_orders: { order_id: @order_ids,
|
||||
ordergroup_id: @ordergroup.id }).ordered.all
|
||||
end
|
||||
|
||||
helper_method \
|
||||
|
|
|
|||
|
|
@ -77,11 +77,11 @@ class MultipleOrdersByArticles < OrderPdf
|
|||
.includes(:article).references(:article)
|
||||
.reorder('order_articles.order_id, articles.name')
|
||||
.preload(:article_price) # preload not join, just in case it went missing
|
||||
.preload(:order, :group_order_articles => { :group_order => :ordergroup })
|
||||
.preload(:order, group_order_articles: { group_order: :ordergroup })
|
||||
end
|
||||
|
||||
def each_order_article
|
||||
order_articles.find_each_with_order(batch_size: BATCH_SIZE) { |oa| yield oa }
|
||||
def each_order_article(&block)
|
||||
order_articles.find_each_with_order(batch_size: BATCH_SIZE, &block)
|
||||
end
|
||||
|
||||
def group_order_articles_for(order_article)
|
||||
|
|
@ -90,7 +90,7 @@ class MultipleOrdersByArticles < OrderPdf
|
|||
goas
|
||||
end
|
||||
|
||||
def each_group_order_article_for(group_order)
|
||||
group_order_articles_for(group_order).each { |goa| yield goa }
|
||||
def each_group_order_article_for(group_order, &block)
|
||||
group_order_articles_for(group_order).each(&block)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class MultipleOrdersByGroups < OrderPdf
|
|||
s
|
||||
end
|
||||
|
||||
def each_ordergroup
|
||||
def each_ordergroup(&block)
|
||||
ordergroups.find_in_batches_with_order(batch_size: BATCH_SIZE) do |ordergroups|
|
||||
@group_order_article_batch = GroupOrderArticle
|
||||
.joins(:group_order)
|
||||
|
|
@ -121,8 +121,8 @@ class MultipleOrdersByGroups < OrderPdf
|
|||
.where(group_orders: { ordergroup_id: ordergroups.map(&:id) })
|
||||
.order('group_orders.order_id, group_order_articles.id')
|
||||
.preload(group_orders: { order: :supplier })
|
||||
.preload(order_article: [:article, :article_price, :order])
|
||||
ordergroups.each { |ordergroup| yield ordergroup }
|
||||
.preload(order_article: %i[article article_price order])
|
||||
ordergroups.each(&block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ class MultipleOrdersByGroups < OrderPdf
|
|||
@group_order_article_batch.select { |goa| goa.group_order.ordergroup_id == ordergroup.id }
|
||||
end
|
||||
|
||||
def each_group_order_article_for(ordergroup)
|
||||
group_order_articles_for(ordergroup).each { |goa| yield goa }
|
||||
def each_group_order_article_for(ordergroup, &block)
|
||||
group_order_articles_for(ordergroup).each(&block)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ module CurrentOrdersHelper
|
|||
elsif funds == 0
|
||||
I18n.t('helpers.current_orders.pay_none')
|
||||
else
|
||||
content_tag :b, I18n.t('helpers.current_orders.pay_amount', amount: number_to_currency(-ordergroup.get_available_funds))
|
||||
content_tag :b,
|
||||
I18n.t('helpers.current_orders.pay_amount',
|
||||
amount: number_to_currency(-ordergroup.get_available_funds))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
Rails.application.routes.draw do
|
||||
scope '/:foodcoop' do
|
||||
namespace :current_orders do
|
||||
resources :ordergroups, :only => [:index, :show] do
|
||||
resources :ordergroups, only: %i[index show] do
|
||||
collection do
|
||||
get :show_on_group_order_article_create
|
||||
get :show_on_group_order_article_update
|
||||
end
|
||||
end
|
||||
|
||||
resources :articles, :only => [:index, :show] do
|
||||
resources :articles, only: %i[index show] do
|
||||
collection do
|
||||
get :show_on_group_order_article_create
|
||||
end
|
||||
end
|
||||
|
||||
resource :orders, :only => [:show] do
|
||||
resource :orders, only: [:show] do
|
||||
collection do
|
||||
get :my
|
||||
get :receive
|
||||
end
|
||||
end
|
||||
|
||||
resources :group_orders, :only => [:index]
|
||||
resources :group_orders, only: [:index]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
$:.push File.expand_path("../lib", __FILE__)
|
||||
$:.push File.expand_path('lib', __dir__)
|
||||
|
||||
# Maintain your gem's version:
|
||||
require "foodsoft_current_orders/version"
|
||||
require 'foodsoft_current_orders/version'
|
||||
|
||||
# Describe your gem and declare its dependencies:
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "foodsoft_current_orders"
|
||||
s.name = 'foodsoft_current_orders'
|
||||
s.version = FoodsoftCurrentOrders::VERSION
|
||||
s.authors = ["wvengen"]
|
||||
s.email = ["dev-voko@willem.engen.nl"]
|
||||
s.homepage = "https://github.com/foodcoop-adam/foodsoft"
|
||||
s.summary = "Quick support for working on all currently active orders in foodsoft."
|
||||
s.description = ""
|
||||
s.authors = ['wvengen']
|
||||
s.email = ['dev-voko@willem.engen.nl']
|
||||
s.homepage = 'https://github.com/foodcoop-adam/foodsoft'
|
||||
s.summary = 'Quick support for working on all currently active orders in foodsoft.'
|
||||
s.description = ''
|
||||
|
||||
s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"]
|
||||
s.files = Dir['{app,config,db,lib}/**/*'] + ['Rakefile', 'README.md']
|
||||
|
||||
s.add_dependency "rails"
|
||||
s.add_dependency "deface", "~> 1.0"
|
||||
s.add_dependency 'rails'
|
||||
s.add_dependency 'deface', '~> 1.0'
|
||||
s.metadata['rubygems_mfa_required'] = 'true'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
require "deface"
|
||||
require "foodsoft_current_orders/engine"
|
||||
require 'deface'
|
||||
require 'foodsoft_current_orders/engine'
|
||||
|
||||
module FoodsoftCurrentOrders
|
||||
def self.enabled?
|
||||
|
|
|
|||
|
|
@ -4,12 +4,15 @@ module FoodsoftCurrentOrders
|
|||
return unless FoodsoftCurrentOrders.enabled?
|
||||
return if primary[:orders].nil?
|
||||
|
||||
cond = Proc.new { current_user.role_orders? }
|
||||
cond = proc { current_user.role_orders? }
|
||||
[
|
||||
SimpleNavigation::Item.new(primary, :stage_divider, nil, nil, class: 'divider', if: cond),
|
||||
SimpleNavigation::Item.new(primary, :current_orders_receive, I18n.t('current_orders.navigation.receive'), context.receive_current_orders_orders_path, if: cond),
|
||||
SimpleNavigation::Item.new(primary, :current_orders_articles, I18n.t('current_orders.navigation.articles'), context.current_orders_articles_path, if: cond),
|
||||
SimpleNavigation::Item.new(primary, :current_orders_ordergroups, I18n.t('current_orders.navigation.ordergroups'), context.current_orders_ordergroups_path, if: cond)
|
||||
SimpleNavigation::Item.new(primary, :current_orders_receive, I18n.t('current_orders.navigation.receive'),
|
||||
context.receive_current_orders_orders_path, if: cond),
|
||||
SimpleNavigation::Item.new(primary, :current_orders_articles, I18n.t('current_orders.navigation.articles'),
|
||||
context.current_orders_articles_path, if: cond),
|
||||
SimpleNavigation::Item.new(primary, :current_orders_ordergroups,
|
||||
I18n.t('current_orders.navigation.ordergroups'), context.current_orders_ordergroups_path, if: cond)
|
||||
].each { |i| primary[:orders].sub_navigation.items << i }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module FoodsoftCurrentOrders
|
||||
VERSION = "0.0.1"
|
||||
VERSION = '0.0.1'
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue