mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 21:46:24 +02:00
Merge pull request #2458 from internetee/monthly-invoices-fix
Handling of cancelled monthly invoices
This commit is contained in:
commit
b515649ded
3 changed files with 55 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLength
|
||||
class SendMonthlyInvoicesJob < ApplicationJob
|
||||
queue_as :default
|
||||
discard_on StandardError
|
||||
|
||||
|
@ -62,6 +62,7 @@ class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLen
|
|||
private
|
||||
|
||||
def handle_assign_numbers_response_errors(response)
|
||||
raise 'ASSIGN NUMBER RESPONSE ERROR: Not Found' if response['error'] == 'Not Found'
|
||||
raise 'INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE' if response['code'] == '403'
|
||||
raise 'PROBLEM WITH TOKEN' if response['error'] == 'out of range'
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module Registrar::BookKeeping # rubocop:disable Metrics/ModuleLength
|
||||
module Registrar::BookKeeping
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
DOMAIN_TO_PRODUCT = { 'ee': '01EE', 'com.ee': '02COM', 'pri.ee': '03PRI',
|
||||
|
@ -39,7 +39,8 @@ module Registrar::BookKeeping # rubocop:disable Metrics/ModuleLength
|
|||
end
|
||||
|
||||
def find_or_init_monthly_invoice(month:, overwrite:)
|
||||
invoice = invoices.find_by(monthly_invoice: true, issue_date: month.end_of_month.to_date)
|
||||
invoice = invoices.find_by(monthly_invoice: true, issue_date: month.end_of_month.to_date,
|
||||
cancelled_at: nil)
|
||||
return invoice if invoice && !overwrite
|
||||
|
||||
summary = monthly_summary(month: month)
|
||||
|
|
|
@ -50,8 +50,8 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_monthly_summary_is_delivered_if_invoice_already_exists
|
||||
@monthly_invoice = invoices(:one)
|
||||
@monthly_invoice.update(number: 309_902, monthly_invoice: true,
|
||||
monthly_invoice = invoices(:one)
|
||||
monthly_invoice.update(number: 309_902, monthly_invoice: true,
|
||||
issue_date: @date.last_month.end_of_month,
|
||||
due_date: @date.last_month.end_of_month,
|
||||
metadata: metadata,
|
||||
|
@ -77,9 +77,49 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
@monthly_invoice.reload
|
||||
monthly_invoice.reload
|
||||
|
||||
assert_not_nil @monthly_invoice.sent_at
|
||||
assert_not_nil monthly_invoice.sent_at
|
||||
assert_emails 1
|
||||
end
|
||||
|
||||
def test_new_monthly_summary_is_delivered_if_invoice_cancelled
|
||||
monthly_invoice = invoices(:one)
|
||||
monthly_invoice.update(number: 309_902, monthly_invoice: true,
|
||||
issue_date: @date.last_month.end_of_month,
|
||||
due_date: @date.last_month.end_of_month,
|
||||
metadata: metadata,
|
||||
in_directo: false,
|
||||
sent_at: nil,
|
||||
cancelled_at: Time.now,
|
||||
e_invoice_sent_at: nil)
|
||||
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
activity.update!(activity_type: 'create', price: price)
|
||||
@user.update(language: 'et')
|
||||
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_903] }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
|
||||
(body.include? '.test registreerimine: 1 aasta(t)') &&
|
||||
(body.include? 'Domeenide ettemaks') &&
|
||||
(body.include? '309903')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_enqueued_jobs 1, only: SendEInvoiceJob do
|
||||
assert_difference('Invoice.count', 1) do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
monthly_invoice.reload
|
||||
last_invoice = Invoice.last
|
||||
assert_not_nil last_invoice.sent_at
|
||||
assert_equal last_invoice.issue_date, monthly_invoice.issue_date
|
||||
assert_nil monthly_invoice.sent_at
|
||||
assert_emails 1
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue