Class: XeroKiwi::Accounting::CreditNote
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::CreditNote
- Defined in:
- lib/xero_kiwi/accounting/credit_note.rb
Overview
Represents a Xero Credit Note returned by the Accounting API.
See: developer.xero.com/documentation/api/accounting/creditnotes
Constant Summary collapse
- ATTRIBUTES =
{ credit_note_id: "CreditNoteID", credit_note_number: "CreditNoteNumber", type: "Type", contact: "Contact", date: "Date", status: "Status", line_amount_types: "LineAmountTypes", line_items: "LineItems", sub_total: "SubTotal", total_tax: "TotalTax", total: "Total", cis_deduction: "CISDeduction", updated_date_utc: "UpdatedDateUTC", currency_code: "CurrencyCode", currency_rate: "CurrencyRate", fully_paid_on_date: "FullyPaidOnDate", reference: "Reference", sent_to_contact: "SentToContact", remaining_credit: "RemainingCredit", allocations: "Allocations", branding_theme_id: "BrandingThemeID", has_attachments: "HasAttachments" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #accounts_payable? ⇒ Boolean
- #accounts_receivable? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attrs, reference: false) ⇒ CreditNote
constructor
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #inspect ⇒ Object
- #reference? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs, reference: false) ⇒ CreditNote
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 47 def initialize(attrs, reference: false) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength attrs = attrs.transform_keys(&:to_s) @is_reference = reference @credit_note_id = attrs["CreditNoteID"] @credit_note_number = attrs["CreditNoteNumber"] @type = attrs["Type"] @contact = attrs["Contact"] ? Contact.new(attrs["Contact"], reference: true) : nil @date = parse_time(attrs["Date"]) @status = attrs["Status"] @line_amount_types = attrs["LineAmountTypes"] @line_items = (attrs["LineItems"] || []).map { |li| LineItem.new(li) } @sub_total = attrs["SubTotal"] @total_tax = attrs["TotalTax"] @total = attrs["Total"] @cis_deduction = attrs["CISDeduction"] @updated_date_utc = parse_time(attrs["UpdatedDateUTC"]) @currency_code = attrs["CurrencyCode"] @currency_rate = attrs["CurrencyRate"] @fully_paid_on_date = parse_time(attrs["FullyPaidOnDate"]) @reference = attrs["Reference"] @sent_to_contact = attrs["SentToContact"] @remaining_credit = attrs["RemainingCredit"] @allocations = (attrs["Allocations"] || []).map { |a| Allocation.new(a) } @branding_theme_id = attrs["BrandingThemeID"] @has_attachments = attrs["HasAttachments"] end |
Class Method Details
.from_response(payload) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 38 def self.from_response(payload) return [] if payload.nil? items = payload["CreditNotes"] return [] if items.nil? items.map { |attrs| new(attrs) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
84 85 86 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 84 def ==(other) other.is_a?(CreditNote) && other.credit_note_id == credit_note_id end |
#accounts_payable? ⇒ Boolean
78 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 78 def accounts_payable? = type == "ACCPAYCREDIT" |
#accounts_receivable? ⇒ Boolean
74 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 74 def accounts_receivable? = type == "ACCRECCREDIT" |
#hash ⇒ Object
89 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 89 def hash = [self.class, credit_note_id].hash |
#inspect ⇒ Object
91 92 93 94 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 91 def inspect "#<#{self.class} credit_note_id=#{credit_note_id.inspect} " \ "type=#{type.inspect} status=#{status.inspect} total=#{total.inspect}>" end |
#reference? ⇒ Boolean
76 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 76 def reference? = @is_reference |
#to_h ⇒ Object
80 81 82 |
# File 'lib/xero_kiwi/accounting/credit_note.rb', line 80 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |