Class: Quickbooks::Model::Customer

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/quickbooks/model/customer.rb

Constant Summary collapse

XML_COLLECTION_NODE =
"Customer"
XML_NODE =
"Customer"
REST_RESOURCE =
'customer'

Instance Method Summary collapse

Methods inherited from BaseModel

resource_for_collection, resource_for_singular, #to_xml_inject_ns, #to_xml_ns

Instance Method Details

#active? ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/quickbooks/model/customer.rb', line 56

def active?
  active.to_s == 'true'
end

#bill_with_parent? ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/quickbooks/model/customer.rb', line 64

def bill_with_parent?
  bill_with_parent.to_s == 'true'
end

#email_address ⇒ Object



88
89
90
# File 'lib/quickbooks/model/customer.rb', line 88

def email_address
  primary_email_address
end

#email_address=(email_address) ⇒ Object



84
85
86
# File 'lib/quickbooks/model/customer.rb', line 84

def email_address=(email_address)
  self.primary_email_address = Quickbooks::Model::EmailAddress.new(email_address)
end

#email_address_is_valid ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/quickbooks/model/customer.rb', line 107

def email_address_is_valid
  if primary_email_address
    address = primary_email_address.address
    unless address.index('@') && address.index('.')
      errors.add(:primary_email_address, "Email address must contain @ and . (dot)")
    end
  end
end

#job? ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/quickbooks/model/customer.rb', line 60

def job?
  job.to_s == 'true'
end

#names_cannot_contain_invalid_characters ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/quickbooks/model/customer.rb', line 98

def names_cannot_contain_invalid_characters
  [:display_name, :given_name, :middle_name, :family_name, :print_on_check_name].each do |property|
    value = send(property).to_s
    if value.index(':')
      errors.add(property, ":#{property} cannot contain a colon (:).")
    end
  end
end

#taxable? ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/quickbooks/model/customer.rb', line 68

def taxable?
  taxable.to_s == 'true'
end

#valid_for_create? ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/quickbooks/model/customer.rb', line 79

def valid_for_create?
  valid?
  errors.empty?
end

#valid_for_deletion? ⇒ Boolean

To delete an account Intuit requires we provide Id and SyncToken fields

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/quickbooks/model/customer.rb', line 93

def valid_for_deletion?
  return false if(id.nil? || sync_token.nil?)
  id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
end

#valid_for_update? ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'lib/quickbooks/model/customer.rb', line 72

def valid_for_update?
  if sync_token.nil?
    errors.add(:sync_token, "Missing required attribute SyncToken for update")
  end
  errors.empty?
end