From 59ecfa8e2f40fa9bc1f4ed947b3847fc54e1eaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergei=20Ts=C3=B5ganov?= Date: Wed, 12 Oct 2022 10:40:03 +0300 Subject: [PATCH] Fixed codeclimate issues --- app/jobs/send_monthly_invoices_job.rb | 13 +++++-------- app/models/concerns/invoice/book_keeping.rb | 13 +++++++++++++ app/models/invoice.rb | 13 ------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/jobs/send_monthly_invoices_job.rb b/app/jobs/send_monthly_invoices_job.rb index 26b383c82..8c13340aa 100644 --- a/app/jobs/send_monthly_invoices_job.rb +++ b/app/jobs/send_monthly_invoices_job.rb @@ -33,8 +33,7 @@ class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLen result = EisBilling::GetMonthlyInvoiceNumbers.send_request(invoice_without_numbers.size) response = JSON.parse(result.body) - billing_restrictions_issue if response['code'] == '403' - billing_out_of_range_issue if response['error'] == 'out of range' + handle_assign_numbers_response_errors(response) numbers = response['invoice_numbers'] invoice_without_numbers.each_with_index do |inv, index| @@ -61,11 +60,9 @@ class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLen private - def billing_out_of_range_issue - raise 'INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE' - end - - def billing_restrictions_issue - raise 'PROBLEM WITH TOKEN' + def handle_assign_numbers_response_errors(response) + raise 'INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE' if response['code'] == '403' + raise 'PROBLEM WITH TOKEN' if response['error'] == 'out of range' end end + diff --git a/app/models/concerns/invoice/book_keeping.rb b/app/models/concerns/invoice/book_keeping.rb index ebde18799..895b763cf 100644 --- a/app/models/concerns/invoice/book_keeping.rb +++ b/app/models/concerns/invoice/book_keeping.rb @@ -25,6 +25,19 @@ module Invoice::BookKeeping invoice end + def to_e_invoice(payable: true) + generator = Invoice::EInvoiceGenerator.new(self, payable) + generator.generate + end + + def do_not_send_e_invoice? + e_invoice_sent? || cancelled? + end + + def e_invoice_sent? + e_invoice_sent_at.present? + end + private def compose_monthly_directo_lines(lines: []) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 88e311029..64366b997 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -131,19 +131,6 @@ class Invoice < ApplicationRecord generator.as_pdf end - def to_e_invoice(payable: true) - generator = Invoice::EInvoiceGenerator.new(self, payable) - generator.generate - end - - def do_not_send_e_invoice? - e_invoice_sent? || cancelled? - end - - def e_invoice_sent? - e_invoice_sent_at.present? - end - def as_csv_row [ number,