fix rubocop errors

This commit is contained in:
Viehlieb 2021-12-24 13:35:26 +01:00
parent 09679812af
commit bafa163ce5
8 changed files with 107 additions and 115 deletions

View file

@ -9,9 +9,11 @@ class GroupOrderInvoicesController < ApplicationController
send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number]
end
end
else raise RecordInvalid
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => "#{error} " + I18n.t('errors.check_tax_number'))
else
raise RecordInvalid
end
rescue => error
redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{error} " + I18n.t('errors.check_tax_number'))
end
def destroy
@ -27,7 +29,7 @@ class GroupOrderInvoicesController < ApplicationController
def create
go = GroupOrder.find(params[:group_order])
@order = go.order
goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
respond_to do |format|
format.js
end

View file

@ -32,7 +32,6 @@ class GroupOrderInvoicePdf < RenderPDF
text I18n.t('documents.group_order_invoice_pdf.tax_number', :number => @options[:tax_number]), size: fontsize(9), align: :left
end
# Receiving Ordergroup
bounding_box [margin_box.left, margin_box.top - 20], width: 200 do
text I18n.t('documents.group_order_invoice_pdf.invoicee')
@ -76,16 +75,17 @@ class GroupOrderInvoicePdf < RenderPDF
marge = FoodsoftConfig[:price_markup]
# data table looks different when price_markup > 0
if marge == 0
data = [I18n.t('documents.group_order_invoice_pdf.no_price_markup_rows')]
data = if marge == 0
[I18n.t('documents.group_order_invoice_pdf.no_price_markup_rows')]
else
data = [I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
[I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
end
goa_tax_hash = GroupOrderArticle.where(group_order_id: group_order.id).find_each.group_by { |oat| oat.order_article.price.tax }
goa_tax_hash.each do |tax, group_order_articles|
group_order_articles.each do |goa|
# if no unit is received, nothing is to be charged
next if goa.result.to_i == 0
order_article = goa.order_article
goa_total_net = goa.result * order_article.price.price
goa_total_gross = goa.result * order_article.price.gross_price
@ -118,7 +118,7 @@ class GroupOrderInvoicePdf < RenderPDF
sum = []
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_net'), number_to_currency(total_net)]
tax_hash_net.keys.each do |tax|
tax_hash_net.each_key.each do |tax|
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.tax_included', tax: tax), number_to_currency(tax_hash_gross[tax] - tax_hash_net[tax])]
end
unless marge == 0
@ -134,7 +134,6 @@ class GroupOrderInvoicePdf < RenderPDF
table.row(sum.length - 1).columns(0..4).borders = []
table.row(sum.length - 1).border_bottom_width = 2
table.row(sum.length - 1).columns(5).borders = [:bottom]
end
move_down 15

View file

@ -63,7 +63,6 @@ class Mailer < ActionMailer::Base
subject: I18n.t('mailer.group_order_invoice.subject', group: @group.name, supplier: @supplier)
end
# Sends order result for specific Ordergroup
def order_result(user, group_order)
@order = group_order.order

View file

@ -1,5 +1,4 @@
class GroupOrderInvoice < ApplicationRecord
belongs_to :group_order
validates_presence_of :group_order
validates_uniqueness_of :invoice_number
@ -8,10 +7,10 @@ class GroupOrderInvoice < ApplicationRecord
def generate_invoice_number(count)
trailing_number = count.to_s.rjust(4, '0')
unless GroupOrderInvoice.find_by(invoice_number: Time.now.strftime("%Y%m%d") + trailing_number)
Time.now.strftime("%Y%m%d") + trailing_number
else
if GroupOrderInvoice.find_by(invoice_number: Time.now.strftime("%Y%m%d") + trailing_number)
generate_invoice_number(count.to_i + 1)
else
Time.now.strftime("%Y%m%d") + trailing_number
end
end
@ -44,7 +43,7 @@ class GroupOrderInvoice < ApplicationRecord
invoice_data[:order_articles] = {}
group_order.order_articles.each do |order_article|
# Get the result of last time ordering, if possible
goa = group_order.group_order_articles.detect { |goa| goa.order_article_id == order_article.id }
goa = group_order.group_order_articles.detect { |tmp_goa| tmp_goa.order_article_id == order_article.id }
# Build hash with relevant data
invoice_data[:order_articles][order_article.id] = {
@ -55,6 +54,5 @@ class GroupOrderInvoice < ApplicationRecord
}
end
invoice_data
end
end

View file

@ -172,7 +172,6 @@ Rails.application.routes.draw do
get :unpaid, on: :collection
end
resources :links, controller: 'financial_links', only: [:create, :show] do
collection do
get :incomplete

View file

@ -9,13 +9,10 @@ feature GroupOrderInvoice, js: true do
let(:ftt) { create :financial_transaction_type }
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
describe 'trigger process' do
include ActiveJob::TestHelper
before { login admin }
after { clear_enqueued_jobs }
it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do
@ -31,7 +28,7 @@ feature GroupOrderInvoice, js: true do
oa.update_results!
order.reload
FoodsoftConfig[:group_order_invoices] = { use: true }
FoodsoftConfig[:contact][:tax_number] = 12345678
FoodsoftConfig[:contact][:tax_number] = 12_345_678
visit confirm_finance_order_path(id: order.id, type: ftt)
expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear'))
click_link_or_button I18n.t('finance.balancing.confirm.clear')
@ -50,7 +47,7 @@ feature GroupOrderInvoice, js: true do
it 'generates Group Order Invoice when order is closed if tax_number is set' do
goa.update_quantities 2, 0
oa.update_results!
FoodsoftConfig[:contact][:tax_number] = 12345678
FoodsoftConfig[:contact][:tax_number] = 12_345_678
order.update!(state: 'closed')
order.reload
visit finance_order_index_path
@ -58,4 +55,3 @@ feature GroupOrderInvoice, js: true do
expect(GroupOrderInvoice.all.count).to eq(1)
end
end
end

View file

@ -13,49 +13,48 @@ describe GroupOrderInvoice do
it 'does not create group order invoice if tax_number not set' do
expect { goi }.to raise_error(ActiveRecord::RecordInvalid)
end
end
describe 'valid group order invoice' do
before do
FoodsoftConfig[:contact][:tax_number] = 12345678
FoodsoftConfig[:contact][:tax_number] = 123_457_8
end
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
let(:user_2) { create :user, groups: [create(:ordergroup)] }
let(:user2) { create :user, groups: [create(:ordergroup)] }
let(:goi_1) { create :group_order_invoice, group_order_id: group_order.id }
let(:goi_2) { create :group_order_invoice, group_order_id: group_order.id }
let(:goi1) { create :group_order_invoice, group_order_id: group_order.id }
let(:goi2) { create :group_order_invoice, group_order_id: group_order.id }
let(:group_order_2) {create :group_order, order: order, ordergroup: user_2.ordergroup }
let(:group_order2) { create :group_order, order: order, ordergroup: user2.ordergroup }
let(:goi_3) { create :group_order_invoice, group_order_id: group_order_2.id }
let(:goi_4) { create :group_order_invoice, group_order_id: group_order_2.id, invoice_number: invoice_number1 }
let(:goi3) { create :group_order_invoice, group_order_id: group_order2.id }
let(:goi4) { create :group_order_invoice, group_order_id: group_order2.id, invoice_number: invoice_number1 }
it 'creates group order invoice if tax_number is set' do
expect(goi_1).to be_valid
expect(goi1).to be_valid
end
it 'sets invoice_number according to date' do
number = Time.now.strftime("%Y%m%d") + '0001'
expect(goi_1.invoice_number).to eq(number.to_i)
expect(goi1.invoice_number).to eq(number.to_i)
end
it 'fails to create if group_order_id is used multiple times for creation' do
expect(goi_1.group_order.id).to eq(group_order.id)
expect{goi_2}.to raise_error(ActiveRecord::RecordNotUnique)
expect(goi1.group_order.id).to eq(group_order.id)
expect { goi2 }.to raise_error(ActiveRecord::RecordNotUnique)
end
it 'creates two different group order invoice with different invoice_numbers' do
expect(goi_1.invoice_number).to eq(invoice_number1.to_i)
expect(goi_3.invoice_number).to eq(invoice_number2.to_i)
expect(goi1.invoice_number).to eq(invoice_number1.to_i)
expect(goi3.invoice_number).to eq(invoice_number2.to_i)
end
it 'fails to create two different group order invoice with same invoice_numbers' do
goi_1
expect{goi_4}.to raise_error(ActiveRecord::RecordInvalid)
goi1
expect { goi4 }.to raise_error(ActiveRecord::RecordInvalid)
end
end
end