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.4.0 lib/active_zuora/invoice.rb