Class: XeroKiwi::Accounting::Allocation

Inherits:
Object
  • Object
show all
Defined in:
lib/xero_kiwi/accounting/allocation.rb

Overview

Represents an allocation of a credit note, prepayment, or overpayment against an invoice.

See: developer.xero.com/documentation/api/accounting/overpayments

Constant Summary collapse

ATTRIBUTES =
{
  allocation_id: "AllocationID",
  amount:        "Amount",
  date:          "Date",
  invoice:       "Invoice",
  is_deleted:    "IsDeleted"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Allocation

Returns a new instance of Allocation.



22
23
24
25
26
27
28
29
# File 'lib/xero_kiwi/accounting/allocation.rb', line 22

def initialize(attrs)
  attrs          = attrs.transform_keys(&:to_s)
  @allocation_id = attrs["AllocationID"]
  @amount        = attrs["Amount"]
  @date          = parse_time(attrs["Date"])
  @invoice       = attrs["Invoice"] ? Invoice.new(attrs["Invoice"], reference: true) : nil
  @is_deleted    = attrs["IsDeleted"]
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



35
36
37
# File 'lib/xero_kiwi/accounting/allocation.rb', line 35

def ==(other)
  other.is_a?(Allocation) && other.allocation_id == allocation_id
end

#hashObject



40
# File 'lib/xero_kiwi/accounting/allocation.rb', line 40

def hash = [self.class, allocation_id].hash

#inspectObject



42
43
44
45
# File 'lib/xero_kiwi/accounting/allocation.rb', line 42

def inspect
  "#<#{self.class} allocation_id=#{allocation_id.inspect} " \
    "amount=#{amount.inspect}>"
end

#to_hObject



31
32
33
# File 'lib/xero_kiwi/accounting/allocation.rb', line 31

def to_h
  ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] }
end