mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
Merge branch 'story/116954455-directo' into staging
This commit is contained in:
commit
a827142ae1
2 changed files with 15 additions and 5 deletions
|
@ -60,7 +60,8 @@ class Directo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.send_monthly_invoices
|
def self.send_monthly_invoices(debug: false)
|
||||||
|
@debug = debug
|
||||||
I18n.locale = :et
|
I18n.locale = :et
|
||||||
month = Time.now - 1.month
|
month = Time.now - 1.month
|
||||||
invoices_until = month.end_of_month
|
invoices_until = month.end_of_month
|
||||||
|
@ -141,11 +142,15 @@ class Directo < ActiveRecord::Base
|
||||||
|
|
||||||
data = builder.to_xml.gsub("\n",'')
|
data = builder.to_xml.gsub("\n",'')
|
||||||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s
|
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s
|
||||||
|
if @debug
|
||||||
|
STDOUT << "#{Time.zone.now.utc} - Directo xml had to be sent #{data}\n"
|
||||||
|
else
|
||||||
Setting.directo_monthly_number_last = directo_next
|
Setting.directo_monthly_number_last = directo_next
|
||||||
Nokogiri::XML(response).css("Result").each do |res|
|
Nokogiri::XML(response).css("Result").each do |res|
|
||||||
Directo.create!(response: res.as_json.to_h, invoice_number: directo_next)
|
Directo.create!(request: data, response: res.as_json.to_h, invoice_number: directo_next)
|
||||||
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Rails.logger.info("[DIRECTO] Registrar #{registrar.id} has nothing to be sent to Directo")
|
Rails.logger.info("[DIRECTO] Registrar #{registrar.id} has nothing to be sent to Directo")
|
||||||
end
|
end
|
||||||
|
|
5
db/migrate/20160405131315_add_request_to_directo.rb
Normal file
5
db/migrate/20160405131315_add_request_to_directo.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddRequestToDirecto < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :directos, :request, :text
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue