mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Reinit Directo client by function
This commit is contained in:
parent
452fa49a71
commit
732afd8cbf
1 changed files with 11 additions and 15 deletions
|
@ -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,22 +29,17 @@ 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|
|
||||||
@client = DirectoApi::Client.new(api_url, sales_agent, payment_term)
|
next unless registrar.cash_account
|
||||||
fetch_monthly_summary(registrar: registrar)
|
|
||||||
|
@client = new_directo_client
|
||||||
|
summary = registrar.monthly_summary(month: @month)
|
||||||
|
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
||||||
next unless @client.invoices.count.positive?
|
next unless @client.invoices.count.positive?
|
||||||
|
|
||||||
sync_with_directo
|
sync_with_directo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_monthly_summary(registrar:)
|
|
||||||
return unless registrar.cash_account
|
|
||||||
|
|
||||||
Rails.logger.info "Fetching monthly summary for registrar #{registrar.name}"
|
|
||||||
summary = registrar.monthly_summary(month: @month)
|
|
||||||
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def assign_monthly_numbers
|
def assign_monthly_numbers
|
||||||
if directo_counter_exceedable?(@client.invoices.count)
|
if directo_counter_exceedable?(@client.invoices.count)
|
||||||
raise 'Directo Counter is going to be out of period!'
|
raise 'Directo Counter is going to be out of period!'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue