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
|
queue_as :default
|
||||||
discard_on StandardError
|
discard_on StandardError
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLen
|
||||||
private
|
private
|
||||||
|
|
||||||
def handle_assign_numbers_response_errors(response)
|
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 'INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE' if response['code'] == '403'
|
||||||
raise 'PROBLEM WITH TOKEN' if response['error'] == 'out of range'
|
raise 'PROBLEM WITH TOKEN' if response['error'] == 'out of range'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module Registrar::BookKeeping # rubocop:disable Metrics/ModuleLength
|
module Registrar::BookKeeping
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
DOMAIN_TO_PRODUCT = { 'ee': '01EE', 'com.ee': '02COM', 'pri.ee': '03PRI',
|
DOMAIN_TO_PRODUCT = { 'ee': '01EE', 'com.ee': '02COM', 'pri.ee': '03PRI',
|
||||||
|
@ -39,7 +39,8 @@ module Registrar::BookKeeping # rubocop:disable Metrics/ModuleLength
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_init_monthly_invoice(month:, overwrite:)
|
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
|
return invoice if invoice && !overwrite
|
||||||
|
|
||||||
summary = monthly_summary(month: month)
|
summary = monthly_summary(month: month)
|
||||||
|
|
|
@ -50,14 +50,14 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_monthly_summary_is_delivered_if_invoice_already_exists
|
def test_monthly_summary_is_delivered_if_invoice_already_exists
|
||||||
@monthly_invoice = invoices(:one)
|
monthly_invoice = invoices(:one)
|
||||||
@monthly_invoice.update(number: 309_902, monthly_invoice: true,
|
monthly_invoice.update(number: 309_902, monthly_invoice: true,
|
||||||
issue_date: @date.last_month.end_of_month,
|
issue_date: @date.last_month.end_of_month,
|
||||||
due_date: @date.last_month.end_of_month,
|
due_date: @date.last_month.end_of_month,
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
in_directo: false,
|
in_directo: false,
|
||||||
sent_at: nil,
|
sent_at: nil,
|
||||||
e_invoice_sent_at: nil)
|
e_invoice_sent_at: nil)
|
||||||
|
|
||||||
activity = account_activities(:one)
|
activity = account_activities(:one)
|
||||||
price = billing_prices(:create_one_year)
|
price = billing_prices(:create_one_year)
|
||||||
|
@ -77,9 +77,49 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
SendMonthlyInvoicesJob.perform_now
|
SendMonthlyInvoicesJob.perform_now
|
||||||
end
|
end
|
||||||
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
|
assert_emails 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue