Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/xero-ruby/models/accounting/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Contact
EIN ||= "EIN".freeze
ITIN ||= "ITIN".freeze
ATIN ||= "ATIN".freeze
NONE ||= "NONE".freeze
TAXNUMBERTYPE_SSN ||= "TAXNUMBERTYPE/SSN".freeze
TAXNUMBERTYPE_EIN ||= "TAXNUMBERTYPE/EIN".freeze
TAXNUMBERTYPE_ITIN ||= "TAXNUMBERTYPE/ITIN".freeze
TAXNUMBERTYPE_ATIN ||= "TAXNUMBERTYPE/ATIN".freeze
TAXNUMBERTYPE_NONE ||= "TAXNUMBERTYPE/NONE".freeze

# The tax type from TaxRates
attr_accessor :accounts_receivable_tax_type
Expand Down Expand Up @@ -538,7 +544,10 @@ def valid?
return false if !@company_number.nil? && @company_number.to_s.length > 50
return false if !@email_address.nil? && @email_address.to_s.length > 255
return false if !@tax_number.nil? && @tax_number.to_s.length > 50
tax_number_type_validator = EnumAttributeValidator.new('String', ["SSN", "EIN", "ITIN", "ATIN"])
tax_number_type_validator = EnumAttributeValidator.new(
'String',
["SSN", "EIN", "ITIN", "ATIN", "NONE", "TAXNUMBERTYPE/SSN", "TAXNUMBERTYPE/EIN", "TAXNUMBERTYPE/ITIN", "TAXNUMBERTYPE/ATIN", "TAXNUMBERTYPE/NONE"]
)
return false unless tax_number_type_validator.valid?(@tax_number_type)
sales_default_line_amount_type_validator = EnumAttributeValidator.new('String', ["INCLUSIVE", "EXCLUSIVE", "NONE"])
return false unless sales_default_line_amount_type_validator.valid?(@sales_default_line_amount_type)
Expand Down Expand Up @@ -640,7 +649,10 @@ def tax_number=(tax_number)
# Custom attribute writer method checking allowed values (enum).
# @param [Object] tax_number_type Object to be assigned
def tax_number_type=(tax_number_type)
validator = EnumAttributeValidator.new('String', ["SSN", "EIN", "ITIN", "ATIN"])
validator = EnumAttributeValidator.new(
'String',
["SSN", "EIN", "ITIN", "ATIN", "NONE", "TAXNUMBERTYPE/SSN", "TAXNUMBERTYPE/EIN", "TAXNUMBERTYPE/ITIN", "TAXNUMBERTYPE/ATIN", "TAXNUMBERTYPE/NONE"]
)
unless validator.valid?(tax_number_type)
fail ArgumentError, "invalid value for \"tax_number_type\", must be one of #{validator.allowable_values}."
end
Expand Down
18 changes: 18 additions & 0 deletions spec/accounting/models/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@
end
end

describe 'test attribute "tax_number_type"' do
it 'accepts unprefixed tax number types' do
["SSN", "EIN", "ITIN", "ATIN", "NONE"].each do |value|
expect { @instance.tax_number_type = value }.not_to raise_error
end
end

it 'accepts tax number types returned by the API' do
["TAXNUMBERTYPE/SSN", "TAXNUMBERTYPE/EIN", "TAXNUMBERTYPE/ITIN", "TAXNUMBERTYPE/ATIN", "TAXNUMBERTYPE/NONE"].each do |value|
expect { @instance.tax_number_type = value }.not_to raise_error
end
end

it 'rejects unsupported tax number types' do
expect { @instance.tax_number_type = "INVALID" }.to raise_error(ArgumentError)
end
end

describe 'test attribute "accounts_receivable_tax_type"' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
Expand Down