Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'active_zuora'
  4.  
  5. username=""
  6. password=""
  7.  
  8. ActiveZuora.configure(
  9. :username => username,
  10. :password => password,
  11. :log => false,
  12. # :wsdl => 'https://www.zuora.com/apps/servlet/GenerateWsdl?version=77.0'
  13. :wsdl => 'https://dl.dropboxusercontent.com/u/1029223/zuora.a.77.0.wsdl'
  14. )
  15.  
  16. ActiveZuora::Base.connection.soap_client.wsdl.endpoint.host = 'www.zuora.com'
  17.  
  18. ActiveZuora.generate_classes
  19.  
  20. class ActiveZuora::CreditBalanceAdjustment
  21. include ActiveZuora::Base
  22. self.namespace = 'http://object.api.zuora.com/'
  23. include ActiveZuora::ZObject
  24.  
  25. field :account_id, :string
  26. field :adjustment_date, :date
  27. field :source_transaction_id, :string
  28. field :amount, :decimal
  29. field :comment, :string
  30. field :reason_code, :string
  31. field :created_date, :date
  32. field :type, :string
  33. end
  34.  
  35. invoices = ActiveZuora::Invoice.select(:id, :status, :amount, :account_id, :invoice_date).where(:status => 'Posted', :amount => {'<' => 0}, :credit_balance_adjustment_amount => 0)
  36.  
  37. invoices.each do |i|
  38. puts "Creating credit balance adjustment for invoice: #{i.id} - #{i.status} - #{i.amount}"
  39.  
  40. cba = ActiveZuora::CreditBalanceAdjustment.new
  41. cba.source_transaction_id = i.id
  42. cba.amount = i.amount * -1
  43. cba.comment = "Automatic transfer of negative invoice to account credit balance"
  44. cba.reason_code = "Standard Adjustment"
  45. cba.type = "Increase"
  46.  
  47. cba.save
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement