mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Merge pull request #1671 from internetee/directo-requests-one-by-one
Send each registrar's monthly summary to Directo separately
This commit is contained in:
commit
f5df30aca1
3 changed files with 56 additions and 16 deletions
|
@ -9,7 +9,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/internetee/directo.git
|
remote: https://github.com/internetee/directo.git
|
||||||
revision: 8ff8a382d004ffb85722a6a7a68a020bd4d7159b
|
revision: e4ba54f601d1815fd8782a196788730d47861e86
|
||||||
branch: master
|
branch: master
|
||||||
specs:
|
specs:
|
||||||
directo (1.0.1)
|
directo (1.0.1)
|
||||||
|
@ -165,7 +165,7 @@ GEM
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.12.2)
|
coffee-script-source (1.12.2)
|
||||||
concurrent-ruby (1.1.6)
|
concurrent-ruby (1.1.7)
|
||||||
countries (3.0.1)
|
countries (3.0.1)
|
||||||
i18n_data (~> 0.10.0)
|
i18n_data (~> 0.10.0)
|
||||||
sixarm_ruby_unaccent (~> 1.1)
|
sixarm_ruby_unaccent (~> 1.1)
|
||||||
|
@ -241,7 +241,7 @@ GEM
|
||||||
httpi (2.4.4)
|
httpi (2.4.4)
|
||||||
rack
|
rack
|
||||||
socksify
|
socksify
|
||||||
i18n (1.8.3)
|
i18n (1.8.5)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
i18n_data (0.10.0)
|
i18n_data (0.10.0)
|
||||||
isikukood (0.1.2)
|
isikukood (0.1.2)
|
||||||
|
|
|
@ -2,15 +2,16 @@ class DirectoInvoiceForwardJob < Que::Job
|
||||||
def run(monthly: false, dry: false)
|
def run(monthly: false, dry: false)
|
||||||
@dry = dry
|
@dry = dry
|
||||||
(@month = Time.zone.now - 1.month) if monthly
|
(@month = Time.zone.now - 1.month) if monthly
|
||||||
api_url = ENV['directo_invoice_url']
|
|
||||||
sales_agent = Setting.directo_sales_agent
|
|
||||||
payment_term = Setting.directo_receipt_payment_term
|
|
||||||
@prepayment_product_id = Setting.directo_receipt_product_name
|
|
||||||
|
|
||||||
@client = DirectoApi::Client.new(api_url, sales_agent, payment_term)
|
@client = new_directo_client
|
||||||
monthly ? send_monthly_invoices : send_receipts
|
monthly ? send_monthly_invoices : send_receipts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_directo_client
|
||||||
|
DirectoApi::Client.new(ENV['directo_invoice_url'], Setting.directo_sales_agent,
|
||||||
|
Setting.directo_receipt_payment_term)
|
||||||
|
end
|
||||||
|
|
||||||
def send_receipts
|
def send_receipts
|
||||||
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
||||||
|
|
||||||
|
@ -28,19 +29,18 @@ class DirectoInvoiceForwardJob < Que::Job
|
||||||
|
|
||||||
def send_monthly_invoices
|
def send_monthly_invoices
|
||||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||||
fetch_monthly_summary(registrar: registrar)
|
next unless registrar.cash_account
|
||||||
|
|
||||||
|
@client = new_directo_client
|
||||||
|
send_invoice_for_registrar(registrar)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless @client.invoices.count.positive?
|
|
||||||
|
|
||||||
sync_with_directo
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_monthly_summary(registrar:)
|
def send_invoice_for_registrar(registrar)
|
||||||
return unless registrar.cash_account
|
|
||||||
|
|
||||||
summary = registrar.monthly_summary(month: @month)
|
summary = registrar.monthly_summary(month: @month)
|
||||||
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
||||||
|
|
||||||
|
sync_with_directo if @client.invoices.count.positive?
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_monthly_numbers
|
def assign_monthly_numbers
|
||||||
|
|
|
@ -151,4 +151,44 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sends_each_monthly_invoice_separately
|
||||||
|
WebMock.reset!
|
||||||
|
|
||||||
|
activity = account_activities(:one)
|
||||||
|
price = billing_prices(:create_one_year)
|
||||||
|
price.update(duration: '3 years')
|
||||||
|
activity.update(activity_type: 'create', price: price)
|
||||||
|
|
||||||
|
# Creating account activity for second action
|
||||||
|
another_activity = activity.dup
|
||||||
|
another_activity.account = accounts(:two)
|
||||||
|
|
||||||
|
AccountActivity.skip_callback(:create, :after, :update_balance)
|
||||||
|
another_activity.created_at = Time.zone.parse('2010-07-05 10:00')
|
||||||
|
another_activity.save
|
||||||
|
AccountActivity.set_callback(:create, :after, :update_balance)
|
||||||
|
|
||||||
|
response = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<results>
|
||||||
|
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||||
|
</results>
|
||||||
|
XML
|
||||||
|
|
||||||
|
first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||||
|
body = CGI.unescape(request.body)
|
||||||
|
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames')
|
||||||
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
|
second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||||
|
body = CGI.unescape(request.body)
|
||||||
|
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||||
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
|
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||||
|
|
||||||
|
assert_requested first_registrar_stub
|
||||||
|
assert_requested second_registrar_stub
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue