Class: XeroKiwi::Accounting::PaymentTerms

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

Overview

Xero payment terms for an Organisation or Contact, containing separate terms for bills (payable) and sales (receivable).

See: developer.xero.com/documentation/api/accounting/types#paymentterms

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ PaymentTerms

Returns a new instance of PaymentTerms.



18
19
20
21
22
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 18

def initialize(attrs)
  attrs  = attrs.transform_keys(&:to_s)
  @bills = PaymentTerm.from_hash(attrs["Bills"])
  @sales = PaymentTerm.from_hash(attrs["Sales"])
end

Instance Attribute Details

#billsObject (readonly)

Returns the value of attribute bills.



10
11
12
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 10

def bills
  @bills
end

#salesObject (readonly)

Returns the value of attribute sales.



10
11
12
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 10

def sales
  @sales
end

Class Method Details

.from_hash(hash) ⇒ Object



12
13
14
15
16
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 12

def self.from_hash(hash)
  return nil if hash.nil?

  new(hash)
end

Instance Method Details

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



28
29
30
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 28

def ==(other)
  other.is_a?(PaymentTerms) && bills == other.bills && sales == other.sales
end

#hashObject



33
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 33

def hash = [self.class, bills, sales].hash

#inspectObject



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

def inspect
  "#<#{self.class} bills=#{bills.inspect} sales=#{sales.inspect}>"
end

#to_hObject



24
25
26
# File 'lib/xero_kiwi/accounting/payment_terms.rb', line 24

def to_h
  { bills: bills&.to_h, sales: sales&.to_h }
end