mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Merge pull request #1524 from internetee/277-check-monthly-invoice-number-in-range
Check if Directo counter is in range
This commit is contained in:
commit
f41289cfa8
2 changed files with 17 additions and 3 deletions
|
@ -67,7 +67,7 @@ class Directo < ApplicationRecord
|
|||
|
||||
|
||||
def self.send_monthly_invoices(debug: false)
|
||||
I18n.locale = :et
|
||||
I18n.locale = :et unless Rails.env.test?
|
||||
month = Time.now - 1.month
|
||||
invoices_until = month.end_of_month
|
||||
date_format = "%Y-%m-%d"
|
||||
|
@ -76,8 +76,9 @@ class Directo < ApplicationRecord
|
|||
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
||||
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i), min_directo].compact.max || 0
|
||||
if max_directo && max_directo <= last_directo
|
||||
raise "Directo counter is out of period (max allowed number is smaller than last counter number)"
|
||||
if max_directo && (max_directo <= last_directo + Registrar.count)
|
||||
raise 'Directo counter is out of period (max allowed number is smaller than last counter'\
|
||||
'number plus Registrar\'s count)'
|
||||
end
|
||||
|
||||
directo_next = last_directo
|
||||
|
|
|
@ -5,6 +5,19 @@ class DirectoTest < ActiveSupport::TestCase
|
|||
@invoice = invoices(:one)
|
||||
end
|
||||
|
||||
def test_monthly_invoices_max_range_raises_if_overlaps
|
||||
|
||||
Setting.directo_monthly_number_max = Setting.directo_monthly_number_last.to_i + Registrar.count - 1
|
||||
error_message = 'Directo counter is out of period (max allowed number is smaller than last '\
|
||||
'counternumber plus Registrar\'s count)'
|
||||
|
||||
error = assert_raises RuntimeError do
|
||||
Directo.send_monthly_invoices
|
||||
end
|
||||
|
||||
assert_equal error_message, error.message
|
||||
end
|
||||
|
||||
def test_xml_is_include_transaction_date
|
||||
@invoice.update(total: @invoice.account_activity.bank_transaction.sum)
|
||||
@invoice.account_activity.bank_transaction.update(paid_at: Time.zone.now)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue