Issue e-invoice along with invoice

Closes #1222
This commit is contained in:
Artur Beljajev 2019-06-25 19:52:15 +03:00
parent 25638da546
commit 86a69c09bf
5 changed files with 17 additions and 6 deletions

View file

@ -53,7 +53,7 @@ class Registrar < ActiveRecord::Base
def issue_prepayment_invoice(amount, description = nil) def issue_prepayment_invoice(amount, description = nil)
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
invoices.create!( invoice = invoices.create!(
issue_date: Time.zone.today, issue_date: Time.zone.today,
due_date: (Time.zone.now + Setting.days_to_keep_invoices_active.days).to_date, due_date: (Time.zone.now + Setting.days_to_keep_invoices_active.days).to_date,
description: description, description: description,
@ -95,6 +95,11 @@ class Registrar < ActiveRecord::Base
} }
] ]
) )
e_invoice = invoice.to_e_invoice
e_invoice.deliver
invoice
end end
def cash_account def cash_account

View file

@ -17,10 +17,7 @@ namespace :registrars do
next if reload_pending || !threshold_reached next if reload_pending || !threshold_reached
Registrar.transaction do Registrar.transaction do
invoice = registrar.issue_prepayment_invoice(reload_amount) registrar.issue_prepayment_invoice(reload_amount)
e_invoice = invoice.to_e_invoice
e_invoice.deliver
registrar.settings['balance_auto_reload']['pending'] = true registrar.settings['balance_auto_reload']['pending'] = true
registrar.save! registrar.save!
end end

View file

@ -93,6 +93,14 @@ class RegistrarTest < ActiveSupport::TestCase
Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting
end end
def test_issues_e_invoice_along_with_invoice
EInvoice::Providers::TestProvider.deliveries.clear
@registrar.issue_prepayment_invoice(100)
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
def test_invalid_without_address_street def test_invalid_without_address_street
registrar = valid_registrar registrar = valid_registrar
registrar.address_street = '' registrar.address_street = ''

View file

@ -5,7 +5,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
setup do setup do
@registrar = registrars(:bestnames) @registrar = registrars(:bestnames)
EInvoice.provider = EInvoice::Providers::TestProvider.new
end end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached

View file

@ -26,6 +26,8 @@ end
CompanyRegister::Client = CompanyRegisterClientStub CompanyRegister::Client = CompanyRegisterClientStub
EInvoice.provider = EInvoice::Providers::TestProvider.new
class ActiveSupport::TestCase class ActiveSupport::TestCase
include FactoryBot::Syntax::Methods include FactoryBot::Syntax::Methods