Run rubocop --fix-layout and remove encoding comments

This commit is contained in:
Patrick Gansterer 2021-03-01 15:27:26 +01:00
parent fa63e6e81d
commit ea2862fdef
283 changed files with 1164 additions and 1969 deletions

View file

@ -1,6 +1,4 @@
# encoding: utf-8
class CurrentOrders::ArticlesController < ApplicationController
before_action :authenticate_orders
before_action :find_order_and_order_article, only: [:index, :show]
@ -21,7 +19,7 @@ class CurrentOrders::ArticlesController < ApplicationController
end
def show_on_group_order_article_update
#@goa = GroupOrderArticle.find(params[:group_order_article_id])
# @goa = GroupOrderArticle.find(params[:group_order_article_id])
end
protected
@ -40,7 +38,7 @@ class CurrentOrders::ArticlesController < ApplicationController
end
helper_method \
def ordergroups_for_adding
def ordergroups_for_adding
Ordergroup.undeleted.order(:name)
end
end

View file

@ -5,12 +5,12 @@ 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).
where(group_orders: {order_id: @order_ids, ordergroup_id: @ordergroup.id}).ordered
@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] }
@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 })
.order('articles.name')
.group_by { |a| a.order_article.article.article_category.name }
.sort { |a, b| a[0] <=> b[0] }
end
private
@ -22,5 +22,4 @@ class CurrentOrders::GroupOrdersController < ApplicationController
redirect_to root_url, :alert => I18n.t('group_orders.errors.no_member')
end
end
end

View file

@ -1,6 +1,4 @@
# encoding: utf-8
class CurrentOrders::OrdergroupsController < ApplicationController
before_action :authenticate_orders
before_action :find_group_orders, only: [:index, :show]
@ -21,7 +19,7 @@ class CurrentOrders::OrdergroupsController < ApplicationController
end
def show_on_group_order_article_update
#@goa = GroupOrderArticle.find(params[:group_order_article_id])
# @goa = GroupOrderArticle.find(params[:group_order_article_id])
@group_order = GroupOrder.find(params[:group_order_id])
@ordergroup = @group_order.ordergroup
end
@ -33,15 +31,15 @@ class CurrentOrders::OrdergroupsController < ApplicationController
@all_ordergroups = Ordergroup.undeleted.order(:name).to_a
@ordered_group_ids = GroupOrder.where(order_id: @order_ids).pluck('DISTINCT(ordergroup_id)')
@all_ordergroups.sort_by! {|o| @ordered_group_ids.include?(o.id) ? o.name : "ZZZZZ#{o.name}" }
@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?
@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?
end
helper_method \
def articles_for_adding
def articles_for_adding
OrderArticle.includes(:article, :article_price).where(order_id: @order_ids)
end
end

View file

@ -1,5 +1,4 @@
class CurrentOrders::OrdersController < ApplicationController
before_action :authenticate_orders, except: :my
def show
@ -14,8 +13,8 @@ class CurrentOrders::OrdersController < ApplicationController
respond_to do |format|
format.pdf do
pdf = case params[:document]
when 'groups' then MultipleOrdersByGroups.new(@order_ids, @doc_options)
when 'articles' then MultipleOrdersByArticles.new(@order_ids, @doc_options)
when 'groups' then MultipleOrdersByGroups.new(@order_ids, @doc_options)
when 'articles' then MultipleOrdersByArticles.new(@order_ids, @doc_options)
end
send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf'
end
@ -36,5 +35,4 @@ class CurrentOrders::OrdersController < ApplicationController
def receive
@orders = Order.finished_not_closed.includes(:supplier)
end
end

View file

@ -1,6 +1,3 @@
# encoding: utf-8
class CurrentOrdersController < ApplicationController
before_action :authenticate_orders
end

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class MultipleOrdersByArticles < OrderPdf
include OrdersHelper
@ -32,28 +31,29 @@ class MultipleOrdersByArticles < OrderPdf
dimrows << rows.length if goa.result == 0
end
next if rows.length == 0
sum = order_article.group_orders_sum
rows.unshift I18n.t('documents.order_by_articles.rows').dup # table header
rows << [I18n.t('documents.order_by_groups.sum'),
order_article.tolerance > 0 ? "#{order_article.quantity} + #{order_article.tolerance}" : order_article.quantity,
sum[:quantity],
nil] #number_to_currency(sum[:price])]
nil] # number_to_currency(sum[:price])]
text "<b>#{order_article.article.name}</b> " +
"(#{order_article.article.unit}; #{number_to_currency order_article.price.fc_price}; " +
units_history_line(order_article, plain: true) + ')',
size: fontsize(10), inline_format: true
table rows, cell_style: {size: fontsize(8), overflow: :shrink_to_fit} do |table|
table rows, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
# borders
table.cells.borders = [:bottom]
table.cells.border_width = 0.02
table.cells.border_color = 'dddddd'
table.rows(0).border_width = 1
table.rows(0).border_color = '666666'
table.row(rows.length-2).border_width = 1
table.row(rows.length-2).border_color = '666666'
table.row(rows.length-1).borders = []
table.row(rows.length - 2).border_width = 1
table.row(rows.length - 2).border_color = '666666'
table.row(rows.length - 1).borders = []
table.column(0).width = 200
table.columns(1..2).align = :center
@ -73,25 +73,24 @@ class MultipleOrdersByArticles < OrderPdf
end
def order_articles
OrderArticle.where(order_id: order).ordered.
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})
OrderArticle.where(order_id: order).ordered
.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 })
end
def each_order_article
order_articles.find_each_with_order(batch_size: BATCH_SIZE) {|oa| yield oa }
order_articles.find_each_with_order(batch_size: BATCH_SIZE) { |oa| yield oa }
end
def group_order_articles_for(order_article)
goas = order_article.group_order_articles.to_a
goas.sort_by! {|goa| goa.group_order.ordergroup_name }
goas.sort_by! { |goa| goa.group_order.ordergroup_name }
goas
end
def each_group_order_article_for(group_order)
group_order_articles_for(group_order).each {|goa| yield goa }
group_order_articles_for(group_order).each { |goa| yield goa }
end
end

View file

@ -1,4 +1,3 @@
# encoding: utf-8
class MultipleOrdersByGroups < OrderPdf
include OrdersHelper
@ -23,12 +22,12 @@ class MultipleOrdersByGroups < OrderPdf
down_or_page 15
total = 0
taxes = Hash.new {0}
taxes = Hash.new { 0 }
rows = []
dimrows = []
has_tolerance = false
each_group_order_article_for(ordergroup) do |goa|
each_group_order_article_for(ordergroup) do |goa|
has_tolerance = true if goa.order_article.price.unit_quantity > 1
price = goa.order_article.price.fc_price
sub_total = goa.total_price
@ -46,7 +45,7 @@ class MultipleOrdersByGroups < OrderPdf
next if rows.length == 0
# total
rows << [{content: I18n.t('documents.order_by_groups.sum'), colspan: 6}, number_to_currency(total), nil]
rows << [{ content: I18n.t('documents.order_by_groups.sum'), colspan: 6 }, number_to_currency(total), nil]
# table header
rows.unshift [
@ -57,14 +56,14 @@ class MultipleOrdersByGroups < OrderPdf
I18n.t('shared.articles.ordered'),
I18n.t('shared.articles.received'),
I18n.t('shared.articles_by.price_sum'),
{image: "#{Rails.root}/app/assets/images/package-bg.png", scale: 0.6, position: :center}
{ image: "#{Rails.root}/app/assets/images/package-bg.png", scale: 0.6, position: :center }
]
# last column showing unit_quantity is useless if they're all one
rows.each {|row| row[-1] = nil} unless has_tolerance
rows.each { |row| row[-1] = nil } unless has_tolerance
text ordergroup.name, size: fontsize(13), style: :bold
table rows, width: bounds.width, cell_style: {size: fontsize(8), overflow: :shrink_to_fit} do |table|
table rows, width: bounds.width, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
# borders
table.cells.borders = [:bottom]
table.cells.border_width = 0.02
@ -72,9 +71,9 @@ class MultipleOrdersByGroups < OrderPdf
table.rows(0).border_width = 1
table.rows(0).border_color = '666666'
table.rows(0).column(5).font_style = :bold
table.row(rows.length-2).border_width = 1
table.row(rows.length-2).border_color = '666666'
table.row(rows.length-1).borders = []
table.row(rows.length - 2).border_width = 1
table.row(rows.length - 2).border_color = '666666'
table.row(rows.length - 1).borders = []
table.column(0).width = 180 # @todo would like to set minimum width here
table.column(1).width = 62
@ -105,34 +104,33 @@ class MultipleOrdersByGroups < OrderPdf
end
def ordergroups
s = Ordergroup.
includes(:group_orders).
where(group_orders: {order_id: order}).
group(:id).
reorder(:name)
s = Ordergroup
.includes(:group_orders)
.where(group_orders: { order_id: order })
.group(:id)
.reorder(:name)
s = s.where(id: @options[:ordergroup]) if @options[:ordergroup]
s
end
def each_ordergroup
ordergroups.find_in_batches_with_order(batch_size: BATCH_SIZE) do |ordergroups|
@group_order_article_batch = GroupOrderArticle.
joins(:group_order).
where(group_orders: {order_id: order}).
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 }
@group_order_article_batch = GroupOrderArticle
.joins(:group_order)
.where(group_orders: { order_id: order })
.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 }
end
end
def group_order_articles_for(ordergroup)
@group_order_article_batch.select {|goa| goa.group_order.ordergroup_id == ordergroup.id }
@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 }
group_order_articles_for(ordergroup).each { |goa| yield goa }
end
end

View file

@ -1,5 +1,4 @@
module CurrentOrdersHelper
def to_pay_message(ordergroup)
funds = ordergroup.get_available_funds
if funds > 0
@ -10,5 +9,4 @@ module CurrentOrdersHelper
content_tag :b, I18n.t('helpers.current_orders.pay_amount', amount: number_to_currency(-ordergroup.get_available_funds))
end
end
end

View file

@ -3,13 +3,14 @@ module FoodsoftCurrentOrders
def navigation(primary, context)
return unless FoodsoftCurrentOrders.enabled?
return if primary[:orders].nil?
cond = Proc.new { 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)
].each {|i| primary[:orders].sub_navigation.items << i }
].each { |i| primary[:orders].sub_navigation.items << i }
end
end
end