Sha256: 2c5b69b67e6fbdcb8cb1c42f7fa37b86a9337b097e5e7956e52bb8109e8b1d56

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

module Zuora
  class Invoice < ZObject
    def self.extra_attributes(attributes=[])
      super([:body])
    end

    def self.create(attributes={})
      self.client.generate([self.new(attributes).to_zobject]).first
    end

    def save
      result = self.class.create(self.attributes)
      if result[:success]
        @errors = []
        __setobj__(self.class.find(result[:id]).to_zobject)
      else
        @errors = result[:errors]
      end
      result[:success]
    end

    def errors
      @errors || []
    end

    def post
      return false unless self.id
      result = self.class.update_attributes(:id => self.id, :status => "Posted").first
      @errors = result[:errors]
      result[:success]
    end

    def invoice_items
      @invoice_items ||= InvoiceItem.where(:invoiceid => self.id)
    end

    def account
      @account ||= Account.find(self.accountId)
    end

    def payments
      # Payments, sorted by date.
      @payments ||= InvoicePayment.where(:invoiceId => self.id).map(&:payment).sort { |a, b| a.effectiveDate <=> b.effectiveDate }
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
active_zuora-1.5.2 lib/active_zuora/invoice.rb
active_zuora-1.5.1 lib/active_zuora/invoice.rb
active_zuora-1.5.0 lib/active_zuora/invoice.rb
active_zuora-1.4.21 lib/active_zuora/invoice.rb
active_zuora-1.4.20 lib/active_zuora/invoice.rb
active_zuora-1.4.19 lib/active_zuora/invoice.rb
active_zuora-1.4.18 lib/active_zuora/invoice.rb
active_zuora-1.4.17 lib/active_zuora/invoice.rb
active_zuora-1.4.16 lib/active_zuora/invoice.rb
active_zuora-1.4.15 lib/active_zuora/invoice.rb
active_zuora-1.4.13 lib/active_zuora/invoice.rb
active_zuora-1.4.12 lib/active_zuora/invoice.rb
active_zuora-1.4.11 lib/active_zuora/invoice.rb
active_zuora-1.4.8 lib/active_zuora/invoice.rb
active_zuora-1.4.7 lib/active_zuora/invoice.rb
active_zuora-1.4.6 lib/active_zuora/invoice.rb
active_zuora-1.4.5 lib/active_zuora/invoice.rb
active_zuora-1.4.4 lib/active_zuora/invoice.rb
active_zuora-1.4.2 lib/active_zuora/invoice.rb
active_zuora-1.4.1 lib/active_zuora/invoice.rb