mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
code linting
This commit is contained in:
parent
b243800f5a
commit
c4d959570f
@ -32,7 +32,7 @@ class AccountingExportService
|
||||
invoices = Invoice.where('created_at >= ? AND created_at <= ?', start_date, end_date).order('created_at ASC')
|
||||
invoices = invoices.where('total > 0') unless export_zeros
|
||||
invoices.each do |i|
|
||||
puts "processing invoice #{i.id}..." unless Rails.env.test?
|
||||
Rails.logger.debug { "processing invoice #{i.id}..." } unless Rails.env.test?
|
||||
content << generate_rows(i)
|
||||
end
|
||||
|
||||
@ -62,20 +62,25 @@ class AccountingExportService
|
||||
# Generate the "subscription" and "reservation" rows associated with the provided invoice
|
||||
def items_rows(invoice)
|
||||
rows = invoice.subscription_invoice? ? "#{subscription_row(invoice)}\n" : ''
|
||||
if invoice.main_item.object_type == 'Reservation'
|
||||
case invoice.main_item.object_type
|
||||
when 'Reservation'
|
||||
items = invoice.invoice_items.reject { |ii| ii.object_type == 'Subscription' }
|
||||
items.each do |item|
|
||||
rows << "#{reservation_row(invoice, item)}\n"
|
||||
end
|
||||
elsif invoice.main_item.object_type == 'WalletTransaction'
|
||||
when 'WalletTransaction'
|
||||
rows << "#{wallet_row(invoice)}\n"
|
||||
elsif invoice.main_item.object_type == 'StatisticProfilePrepaidPack'
|
||||
when 'StatisticProfilePrepaidPack'
|
||||
rows << "#{pack_row(invoice)}\n"
|
||||
elsif invoice.main_item.object_type == 'Error'
|
||||
when 'Error'
|
||||
items = invoice.invoice_items.reject { |ii| ii.object_type == 'Subscription' }
|
||||
items.each do |item|
|
||||
rows << "#{error_row(invoice, item)}\n"
|
||||
end
|
||||
when 'Subscription'
|
||||
# do nothing, subscription was already handled by subscription_row
|
||||
else
|
||||
Rails.logger.warn { "Unknown main object type #{invoice.main_item.object_type}" }
|
||||
end
|
||||
rows
|
||||
end
|
||||
@ -185,18 +190,14 @@ class AccountingExportService
|
||||
row << invoice.reference
|
||||
when 'line_label'
|
||||
row << line_label
|
||||
when 'debit_origin'
|
||||
when 'debit_origin', 'debit_euro'
|
||||
row << method(debit_method).call(invoice, amount)
|
||||
when 'credit_origin'
|
||||
row << method(credit_method).call(invoice, amount)
|
||||
when 'debit_euro'
|
||||
row << method(debit_method).call(invoice, amount)
|
||||
when 'credit_euro'
|
||||
when 'credit_origin', 'credit_euro'
|
||||
row << method(credit_method).call(invoice, amount)
|
||||
when 'lettering'
|
||||
row << ''
|
||||
else
|
||||
puts "Unsupported column: #{column}"
|
||||
Rails.logger.debug { "Unsupported column: #{column}" }
|
||||
end
|
||||
row << separator
|
||||
end
|
||||
@ -214,30 +215,30 @@ class AccountingExportService
|
||||
if invoice.subscription_invoice?
|
||||
Setting.get("accounting_subscription_#{type}")
|
||||
else
|
||||
puts "WARN: Invoice #{invoice.id} has no subscription"
|
||||
Rails.logger.debug { "WARN: Invoice #{invoice.id} has no subscription" }
|
||||
end
|
||||
when :reservation
|
||||
if invoice.main_item.object_type == 'Reservation'
|
||||
Setting.get("accounting_#{invoice.main_item.object.reservable_type}_#{type}")
|
||||
else
|
||||
puts "WARN: Invoice #{invoice.id} has no reservation"
|
||||
Rails.logger.debug { "WARN: Invoice #{invoice.id} has no reservation" }
|
||||
end
|
||||
when :wallet
|
||||
if invoice.main_item.object_type == 'WalletTransaction'
|
||||
Setting.get("accounting_wallet_#{type}")
|
||||
else
|
||||
puts "WARN: Invoice #{invoice.id} is not a wallet credit"
|
||||
Rails.logger.debug { "WARN: Invoice #{invoice.id} is not a wallet credit" }
|
||||
end
|
||||
when :pack
|
||||
if invoice.main_item.object_type == 'StatisticProfilePrepaidPack'
|
||||
Setting.get("accounting_Pack_#{type}")
|
||||
else
|
||||
puts "WARN: Invoice #{invoice.id} has no prepaid-pack"
|
||||
Rails.logger.debug { "WARN: Invoice #{invoice.id} has no prepaid-pack" }
|
||||
end
|
||||
when :error
|
||||
Setting.get("accounting_Error_#{type}")
|
||||
else
|
||||
puts "Unsupported account #{account}"
|
||||
Rails.logger.debug { "Unsupported account #{account}" }
|
||||
end || ''
|
||||
end
|
||||
|
||||
|
@ -14,7 +14,8 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
post '/api/accounting/export',
|
||||
params: {
|
||||
query: {
|
||||
columns: %w[journal_code date account_code account_label piece line_label debit_origin credit_origin debit_euro credit_euro lettering],
|
||||
columns: %w[journal_code date account_code account_label piece line_label
|
||||
debit_origin credit_origin debit_euro credit_euro lettering],
|
||||
encoding: 'ISO-8859-1',
|
||||
date_format: '%d/%m/%Y',
|
||||
start_date: '2012-03-12T00:00:00.000Z',
|
||||
@ -66,7 +67,7 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
card_client_label = Setting.get('accounting_card_client_label')
|
||||
assert_equal card_client_label, data[0][I18n.t('accounting_export.account_label')], 'Account label for card client is wrong'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} was not paid by card"
|
||||
warn "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} was not paid by card"
|
||||
end
|
||||
|
||||
assert_equal first_invoice.reference, data[0][I18n.t('accounting_export.piece')], 'Piece (invoice reference) is wrong'
|
||||
@ -76,14 +77,14 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
data[0][I18n.t('accounting_export.line_label')],
|
||||
'Line label does not contains the reference to the invoiced item'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} does not have a subscription"
|
||||
warn "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} does not have a subscription"
|
||||
end
|
||||
|
||||
if first_invoice.wallet_transaction_id.nil?
|
||||
assert_equal first_invoice.total / 100.00, data[0][I18n.t('accounting_export.debit_origin')].to_f, 'Origin debit amount does not match'
|
||||
assert_equal first_invoice.total / 100.00, data[0][I18n.t('accounting_export.debit_euro')].to_f, 'Euro debit amount does not match'
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} is using wallet"
|
||||
warn "WARNING: unable to test accurately accounting export: invoice #{first_invoice.id} is using wallet"
|
||||
end
|
||||
|
||||
assert_equal 0, data[0][I18n.t('accounting_export.credit_origin')].to_f, 'Credit origin amount does not match'
|
||||
@ -130,7 +131,7 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
|
||||
assert_equal machine_label, item_row[I18n.t('accounting_export.account_label')], 'Account label for machine reservation is wrong'
|
||||
|
||||
else
|
||||
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{machine_invoice.id} is not a Machine reservation"
|
||||
warn "WARNING: unable to test accurately accounting export: invoice #{machine_invoice.id} is not a Machine reservation"
|
||||
end
|
||||
|
||||
# Clean CSV file
|
||||
|
Loading…
x
Reference in New Issue
Block a user