xero_gateway 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xero_gateway.rb +4 -3
- data/lib/xero_gateway/bank_transaction.rb +4 -4
- data/lib/xero_gateway/base_record.rb +31 -11
- data/lib/xero_gateway/branding_theme.rb +14 -0
- data/lib/xero_gateway/contact.rb +39 -87
- data/lib/xero_gateway/credit_note.rb +6 -6
- data/lib/xero_gateway/dates.rb +4 -0
- data/lib/xero_gateway/gateway.rb +9 -7
- data/lib/xero_gateway/invoice.rb +7 -7
- data/lib/xero_gateway/journal_line.rb +16 -16
- data/lib/xero_gateway/line_item.rb +6 -6
- data/lib/xero_gateway/line_item_calculations.rb +2 -2
- data/lib/xero_gateway/payment.rb +2 -2
- data/lib/xero_gateway/version.rb +1 -1
- data/test/test_helper.rb +4 -4
- data/test/unit/bank_transaction_test.rb +3 -3
- data/test/unit/contact_test.rb +54 -1
- data/test/unit/credit_note_test.rb +15 -15
- data/test/unit/invoice_test.rb +15 -15
- data/test/unit/manual_journal_test.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0195a3504b16daf5f4e5ef6c9644fcb7fd8ea146'
|
4
|
+
data.tar.gz: 770b6ae03cf67b5f9575b83ad446e9b049c619ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e236f63458fa76c432032efd36ae3449c2d2aec38c43d0912d0015eb0536fdca81cd2ac58ca8f526d3c68032bff7f7f4348d1ac969abcf4095a52b3556ee5ce9
|
7
|
+
data.tar.gz: 914c8e0ed970d288f04ab4bcd2f7bf9ff538034882c62647926ee78f898fdcc53e7c001f1873e74230a7abc0c7f3923295361d5ae967bf7aa3884a8eb91c33a3
|
data/lib/xero_gateway.rb
CHANGED
@@ -19,12 +19,15 @@ require File.join(File.dirname(__FILE__), 'xero_gateway', 'money')
|
|
19
19
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'line_item_calculations')
|
20
20
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'response')
|
21
21
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'base_record')
|
22
|
+
require File.join(File.dirname(__FILE__), 'xero_gateway', 'branding_theme')
|
22
23
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'account')
|
23
24
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'accounts_list')
|
24
25
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'tracking_category')
|
26
|
+
require File.join(File.dirname(__FILE__), 'xero_gateway', 'address')
|
27
|
+
require File.join(File.dirname(__FILE__), 'xero_gateway', 'phone')
|
28
|
+
require File.join(File.dirname(__FILE__), 'xero_gateway', 'contact_person')
|
25
29
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'contact')
|
26
30
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'contact_group')
|
27
|
-
require File.join(File.dirname(__FILE__), 'xero_gateway', 'contact_person')
|
28
31
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'line_item')
|
29
32
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'payment')
|
30
33
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'payroll_calendar')
|
@@ -34,9 +37,7 @@ require File.join(File.dirname(__FILE__), 'xero_gateway', 'bank_transaction')
|
|
34
37
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'credit_note')
|
35
38
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'journal_line')
|
36
39
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'manual_journal')
|
37
|
-
require File.join(File.dirname(__FILE__), 'xero_gateway', 'address')
|
38
40
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'report')
|
39
|
-
require File.join(File.dirname(__FILE__), 'xero_gateway', 'phone')
|
40
41
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'organisation')
|
41
42
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'tax_rate')
|
42
43
|
require File.join(File.dirname(__FILE__), 'xero_gateway', 'currency')
|
@@ -157,16 +157,16 @@ module XeroGateway
|
|
157
157
|
when "UpdatedDateUTC" then bank_transaction.updated_at = parse_date_time(element.text)
|
158
158
|
when "Type" then bank_transaction.type = element.text
|
159
159
|
when "CurrencyCode" then bank_transaction.currency_code = element.text
|
160
|
-
when "CurrencyRate" then bank_transaction.currency_rate = BigDecimal
|
160
|
+
when "CurrencyRate" then bank_transaction.currency_rate = BigDecimal(element.text)
|
161
161
|
when "Contact" then bank_transaction.contact = Contact.from_xml(element)
|
162
162
|
when "BankAccount" then bank_transaction.bank_account = Account.from_xml(element)
|
163
163
|
when "Date" then bank_transaction.date = parse_date(element.text)
|
164
164
|
when "Status" then bank_transaction.status = element.text
|
165
165
|
when "Reference" then bank_transaction.reference = element.text
|
166
166
|
when "LineItems" then element.children.each {|line_item| bank_transaction.line_items_downloaded = true; bank_transaction.line_items << LineItem.from_xml(line_item) }
|
167
|
-
when "Total" then bank_transaction.total = BigDecimal
|
168
|
-
when "SubTotal" then bank_transaction.sub_total = BigDecimal
|
169
|
-
when "TotalTax" then bank_transaction.total_tax = BigDecimal
|
167
|
+
when "Total" then bank_transaction.total = BigDecimal(element.text)
|
168
|
+
when "SubTotal" then bank_transaction.sub_total = BigDecimal(element.text)
|
169
|
+
when "TotalTax" then bank_transaction.total_tax = BigDecimal(element.text)
|
170
170
|
when "IsReconciled" then bank_transaction.is_reconciled = (element.text.strip.downcase == "true")
|
171
171
|
when "Url" then bank_transaction.url = element.text
|
172
172
|
end
|
@@ -5,6 +5,10 @@ module XeroGateway
|
|
5
5
|
|
6
6
|
class_attribute :element_name
|
7
7
|
class_attribute :attribute_definitions
|
8
|
+
class_attribute :attribute_definitions_readonly
|
9
|
+
|
10
|
+
# The source XML record that initialized this instance.
|
11
|
+
attr_reader :source_xml
|
8
12
|
|
9
13
|
class << self
|
10
14
|
def attributes(hash)
|
@@ -27,8 +31,15 @@ module XeroGateway
|
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
# Set list of attributes that should never be included in update/create responses.
|
35
|
+
def readonly_attributes(*attrs)
|
36
|
+
self.attribute_definitions_readonly ||= []
|
37
|
+
self.attribute_definitions_readonly += attrs.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
def from_xml(base_element, gateway = nil)
|
41
|
+
args = gateway ? [{ gateway: gateway }] : []
|
42
|
+
new(*args).from_xml(base_element)
|
32
43
|
end
|
33
44
|
|
34
45
|
def xml_element
|
@@ -46,14 +57,14 @@ module XeroGateway
|
|
46
57
|
to_xml == other.to_xml
|
47
58
|
end
|
48
59
|
|
49
|
-
def to_xml
|
50
|
-
builder = Builder::XmlMarkup.new
|
60
|
+
def to_xml(builder = Builder::XmlMarkup.new)
|
51
61
|
builder.__send__(self.class.xml_element) do
|
52
62
|
to_xml_attributes(builder)
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
56
66
|
def from_xml(base_element)
|
67
|
+
@source_xml = base_element
|
57
68
|
from_xml_attributes(base_element)
|
58
69
|
self
|
59
70
|
end
|
@@ -79,11 +90,13 @@ module XeroGateway
|
|
79
90
|
when :boolean then element.text == "true"
|
80
91
|
when :float then element.text.to_f
|
81
92
|
when :integer then element.text.to_i
|
82
|
-
when :currency then BigDecimal
|
83
|
-
when :date then
|
84
|
-
when :datetime then
|
85
|
-
when :datetime_utc then
|
93
|
+
when :currency then BigDecimal(element.text)
|
94
|
+
when :date then Dates::Helpers.parse_date(element.text)
|
95
|
+
when :datetime then Dates::Helpers.parse_date_time(element.text)
|
96
|
+
when :datetime_utc then Dates::Helpers.parse_date_time_utc(element.text)
|
86
97
|
when Array then array_from_xml(element, attr_definition)
|
98
|
+
when Class
|
99
|
+
attr_definition.from_xml(element) if attr_definition.respond_to?(:from_xml)
|
87
100
|
else element.text
|
88
101
|
end if element.text.present? || element.children.present?
|
89
102
|
|
@@ -97,6 +110,8 @@ module XeroGateway
|
|
97
110
|
|
98
111
|
def to_xml_attributes(builder = Builder::XmlMarkup.new, path = nil, attr_definitions = self.class.attribute_definitions)
|
99
112
|
attr_definitions.each do |attr, value|
|
113
|
+
next if self.class.attribute_definitions_readonly && self.class.attribute_definitions_readonly.include?(attr)
|
114
|
+
|
100
115
|
case value
|
101
116
|
when Hash
|
102
117
|
builder.__send__(attr) do
|
@@ -104,14 +119,19 @@ module XeroGateway
|
|
104
119
|
end
|
105
120
|
when Array
|
106
121
|
raise UnsupportedAttributeType.new("#{value} instances don't respond to #to_xml") unless value.first.method_defined?(:to_xml)
|
107
|
-
|
122
|
+
options = value.length > 1 ? value.last : {}
|
123
|
+
|
124
|
+
value = send("#{path}#{attr}".underscore)
|
125
|
+
value ||= [] unless options[:omit_if_empty]
|
126
|
+
|
108
127
|
builder.__send__(attr) do |array_wrapper|
|
109
128
|
value.map do |k|
|
110
129
|
k.to_xml(array_wrapper)
|
111
130
|
end
|
112
|
-
end
|
131
|
+
end unless value.nil?
|
113
132
|
else
|
114
|
-
|
133
|
+
value = send("#{path}#{attr}".underscore)
|
134
|
+
builder.__send__(attr, value) unless value.nil?
|
115
135
|
end
|
116
136
|
end
|
117
137
|
end
|
data/lib/xero_gateway/contact.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module XeroGateway
|
2
|
-
class Contact
|
3
|
-
include Dates
|
4
|
-
|
2
|
+
class Contact < BaseRecord
|
5
3
|
GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
|
6
4
|
|
7
5
|
CONTACT_STATUS = {
|
@@ -9,29 +7,50 @@ module XeroGateway
|
|
9
7
|
'DELETED' => 'Deleted'
|
10
8
|
} unless defined?(CONTACT_STATUS)
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
attr_accessor :gateway, :errors
|
11
|
+
|
12
|
+
attributes({
|
13
|
+
"ContactID" => :string,
|
14
|
+
"ContactNumber" => :string,
|
15
|
+
"AccountNumber" => :string,
|
16
|
+
"ContactStatus" => :string,
|
17
|
+
"Name" => :string,
|
18
|
+
"FirstName" => :string,
|
19
|
+
"LastName" => :string,
|
20
|
+
"EmailAddress" => :string,
|
21
|
+
"Addresses" => [Address, { :omit_if_empty => true }],
|
22
|
+
"Phones" => [Phone],
|
23
|
+
"BankAccountDetails" => :string,
|
24
|
+
"TaxNumber" => :string,
|
25
|
+
"AccountsReceivableTaxType" => :string,
|
26
|
+
"AccountsPayableTaxType" => :string,
|
27
|
+
"ContactGroups" => :string,
|
28
|
+
"IsCustomer" => :boolean,
|
29
|
+
"IsSupplier" => :boolean,
|
30
|
+
"DefaultCurrency" => :string,
|
31
|
+
"UpdatedDateUTC" => :datetime_utc,
|
32
|
+
"ContactPersons" => [ContactPerson],
|
33
|
+
"BrandingTheme" => BrandingTheme
|
34
|
+
})
|
35
|
+
|
36
|
+
readonly_attributes "IsCustomer", "IsSupplier", "BrandingTheme"
|
37
|
+
|
38
|
+
{ :updated_at => :updated_date_utc,
|
39
|
+
:status => :contact_status,
|
40
|
+
:email => :email_address }.each do |alt, orig|
|
41
|
+
alias_method alt, orig
|
42
|
+
alias_method "#{alt}=", "#{orig}="
|
43
|
+
end
|
22
44
|
|
23
45
|
def initialize(params = {})
|
24
|
-
|
25
|
-
|
26
|
-
params = {}.merge(params)
|
27
|
-
params.each do |k,v|
|
28
|
-
self.send("#{k}=", v)
|
29
|
-
end
|
46
|
+
super
|
30
47
|
|
48
|
+
@errors ||= []
|
31
49
|
@phones ||= []
|
32
50
|
@addresses ||= nil
|
33
51
|
end
|
34
52
|
|
53
|
+
|
35
54
|
def address=(address)
|
36
55
|
self.addresses = [address]
|
37
56
|
end
|
@@ -84,6 +103,7 @@ module XeroGateway
|
|
84
103
|
self.contact_persons << ContactPerson.new(contact_person_params)
|
85
104
|
end
|
86
105
|
|
106
|
+
|
87
107
|
# Validate the Contact record according to what will be valid by the gateway.
|
88
108
|
#
|
89
109
|
# Usage:
|
@@ -142,73 +162,5 @@ module XeroGateway
|
|
142
162
|
gateway.update_contact(self)
|
143
163
|
end
|
144
164
|
|
145
|
-
def to_xml(b = Builder::XmlMarkup.new)
|
146
|
-
b.Contact {
|
147
|
-
b.ContactID self.contact_id if self.contact_id
|
148
|
-
b.ContactNumber self.contact_number if self.contact_number
|
149
|
-
b.AccountNumber self.account_number if self.account_number
|
150
|
-
b.Name self.name if self.name
|
151
|
-
b.EmailAddress self.email if self.email
|
152
|
-
b.FirstName self.first_name if self.first_name
|
153
|
-
b.LastName self.last_name if self.last_name
|
154
|
-
b.BankAccountDetails self.bank_account_details if self.bank_account_details
|
155
|
-
b.TaxNumber self.tax_number if self.tax_number
|
156
|
-
b.AccountsReceivableTaxType self.accounts_receivable_tax_type if self.accounts_receivable_tax_type
|
157
|
-
b.AccountsPayableTaxType self.accounts_payable_tax_type if self.accounts_payable_tax_type
|
158
|
-
b.ContactGroups if self.contact_groups
|
159
|
-
b.IsCustomer true if self.is_customer
|
160
|
-
b.IsSupplier true if self.is_supplier
|
161
|
-
b.DefaultCurrency if self.default_currency
|
162
|
-
b.Addresses {
|
163
|
-
addresses.each { |address| address.to_xml(b) }
|
164
|
-
} unless addresses.nil?
|
165
|
-
b.Phones {
|
166
|
-
phones.each { |phone| phone.to_xml(b) }
|
167
|
-
} if self.phones.any?
|
168
|
-
b.ContactPersons {
|
169
|
-
contact_persons.each { |contact_person| contact_person.to_xml(b) }
|
170
|
-
} unless contact_persons.nil?
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
# Take a Contact element and convert it into an Contact object
|
175
|
-
def self.from_xml(contact_element, gateway = nil)
|
176
|
-
contact = Contact.new(:gateway => gateway)
|
177
|
-
contact_element.children.each do |element|
|
178
|
-
case(element.name)
|
179
|
-
when "ContactID" then contact.contact_id = element.text
|
180
|
-
when "ContactNumber" then contact.contact_number = element.text
|
181
|
-
when "AccountNumber" then contact.account_number = element.text
|
182
|
-
when "ContactStatus" then contact.status = element.text
|
183
|
-
when "Name" then contact.name = element.text
|
184
|
-
when "FirstName" then contact.first_name = element.text
|
185
|
-
when "LastName" then contact.last_name = element.text
|
186
|
-
when "EmailAddress" then contact.email = element.text
|
187
|
-
when "Addresses" then element.children.each { |address_element| contact.addresses ||= []; contact.addresses << Address.from_xml(address_element) }
|
188
|
-
when "Phones" then element.children.each { |phone_element| contact.phones << Phone.from_xml(phone_element) }
|
189
|
-
when "BankAccountDetails" then contact.bank_account_details = element.text
|
190
|
-
when "TaxNumber" then contact.tax_number = element.text
|
191
|
-
when "AccountsReceivableTaxType" then contact.accounts_receivable_tax_type = element.text
|
192
|
-
when "AccountsPayableTaxType" then contact.accounts_payable_tax_type = element.text
|
193
|
-
when "ContactGroups" then contact.contact_groups = element.text
|
194
|
-
when "IsCustomer" then contact.is_customer = (element.text == "true")
|
195
|
-
when "IsSupplier" then contact.is_supplier = (element.text == "true")
|
196
|
-
when "DefaultCurrency" then contact.default_currency = element.text
|
197
|
-
when "UpdatedDateUTC" then contact.updated_at = parse_date_time(element.text)
|
198
|
-
when "ContactPersons" then element.children.each { |contact_person_element| contact.contact_persons ||= []; contact.contact_persons << ContactPerson.from_xml(contact_person_element) }
|
199
|
-
end
|
200
|
-
end
|
201
|
-
contact
|
202
|
-
end
|
203
|
-
|
204
|
-
def ==(other)
|
205
|
-
[ :contact_id, :contact_number, :account_number, :status, :name, :first_name, :last_name, :email, :addresses, :phones, :updated_at,
|
206
|
-
:bank_account_details, :tax_number, :accounts_receivable_tax_type, :accounts_payable_tax_type, :is_customer, :is_supplier,
|
207
|
-
:default_currency, :contact_groups ].each do |field|
|
208
|
-
return false if send(field) != other.send(field)
|
209
|
-
end
|
210
|
-
return true
|
211
|
-
end
|
212
|
-
|
213
165
|
end
|
214
166
|
end
|
@@ -197,13 +197,13 @@ module XeroGateway
|
|
197
197
|
when "Reference" then credit_note.reference = element.text
|
198
198
|
when "LineAmountTypes" then credit_note.line_amount_types = element.text
|
199
199
|
when "LineItems" then element.children.each {|line_item| credit_note.line_items_downloaded = true; credit_note.line_items << LineItem.from_xml(line_item) }
|
200
|
-
when "SubTotal" then credit_note.sub_total = BigDecimal
|
201
|
-
when "TotalTax" then credit_note.total_tax = BigDecimal
|
202
|
-
when "Total" then credit_note.total = BigDecimal
|
200
|
+
when "SubTotal" then credit_note.sub_total = BigDecimal(element.text)
|
201
|
+
when "TotalTax" then credit_note.total_tax = BigDecimal(element.text)
|
202
|
+
when "Total" then credit_note.total = BigDecimal(element.text)
|
203
203
|
when "Payments" then element.children.each { | payment | credit_note.payments << Payment.from_xml(payment) }
|
204
|
-
when "AmountDue" then credit_note.amount_due = BigDecimal
|
205
|
-
when "AmountPaid" then credit_note.amount_paid = BigDecimal
|
206
|
-
when "AmountCredited" then credit_note.amount_credited = BigDecimal
|
204
|
+
when "AmountDue" then credit_note.amount_due = BigDecimal(element.text)
|
205
|
+
when "AmountPaid" then credit_note.amount_paid = BigDecimal(element.text)
|
206
|
+
when "AmountCredited" then credit_note.amount_credited = BigDecimal(element.text)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
credit_note
|
data/lib/xero_gateway/dates.rb
CHANGED
data/lib/xero_gateway/gateway.rb
CHANGED
@@ -165,14 +165,16 @@ module XeroGateway
|
|
165
165
|
|
166
166
|
request_params = {}
|
167
167
|
|
168
|
-
request_params[:InvoiceID]
|
169
|
-
request_params[:InvoiceNumber]
|
170
|
-
request_params[:order]
|
171
|
-
request_params[:ModifiedAfter]
|
172
|
-
request_params[:
|
173
|
-
request_params[:
|
168
|
+
request_params[:InvoiceID] = options[:invoice_id] if options[:invoice_id]
|
169
|
+
request_params[:InvoiceNumber] = options[:invoice_number] if options[:invoice_number]
|
170
|
+
request_params[:order] = options[:order] if options[:order]
|
171
|
+
request_params[:ModifiedAfter] = options[:modified_since] if options[:modified_since]
|
172
|
+
request_params[:IDs] = Array(options[:invoice_ids]).join(",") if options[:invoice_ids]
|
173
|
+
request_params[:InvoiceNumbers] = Array(options[:invoice_numbers]).join(",") if options[:invoice_numbers]
|
174
|
+
request_params[:ContactIDs] = Array(options[:contact_ids]).join(",") if options[:contact_ids]
|
175
|
+
request_params[:page] = options[:page] if options[:page]
|
174
176
|
|
175
|
-
request_params[:where]
|
177
|
+
request_params[:where] = options[:where] if options[:where]
|
176
178
|
|
177
179
|
response_xml = http_get(@client, "#{@xero_url}/Invoices", request_params)
|
178
180
|
|
data/lib/xero_gateway/invoice.rb
CHANGED
@@ -209,7 +209,7 @@ module XeroGateway
|
|
209
209
|
when "InvoiceNumber" then invoice.invoice_number = element.text
|
210
210
|
when "Type" then invoice.invoice_type = element.text
|
211
211
|
when "CurrencyCode" then invoice.currency_code = element.text
|
212
|
-
when "CurrencyRate" then invoice.currency_rate = BigDecimal
|
212
|
+
when "CurrencyRate" then invoice.currency_rate = BigDecimal(element.text)
|
213
213
|
when "Contact" then invoice.contact = Contact.from_xml(element)
|
214
214
|
when "Date" then invoice.date = parse_date(element.text)
|
215
215
|
when "DueDate" then invoice.due_date = parse_date(element.text)
|
@@ -220,13 +220,13 @@ module XeroGateway
|
|
220
220
|
when "BrandingThemeID" then invoice.branding_theme_id = element.text
|
221
221
|
when "LineAmountTypes" then invoice.line_amount_types = element.text
|
222
222
|
when "LineItems" then element.children.each {|line_item| invoice.line_items_downloaded = true; invoice.line_items << LineItem.from_xml(line_item) }
|
223
|
-
when "SubTotal" then invoice.sub_total = BigDecimal
|
224
|
-
when "TotalTax" then invoice.total_tax = BigDecimal
|
225
|
-
when "Total" then invoice.total = BigDecimal
|
223
|
+
when "SubTotal" then invoice.sub_total = BigDecimal(element.text)
|
224
|
+
when "TotalTax" then invoice.total_tax = BigDecimal(element.text)
|
225
|
+
when "Total" then invoice.total = BigDecimal(element.text)
|
226
226
|
when "Payments" then element.children.each { | payment | invoice.payments << Payment.from_xml(payment) }
|
227
|
-
when "AmountDue" then invoice.amount_due = BigDecimal
|
228
|
-
when "AmountPaid" then invoice.amount_paid = BigDecimal
|
229
|
-
when "AmountCredited" then invoice.amount_credited = BigDecimal
|
227
|
+
when "AmountDue" then invoice.amount_due = BigDecimal(element.text)
|
228
|
+
when "AmountPaid" then invoice.amount_paid = BigDecimal(element.text)
|
229
|
+
when "AmountCredited" then invoice.amount_credited = BigDecimal(element.text)
|
230
230
|
when "SentToContact" then invoice.sent_to_contact = (element.text.strip.downcase == "true")
|
231
231
|
when "Url" then invoice.url = element.text
|
232
232
|
when "ValidationErrors" then invoice.errors = element.children.map { |error| Error.parse(error) }
|
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'account')
|
|
3
3
|
module XeroGateway
|
4
4
|
class JournalLine
|
5
5
|
include Money
|
6
|
-
|
6
|
+
|
7
7
|
TAX_TYPE = Account::TAX_TYPE unless defined?(TAX_TYPE)
|
8
8
|
|
9
9
|
# Any errors that occurred when the #valid? method called.
|
@@ -11,29 +11,29 @@ module XeroGateway
|
|
11
11
|
|
12
12
|
# All accessible fields
|
13
13
|
attr_accessor :journal_line_id, :line_amount, :account_code, :description, :tax_type, :tracking
|
14
|
-
|
14
|
+
|
15
15
|
def initialize(params = {})
|
16
16
|
@errors ||= []
|
17
17
|
@tracking ||= []
|
18
|
-
|
18
|
+
|
19
19
|
params.each do |k,v|
|
20
20
|
self.send("#{k}=", v)
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Validate the JournalLineItem record according to what will be valid by the gateway.
|
25
25
|
#
|
26
|
-
# Usage:
|
26
|
+
# Usage:
|
27
27
|
# journal_line_item.valid? # Returns true/false
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# Additionally sets journal_line_item.errors array to an array of field/error.
|
30
30
|
def valid?
|
31
31
|
@errors = []
|
32
|
-
|
32
|
+
|
33
33
|
if !journal_line_id.nil? && journal_line_id !~ GUID_REGEX
|
34
34
|
@errors << ['journal_line_id', 'must be blank or a valid Xero GUID']
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
unless line_amount
|
38
38
|
@errors << ['line_amount', "can't be blank"]
|
39
39
|
end
|
@@ -41,20 +41,20 @@ module XeroGateway
|
|
41
41
|
unless account_code
|
42
42
|
@errors << ['account_code', "can't be blank"]
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
@errors.size == 0
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def has_tracking?
|
49
49
|
return false if tracking.nil?
|
50
|
-
|
50
|
+
|
51
51
|
if tracking.is_a?(Array)
|
52
52
|
return tracking.any?
|
53
53
|
else
|
54
54
|
return tracking.is_a?(TrackingCategory)
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def to_xml(b = Builder::XmlMarkup.new)
|
59
59
|
b.JournalLine {
|
60
60
|
b.LineAmount line_amount # mandatory
|
@@ -73,12 +73,12 @@ module XeroGateway
|
|
73
73
|
end
|
74
74
|
}
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def self.from_xml(journal_line_element)
|
78
78
|
journal_line = JournalLine.new
|
79
79
|
journal_line_element.children.each do |element|
|
80
80
|
case(element.name)
|
81
|
-
when "LineAmount" then journal_line.line_amount = BigDecimal
|
81
|
+
when "LineAmount" then journal_line.line_amount = BigDecimal(element.text)
|
82
82
|
when "AccountCode" then journal_line.account_code = element.text
|
83
83
|
when "JournalLineID" then journal_line.journal_line_id = element.text
|
84
84
|
when "Description" then journal_line.description = element.text
|
@@ -90,7 +90,7 @@ module XeroGateway
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
journal_line
|
93
|
-
end
|
93
|
+
end
|
94
94
|
|
95
95
|
def ==(other)
|
96
96
|
[:description, :line_amount, :account_code, :tax_type].each do |field|
|
@@ -98,5 +98,5 @@ module XeroGateway
|
|
98
98
|
end
|
99
99
|
return true
|
100
100
|
end
|
101
|
-
end
|
101
|
+
end
|
102
102
|
end
|
@@ -16,7 +16,7 @@ module XeroGateway
|
|
16
16
|
@errors ||= []
|
17
17
|
@tracking ||= []
|
18
18
|
@quantity = 1
|
19
|
-
@unit_amount = BigDecimal
|
19
|
+
@unit_amount = BigDecimal('0')
|
20
20
|
|
21
21
|
params.each do |k,v|
|
22
22
|
self.send("#{k}=", v)
|
@@ -68,7 +68,7 @@ module XeroGateway
|
|
68
68
|
# for the API call to succeed.
|
69
69
|
def line_amount
|
70
70
|
total = quantity * unit_amount
|
71
|
-
total = total * (1 - (discount_rate / BigDecimal
|
71
|
+
total = total * (1 - (discount_rate / BigDecimal(100))) if discount_rate
|
72
72
|
total
|
73
73
|
end
|
74
74
|
|
@@ -103,12 +103,12 @@ module XeroGateway
|
|
103
103
|
when "LineItemID" then line_item.line_item_id = element.text
|
104
104
|
when "Description" then line_item.description = element.text
|
105
105
|
when "Quantity" then line_item.quantity = BigDecimal(element.text)
|
106
|
-
when "UnitAmount" then line_item.unit_amount = BigDecimal
|
106
|
+
when "UnitAmount" then line_item.unit_amount = BigDecimal(element.text)
|
107
107
|
when "ItemCode" then line_item.item_code = element.text
|
108
108
|
when "TaxType" then line_item.tax_type = element.text
|
109
|
-
when "TaxAmount" then line_item.tax_amount = BigDecimal
|
110
|
-
when "LineAmount" then line_item.line_amount = BigDecimal
|
111
|
-
when "DiscountRate" then line_item.discount_rate = BigDecimal
|
109
|
+
when "TaxAmount" then line_item.tax_amount = BigDecimal(element.text)
|
110
|
+
when "LineAmount" then line_item.line_amount = BigDecimal(element.text)
|
111
|
+
when "DiscountRate" then line_item.discount_rate = BigDecimal(element.text)
|
112
112
|
when "AccountCode" then line_item.account_code = element.text
|
113
113
|
when "Tracking" then
|
114
114
|
element.children.each do | tracking_element |
|
@@ -40,8 +40,8 @@ module XeroGateway
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def sum_line_items(lines, sum_type = :line_amount)
|
43
|
-
lines.inject(BigDecimal
|
44
|
-
sum + BigDecimal
|
43
|
+
lines.inject(BigDecimal('0')) do |sum, line|
|
44
|
+
sum + BigDecimal(line.send(sum_type).to_s)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
data/lib/xero_gateway/payment.rb
CHANGED
@@ -26,9 +26,9 @@ module XeroGateway
|
|
26
26
|
when 'PaymentType' then payment.payment_type = element.text
|
27
27
|
when 'Date' then payment.date = parse_date_time(element.text)
|
28
28
|
when 'UpdatedDateUTC' then payment.updated_at = parse_date_time(element.text)
|
29
|
-
when 'Amount' then payment.amount = BigDecimal
|
29
|
+
when 'Amount' then payment.amount = BigDecimal(element.text)
|
30
30
|
when 'Reference' then payment.reference = element.text
|
31
|
-
when 'CurrencyRate' then payment.currency_rate = BigDecimal
|
31
|
+
when 'CurrencyRate' then payment.currency_rate = BigDecimal(element.text)
|
32
32
|
when 'Invoice'
|
33
33
|
payment.invoice_id = element.elements["//InvoiceID"].text
|
34
34
|
payment.invoice_number = element.elements["//InvoiceNumber"].text
|
data/lib/xero_gateway/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -161,8 +161,8 @@ module TestHelper
|
|
161
161
|
line_item_params[0] = {
|
162
162
|
:description => "A LINE ITEM",
|
163
163
|
:account_code => "200",
|
164
|
-
:unit_amount => BigDecimal
|
165
|
-
:tax_amount => BigDecimal
|
164
|
+
:unit_amount => BigDecimal("100"),
|
165
|
+
:tax_amount => BigDecimal("12.5"),
|
166
166
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
|
167
167
|
}.merge(line_item_params[0])
|
168
168
|
|
@@ -230,14 +230,14 @@ module TestHelper
|
|
230
230
|
journal_line_params[0] = {
|
231
231
|
:description => "FIRST LINE",
|
232
232
|
:account_code => "200",
|
233
|
-
:line_amount => BigDecimal
|
233
|
+
:line_amount => BigDecimal("100"),
|
234
234
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
|
235
235
|
}.merge(journal_line_params[0])
|
236
236
|
params_line_1 = journal_line_params[1] || {}
|
237
237
|
journal_line_params[1] = {
|
238
238
|
:description => "SECOND LINE",
|
239
239
|
:account_code => "200",
|
240
|
-
:line_amount => BigDecimal
|
240
|
+
:line_amount => BigDecimal("-100"),
|
241
241
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah2", :options => "hello2")
|
242
242
|
}.merge(params_line_1)
|
243
243
|
|
@@ -30,8 +30,8 @@ class BankTransactionTest < Test::Unit::TestCase
|
|
30
30
|
line_item = bank_transaction.line_items.first
|
31
31
|
assert_equal('A LINE ITEM', line_item.description)
|
32
32
|
assert_equal('200', line_item.account_code)
|
33
|
-
assert_equal(BigDecimal
|
34
|
-
assert_equal(BigDecimal
|
33
|
+
assert_equal(BigDecimal('100'), line_item.unit_amount)
|
34
|
+
assert_equal(BigDecimal('12.5'), line_item.tax_amount)
|
35
35
|
end
|
36
36
|
|
37
37
|
should "allow overriding transaction defaults" do
|
@@ -114,7 +114,7 @@ class BankTransactionTest < Test::Unit::TestCase
|
|
114
114
|
XeroGateway::BankTransaction.any_instance.stubs(:line_items_downloaded?).returns(false)
|
115
115
|
parsed_bank_transaction = XeroGateway::BankTransaction.from_xml(bank_transaction_element)
|
116
116
|
assert_equal 'http://example.com?with=params&and=more', parsed_bank_transaction.url
|
117
|
-
assert_equal BigDecimal
|
117
|
+
assert_equal BigDecimal('1000'), parsed_bank_transaction.total
|
118
118
|
end
|
119
119
|
|
120
120
|
should "ignore missing contact" do
|
data/test/unit/contact_test.rb
CHANGED
@@ -98,7 +98,7 @@ class ContactTest < Test::Unit::TestCase
|
|
98
98
|
contact_element = REXML::XPath.first(REXML::Document.new(test_xml.gsub(/\s/, "")), "/Contact")
|
99
99
|
contact = XeroGateway::Contact.from_xml(contact_element)
|
100
100
|
|
101
|
-
assert_equal Time.
|
101
|
+
assert_equal Time.utc(2016, 8, 31, 04, 55, 39), contact.updated_at.utc
|
102
102
|
|
103
103
|
end
|
104
104
|
|
@@ -165,6 +165,59 @@ class ContactTest < Test::Unit::TestCase
|
|
165
165
|
assert(!phone.valid?)
|
166
166
|
end
|
167
167
|
|
168
|
+
def test_loads_branding_theme_if_set
|
169
|
+
test_xml = <<-TESTING.strip_heredoc.chomp
|
170
|
+
<Contact>
|
171
|
+
<ContactID>f1d403d1-7d30-46c2-a2be-fc2bb29bd295</ContactID>
|
172
|
+
<ContactStatus>ACTIVE</ContactStatus>
|
173
|
+
<Name>24 Locks</Name>
|
174
|
+
<Addresses>
|
175
|
+
<Address>
|
176
|
+
<AddressType>POBOX</AddressType>
|
177
|
+
</Address>
|
178
|
+
<Address>
|
179
|
+
<AddressType>STREET</AddressType>
|
180
|
+
</Address>
|
181
|
+
</Addresses>
|
182
|
+
<Phones>
|
183
|
+
<Phone>
|
184
|
+
<PhoneType>DDI</PhoneType>
|
185
|
+
</Phone>
|
186
|
+
<Phone>
|
187
|
+
<PhoneType>DEFAULT</PhoneType>
|
188
|
+
</Phone>
|
189
|
+
<Phone>
|
190
|
+
<PhoneType>FAX</PhoneType>
|
191
|
+
</Phone>
|
192
|
+
<Phone>
|
193
|
+
<PhoneType>MOBILE</PhoneType>
|
194
|
+
</Phone>
|
195
|
+
</Phones>
|
196
|
+
<ContactPersons>
|
197
|
+
<ContactPerson>
|
198
|
+
<FirstName>John</FirstName>
|
199
|
+
<LastName>Smith</LastName>
|
200
|
+
<EmailAddress>john@acme.com</EmailAddress>
|
201
|
+
<IncludeInEmails>true</IncludeInEmails>
|
202
|
+
</ContactPerson>
|
203
|
+
</ContactPersons>
|
204
|
+
<UpdatedDateUTC>2016-08-31T04:55:39.217</UpdatedDateUTC>
|
205
|
+
<IsSupplier>false</IsSupplier>
|
206
|
+
<IsCustomer>false</IsCustomer>
|
207
|
+
<HasAttachments>false</HasAttachments>
|
208
|
+
<BrandingTheme>
|
209
|
+
<BrandingThemeID>3761deb4-209e-4197-80bb-2993aff35387</BrandingThemeID>
|
210
|
+
<Name>Test_Theme</Name>
|
211
|
+
</BrandingTheme>
|
212
|
+
</Contact>
|
213
|
+
TESTING
|
214
|
+
|
215
|
+
contact_element = REXML::XPath.first(REXML::Document.new(test_xml.gsub(/\s/, "")), "/Contact")
|
216
|
+
contact = XeroGateway::Contact.from_xml(contact_element)
|
217
|
+
|
218
|
+
assert_equal "Test_Theme", contact.branding_theme.name
|
219
|
+
end
|
220
|
+
|
168
221
|
private
|
169
222
|
|
170
223
|
def create_test_contact
|
@@ -24,14 +24,14 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
24
24
|
line_item = credit_note.line_items.first
|
25
25
|
|
26
26
|
# Make sure that everything adds up to begin with.
|
27
|
-
expected_sub_total = credit_note.line_items.inject(BigDecimal
|
27
|
+
expected_sub_total = credit_note.line_items.inject(BigDecimal('0')) { | sum, l | l.line_amount }
|
28
28
|
assert_equal(expected_sub_total, credit_note.sub_total)
|
29
29
|
|
30
30
|
# Change the amount of the first line item and make sure that
|
31
31
|
# everything still continues to add up.
|
32
32
|
line_item.unit_amount = line_item.unit_amount + 10
|
33
33
|
assert_not_equal(expected_sub_total, credit_note.sub_total)
|
34
|
-
expected_sub_total = credit_note.line_items.inject(BigDecimal
|
34
|
+
expected_sub_total = credit_note.line_items.inject(BigDecimal('0')) { | sum, l | l.line_amount }
|
35
35
|
assert_equal(expected_sub_total, credit_note.sub_total)
|
36
36
|
end
|
37
37
|
|
@@ -41,14 +41,14 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
41
41
|
line_item = credit_note.line_items.first
|
42
42
|
|
43
43
|
# Make sure that everything adds up to begin with.
|
44
|
-
expected_total_tax = credit_note.line_items.inject(BigDecimal
|
44
|
+
expected_total_tax = credit_note.line_items.inject(BigDecimal('0')) { | sum, l | l.tax_amount }
|
45
45
|
assert_equal(expected_total_tax, credit_note.total_tax)
|
46
46
|
|
47
47
|
# Change the tax_amount of the first line item and make sure that
|
48
48
|
# everything still continues to add up.
|
49
49
|
line_item.tax_amount = line_item.tax_amount + 10
|
50
50
|
assert_not_equal(expected_total_tax, credit_note.total_tax)
|
51
|
-
expected_total_tax = credit_note.line_items.inject(BigDecimal
|
51
|
+
expected_total_tax = credit_note.line_items.inject(BigDecimal('0')) { | sum, l | l.tax_amount }
|
52
52
|
assert_equal(expected_total_tax, credit_note.total_tax)
|
53
53
|
end
|
54
54
|
|
@@ -96,9 +96,9 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
96
96
|
credit_note.line_items = []
|
97
97
|
|
98
98
|
assert_nothing_raised(Exception) {
|
99
|
-
assert_equal(BigDecimal
|
100
|
-
assert_equal(BigDecimal
|
101
|
-
assert_equal(BigDecimal
|
99
|
+
assert_equal(BigDecimal('0'), credit_note.sub_total)
|
100
|
+
assert_equal(BigDecimal('0'), credit_note.total_tax)
|
101
|
+
assert_equal(BigDecimal('0'), credit_note.total)
|
102
102
|
}
|
103
103
|
end
|
104
104
|
|
@@ -142,8 +142,8 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
142
142
|
# Test the line_item defaults.
|
143
143
|
assert_equal('A LINE ITEM', credit_note.line_items.first.description)
|
144
144
|
assert_equal('200', credit_note.line_items.first.account_code)
|
145
|
-
assert_equal(BigDecimal
|
146
|
-
assert_equal(BigDecimal
|
145
|
+
assert_equal(BigDecimal('100'), credit_note.line_items.first.unit_amount)
|
146
|
+
assert_equal(BigDecimal('12.5'), credit_note.line_items.first.tax_amount)
|
147
147
|
|
148
148
|
# Test overriding an credit_note parameter (assume works for all).
|
149
149
|
credit_note = create_test_credit_note({:type => 'ACCPAYCREDIT'})
|
@@ -159,18 +159,18 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
159
159
|
credit_note = create_test_credit_note({}, {}, {:description => 'OVERRIDDEN LINE ITEM'})
|
160
160
|
assert_equal(1, credit_note.line_items.size)
|
161
161
|
assert_equal('OVERRIDDEN LINE ITEM', credit_note.line_items.first.description)
|
162
|
-
assert_equal(BigDecimal
|
162
|
+
assert_equal(BigDecimal('100'), credit_note.line_items.first.unit_amount)
|
163
163
|
|
164
164
|
# Test overriding line_items with array of 2 line_items.
|
165
165
|
credit_note = create_test_credit_note({}, {}, [
|
166
166
|
{:description => 'OVERRIDDEN ITEM 1'},
|
167
|
-
{:description => 'OVERRIDDEN ITEM 2', :account_code => '200', :unit_amount => BigDecimal
|
167
|
+
{:description => 'OVERRIDDEN ITEM 2', :account_code => '200', :unit_amount => BigDecimal('200'), :tax_amount => '25.0'}
|
168
168
|
])
|
169
169
|
assert_equal(2, credit_note.line_items.size)
|
170
170
|
assert_equal('OVERRIDDEN ITEM 1', credit_note.line_items[0].description)
|
171
|
-
assert_equal(BigDecimal
|
171
|
+
assert_equal(BigDecimal('100'), credit_note.line_items[0].unit_amount)
|
172
172
|
assert_equal('OVERRIDDEN ITEM 2', credit_note.line_items[1].description)
|
173
|
-
assert_equal(BigDecimal
|
173
|
+
assert_equal(BigDecimal('200'), credit_note.line_items[1].unit_amount)
|
174
174
|
end
|
175
175
|
|
176
176
|
def test_auto_creation_of_associated_contact
|
@@ -256,8 +256,8 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
256
256
|
line_item_params[0] = {
|
257
257
|
:description => "A LINE ITEM",
|
258
258
|
:account_code => "200",
|
259
|
-
:unit_amount => BigDecimal
|
260
|
-
:tax_amount => BigDecimal
|
259
|
+
:unit_amount => BigDecimal("100"),
|
260
|
+
:tax_amount => BigDecimal("12.5"),
|
261
261
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
|
262
262
|
}.merge(line_item_params[0])
|
263
263
|
|
data/test/unit/invoice_test.rb
CHANGED
@@ -97,7 +97,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
97
97
|
line_item = invoice.line_items.first
|
98
98
|
|
99
99
|
# Make sure that everything adds up to begin with.
|
100
|
-
expected_sub_total = invoice.line_items.inject(BigDecimal
|
100
|
+
expected_sub_total = invoice.line_items.inject(BigDecimal('0')) { | sum, l | l.line_amount }
|
101
101
|
assert_equal(expected_sub_total, invoice.sub_total)
|
102
102
|
|
103
103
|
# Change the sub_total and check that it doesn't modify anything.
|
@@ -108,7 +108,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
108
108
|
# everything still continues to add up.
|
109
109
|
line_item.unit_amount = line_item.unit_amount + 10
|
110
110
|
assert_not_equal(expected_sub_total, invoice.sub_total)
|
111
|
-
expected_sub_total = invoice.line_items.inject(BigDecimal
|
111
|
+
expected_sub_total = invoice.line_items.inject(BigDecimal('0')) { | sum, l | l.line_amount }
|
112
112
|
assert_equal(expected_sub_total, invoice.sub_total)
|
113
113
|
end
|
114
114
|
|
@@ -118,7 +118,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
118
118
|
line_item = invoice.line_items.first
|
119
119
|
|
120
120
|
# Make sure that everything adds up to begin with.
|
121
|
-
expected_total_tax = invoice.line_items.inject(BigDecimal
|
121
|
+
expected_total_tax = invoice.line_items.inject(BigDecimal('0')) { | sum, l | l.tax_amount }
|
122
122
|
assert_equal(expected_total_tax, invoice.total_tax)
|
123
123
|
|
124
124
|
# Change the total_tax and check that it doesn't modify anything.
|
@@ -129,7 +129,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
129
129
|
# everything still continues to add up.
|
130
130
|
line_item.tax_amount = line_item.tax_amount + 10
|
131
131
|
assert_not_equal(expected_total_tax, invoice.total_tax)
|
132
|
-
expected_total_tax = invoice.line_items.inject(BigDecimal
|
132
|
+
expected_total_tax = invoice.line_items.inject(BigDecimal('0')) { | sum, l | l.tax_amount }
|
133
133
|
assert_equal(expected_total_tax, invoice.total_tax)
|
134
134
|
end
|
135
135
|
|
@@ -202,9 +202,9 @@ class InvoiceTest < Test::Unit::TestCase
|
|
202
202
|
invoice.line_items = []
|
203
203
|
|
204
204
|
assert_nothing_raised(Exception) {
|
205
|
-
assert_equal(BigDecimal
|
206
|
-
assert_equal(BigDecimal
|
207
|
-
assert_equal(BigDecimal
|
205
|
+
assert_equal(BigDecimal('0'), invoice.sub_total)
|
206
|
+
assert_equal(BigDecimal('0'), invoice.total_tax)
|
207
|
+
assert_equal(BigDecimal('0'), invoice.total)
|
208
208
|
}
|
209
209
|
end
|
210
210
|
|
@@ -250,8 +250,8 @@ class InvoiceTest < Test::Unit::TestCase
|
|
250
250
|
# Test the line_item defaults.
|
251
251
|
assert_equal('A LINE ITEM', invoice.line_items.first.description)
|
252
252
|
assert_equal('200', invoice.line_items.first.account_code)
|
253
|
-
assert_equal(BigDecimal
|
254
|
-
assert_equal(BigDecimal
|
253
|
+
assert_equal(BigDecimal('100'), invoice.line_items.first.unit_amount)
|
254
|
+
assert_equal(BigDecimal('12.5'), invoice.line_items.first.tax_amount)
|
255
255
|
|
256
256
|
# Test optional params
|
257
257
|
assert_nil invoice.url
|
@@ -270,18 +270,18 @@ class InvoiceTest < Test::Unit::TestCase
|
|
270
270
|
invoice = create_test_invoice({}, {}, {:description => 'OVERRIDDEN LINE ITEM'})
|
271
271
|
assert_equal(1, invoice.line_items.size)
|
272
272
|
assert_equal('OVERRIDDEN LINE ITEM', invoice.line_items.first.description)
|
273
|
-
assert_equal(BigDecimal
|
273
|
+
assert_equal(BigDecimal('100'), invoice.line_items.first.unit_amount)
|
274
274
|
|
275
275
|
# Test overriding line_items with array of 2 line_items.
|
276
276
|
invoice = create_test_invoice({}, {}, [
|
277
277
|
{:description => 'OVERRIDDEN ITEM 1'},
|
278
|
-
{:description => 'OVERRIDDEN ITEM 2', :account_code => '200', :unit_amount => BigDecimal
|
278
|
+
{:description => 'OVERRIDDEN ITEM 2', :account_code => '200', :unit_amount => BigDecimal('200'), :tax_amount => '25.0'}
|
279
279
|
])
|
280
280
|
assert_equal(2, invoice.line_items.size)
|
281
281
|
assert_equal('OVERRIDDEN ITEM 1', invoice.line_items[0].description)
|
282
|
-
assert_equal(BigDecimal
|
282
|
+
assert_equal(BigDecimal('100'), invoice.line_items[0].unit_amount)
|
283
283
|
assert_equal('OVERRIDDEN ITEM 2', invoice.line_items[1].description)
|
284
|
-
assert_equal(BigDecimal
|
284
|
+
assert_equal(BigDecimal('200'), invoice.line_items[1].unit_amount)
|
285
285
|
end
|
286
286
|
|
287
287
|
def test_auto_creation_of_associated_contact
|
@@ -391,8 +391,8 @@ class InvoiceTest < Test::Unit::TestCase
|
|
391
391
|
line_item_params[0] = {
|
392
392
|
:description => "A LINE ITEM",
|
393
393
|
:account_code => "200",
|
394
|
-
:unit_amount => BigDecimal
|
395
|
-
:tax_amount => BigDecimal
|
394
|
+
:unit_amount => BigDecimal("100"),
|
395
|
+
:tax_amount => BigDecimal("12.5"),
|
396
396
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
|
397
397
|
}.merge(line_item_params[0])
|
398
398
|
|
@@ -16,7 +16,7 @@ class ManualJournalTest < Test::Unit::TestCase
|
|
16
16
|
journal_line = manual_journal.journal_lines.first
|
17
17
|
assert_equal('FIRST LINE', journal_line.description)
|
18
18
|
assert_equal('200', journal_line.account_code)
|
19
|
-
assert_equal(BigDecimal
|
19
|
+
assert_equal(BigDecimal('100'), journal_line.line_amount)
|
20
20
|
end
|
21
21
|
|
22
22
|
should "allow overriding transaction defaults" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xero_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Connor
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: builder
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/xero_gateway/address.rb
|
189
189
|
- lib/xero_gateway/bank_transaction.rb
|
190
190
|
- lib/xero_gateway/base_record.rb
|
191
|
+
- lib/xero_gateway/branding_theme.rb
|
191
192
|
- lib/xero_gateway/ca-certificates.crt
|
192
193
|
- lib/xero_gateway/contact.rb
|
193
194
|
- lib/xero_gateway/contact_group.rb
|