quickbooks-ruby 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/lib/quickbooks-ruby.rb +12 -2
  3. data/lib/quickbooks/model/account.rb +3 -3
  4. data/lib/quickbooks/model/account_based_expense_line_detail.rb +2 -2
  5. data/lib/quickbooks/model/base_model.rb +5 -1
  6. data/lib/quickbooks/model/bill.rb +2 -1
  7. data/lib/quickbooks/model/bill_line_item.rb +2 -2
  8. data/lib/quickbooks/model/bill_payment.rb +0 -1
  9. data/lib/quickbooks/model/bill_payment_line_item.rb +2 -2
  10. data/lib/quickbooks/model/class.rb +31 -0
  11. data/lib/quickbooks/model/credit_memo.rb +8 -1
  12. data/lib/quickbooks/model/customer.rb +2 -2
  13. data/lib/quickbooks/model/department.rb +31 -0
  14. data/lib/quickbooks/model/discount_line_detail.rb +2 -2
  15. data/lib/quickbooks/model/discount_override.rb +1 -1
  16. data/lib/quickbooks/model/document_numbering.rb +18 -0
  17. data/lib/quickbooks/model/employee.rb +1 -1
  18. data/lib/quickbooks/model/estimate.rb +3 -6
  19. data/lib/quickbooks/model/group_line_detail.rb +2 -2
  20. data/lib/quickbooks/model/invoice.rb +9 -8
  21. data/lib/quickbooks/model/invoice_line_item.rb +2 -2
  22. data/lib/quickbooks/model/item_based_expense_line_detail.rb +3 -3
  23. data/lib/quickbooks/model/line.rb +1 -1
  24. data/lib/quickbooks/model/markup_info.rb +2 -2
  25. data/lib/quickbooks/model/payment.rb +2 -2
  26. data/lib/quickbooks/model/payment_line_detail.rb +2 -2
  27. data/lib/quickbooks/model/payment_method.rb +1 -1
  28. data/lib/quickbooks/model/purchase.rb +2 -2
  29. data/lib/quickbooks/model/sales_item_line_detail.rb +1 -1
  30. data/lib/quickbooks/model/sales_receipt.rb +8 -6
  31. data/lib/quickbooks/model/tax_code.rb +3 -14
  32. data/lib/quickbooks/model/tax_line_detail.rb +2 -2
  33. data/lib/quickbooks/model/tax_rate.rb +1 -4
  34. data/lib/quickbooks/model/transaction_tax_detail.rb +1 -1
  35. data/lib/quickbooks/service/account.rb +0 -4
  36. data/lib/quickbooks/service/base_service.rb +20 -12
  37. data/lib/quickbooks/service/bill.rb +4 -2
  38. data/lib/quickbooks/service/bill_payment.rb +1 -3
  39. data/lib/quickbooks/service/class.rb +23 -0
  40. data/lib/quickbooks/service/company_info.rb +1 -5
  41. data/lib/quickbooks/service/credit_memo.rb +2 -4
  42. data/lib/quickbooks/service/customer.rb +0 -4
  43. data/lib/quickbooks/service/department.rb +23 -0
  44. data/lib/quickbooks/service/employee.rb +0 -4
  45. data/lib/quickbooks/service/estimate.rb +1 -5
  46. data/lib/quickbooks/service/invoice.rb +2 -6
  47. data/lib/quickbooks/service/item.rb +1 -5
  48. data/lib/quickbooks/service/payment.rb +0 -4
  49. data/lib/quickbooks/service/payment_method.rb +6 -8
  50. data/lib/quickbooks/service/purchase.rb +1 -3
  51. data/lib/quickbooks/service/purchase_order.rb +2 -4
  52. data/lib/quickbooks/service/sales_receipt.rb +1 -3
  53. data/lib/quickbooks/service/service_crud.rb +1 -15
  54. data/lib/quickbooks/service/tax_code.rb +0 -4
  55. data/lib/quickbooks/service/tax_rate.rb +0 -4
  56. data/lib/quickbooks/service/term.rb +0 -4
  57. data/lib/quickbooks/service/time_activity.rb +0 -4
  58. data/lib/quickbooks/service/vendor.rb +0 -4
  59. data/lib/quickbooks/service/vendor_credit.rb +2 -4
  60. data/lib/quickbooks/util/logging.rb +10 -0
  61. data/lib/quickbooks/util/name_entity.rb +2 -1
  62. data/lib/quickbooks/version.rb +1 -1
  63. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff4b1233ad85484b5c75b299803783ce7db38148
4
- data.tar.gz: d280d02ad5ad234a969568ba7184412a5dc71b00
3
+ metadata.gz: 8d86d02f5ca0f37bb54251f62fad6ac5f2e6c3ba
4
+ data.tar.gz: 90261ad5a8722a50537537a8bb22d6e63056a9db
5
5
  SHA512:
6
- metadata.gz: b3859a045fa2ceed5ef713f7377a9c707738dd3e6430d804a46e12e6a8371eefb14cfb89c6cdb69d6624c93f4f382cdd6078ffb62bbfa2fcbff6a8afbb724550
7
- data.tar.gz: 3ce96e27454142e80ab5b7debe74d7da070f5f29794c3d8a53d31a82f5a7c00e8823c50651444bb724c7f9ad2bb7c1a5df0755950b3e27f2fb75b9d63042503f
6
+ metadata.gz: 7af4121f20483c55b7ff788c10766c511980cf7aa12fde117257b571955c4a60d672062e736e196e061e476debac0f654d0eab4e5112631dd78ea0d4929ebcad
7
+ data.tar.gz: 2cba0c3f044de53f4f85678f4a9fa24e489c4f662e2533b01fde4d92172e226c7a95813db1e2dcfd3f0c4a409767af96a6f8924fd3792b9aca525a0b9c3f124e
@@ -15,11 +15,14 @@ require 'quickbooks/util/query_builder'
15
15
  #== Models
16
16
  require 'quickbooks/model/base_model'
17
17
  require 'quickbooks/model/base_reference'
18
+ require 'quickbooks/model/document_numbering'
18
19
  require 'quickbooks/model/access_token_response'
19
20
  require 'quickbooks/model/meta_data'
21
+ require 'quickbooks/model/class'
20
22
  require 'quickbooks/model/custom_field'
21
23
  require 'quickbooks/model/sales_item_line_detail'
22
24
  require 'quickbooks/model/sub_total_line_detail'
25
+ require 'quickbooks/model/department'
23
26
  require 'quickbooks/model/discount_line_detail'
24
27
  require 'quickbooks/model/discount_override'
25
28
  require 'quickbooks/model/payment_line_detail'
@@ -76,8 +79,10 @@ require 'quickbooks/model/batch_response'
76
79
  require 'quickbooks/service/service_crud'
77
80
  require 'quickbooks/service/base_service'
78
81
  require 'quickbooks/service/access_token'
82
+ require 'quickbooks/service/class'
79
83
  require 'quickbooks/service/company_info'
80
84
  require 'quickbooks/service/customer'
85
+ require 'quickbooks/service/department'
81
86
  require 'quickbooks/service/invoice'
82
87
  require 'quickbooks/service/item'
83
88
  require 'quickbooks/service/sales_receipt'
@@ -112,13 +117,18 @@ module Quickbooks
112
117
  end
113
118
 
114
119
  # set logging on or off
115
- attr_writer :log
120
+ attr_writer :log, :log_xml_pretty_print
116
121
 
117
122
  # Returns whether to log. Defaults to 'false'.
118
123
  def log?
119
124
  @log ||= false
120
125
  end
121
126
 
127
+ # pretty printing the xml in the logs is "on" by default
128
+ def log_xml_pretty_print?
129
+ defined?(@log_xml_pretty_print) ? @log_xml_pretty_print : true
130
+ end
131
+
122
132
  def log(msg)
123
133
  if log?
124
134
  logger.info(msg)
@@ -134,7 +144,7 @@ module Quickbooks
134
144
  class ServiceUnavailable < StandardError; end
135
145
 
136
146
  class IntuitRequestException < StandardError
137
- attr_accessor :message, :code, :detail, :type
147
+ attr_accessor :message, :code, :detail, :type, :request_xml
138
148
  def initialize(msg)
139
149
  self.message = msg
140
150
  super(msg)
@@ -34,9 +34,9 @@ module Quickbooks
34
34
  xml_accessor :acct_num, :from => 'AcctNum'
35
35
  xml_accessor :bank_num, :from => 'BankNum'
36
36
 
37
- xml_accessor :current_balance, :from => 'CurrentBalance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
38
- xml_accessor :current_balance_with_sub_accounts, :from => 'CurrentBalanceWithSubAccounts', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
39
- xml_accessor :opening_balance, :from => 'OpeningBalance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
37
+ xml_accessor :current_balance, :from => 'CurrentBalance', :as => BigDecimal, :to_xml => to_xml_big_decimal
38
+ xml_accessor :current_balance_with_sub_accounts, :from => 'CurrentBalanceWithSubAccounts', :as => BigDecimal, :to_xml => to_xml_big_decimal
39
+ xml_accessor :opening_balance, :from => 'OpeningBalance', :as => BigDecimal, :to_xml => to_xml_big_decimal
40
40
  xml_accessor :opening_balance_date, :from => 'OpeningBalanceDate', :as => DateTime
41
41
  xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
42
42
  xml_accessor :tax_account?, :from => 'TaxAccount'
@@ -5,11 +5,11 @@ module Quickbooks
5
5
  xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
6
6
  xml_accessor :account_ref, :from => 'AccountRef', :as => BaseReference
7
7
  xml_accessor :billable_status, :from => 'BillableStatus'
8
- xml_accessor :tax_amount, :from => 'UnitPrice', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
8
+ xml_accessor :tax_amount, :from => 'UnitPrice', :as => BigDecimal, :to_xml => to_xml_big_decimal
9
9
  xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
10
10
 
11
11
  reference_setters :customer_ref, :class_ref, :account_ref, :tax_code_ref
12
12
 
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -41,9 +41,13 @@ module Quickbooks
41
41
  HashWithIndifferentAccess[attributes]
42
42
  end
43
43
 
44
+ def ensure_line_items_initialization
45
+ self.line_items ||= []
46
+ end
47
+
44
48
  class << self
45
49
  def to_xml_big_decimal
46
- Proc.new { |val| val.to_f unless val.nil? }
50
+ Proc.new { |val| val.nil? ? nil : val.to_f }
47
51
  end
48
52
 
49
53
  def attribute_names
@@ -10,6 +10,7 @@ module Quickbooks
10
10
  xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
11
11
  xml_accessor :doc_number, :from => 'DocNumber'
12
12
  xml_accessor :txn_date, :from => 'TxnDate', :as => Date
13
+ xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
13
14
 
14
15
  xml_accessor :line_items, :from => 'Line', :as => [BillLineItem]
15
16
 
@@ -30,7 +31,7 @@ module Quickbooks
30
31
 
31
32
  validates_length_of :line_items, :minimum => 1
32
33
 
33
- reference_setters :vendor_ref, :payer_ref, :sales_term_ref
34
+ reference_setters :department_ref, :vendor_ref, :payer_ref, :sales_term_ref
34
35
  end
35
36
  end
36
37
  end
@@ -8,7 +8,7 @@ module Quickbooks
8
8
  xml_accessor :id, :from => 'Id', :as => Integer
9
9
  xml_accessor :line_num, :from => 'LineNum', :as => Integer
10
10
  xml_accessor :description, :from => 'Description'
11
- xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
11
+ xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
12
12
  xml_accessor :detail_type, :from => 'DetailType'
13
13
 
14
14
  #== Various detail types
@@ -20,4 +20,4 @@ module Quickbooks
20
20
 
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -23,7 +23,6 @@ module Quickbooks
23
23
  ## Required if PayType is CreditCard.
24
24
  xml_accessor :credit_card_payment, :from => 'CreditCardPayment', :as => BillPaymentCreditCard
25
25
 
26
- # readonly
27
26
  xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal
28
27
 
29
28
  validates_length_of :line_items, :minimum => 1
@@ -9,7 +9,7 @@ module Quickbooks
9
9
  xml_accessor :id, :from => 'Id', :as => Integer
10
10
  xml_accessor :line_num, :from => 'LineNum', :as => Integer
11
11
  xml_accessor :description, :from => 'Description'
12
- xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
12
+ xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
13
13
  xml_accessor :detail_type, :from => 'DetailType'
14
14
 
15
15
  xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
@@ -18,4 +18,4 @@ module Quickbooks
18
18
 
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -0,0 +1,31 @@
1
+ module Quickbooks
2
+ module Model
3
+ class Class < BaseModel
4
+ XML_COLLECTION_NODE = "Class"
5
+ XML_NODE = "Class"
6
+ REST_RESOURCE = 'class'
7
+ include NameEntity::Quality
8
+ include NameEntity::PermitAlterations
9
+
10
+ xml_name XML_NODE
11
+ xml_accessor :id, :from => 'Id', :as => Integer
12
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
13
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
14
+ xml_accessor :name, :from => 'Name'
15
+ xml_accessor :sub_class, :from => 'SubClass'
16
+ xml_accessor :parent_ref, :from => 'ParentRef', :as => BaseReference
17
+ xml_accessor :fully_qualified_name, :from => 'FullyQualifiedName' # ReadOnly
18
+ xml_accessor :active?, :from => 'Active'
19
+
20
+ reference_setters :parent_ref
21
+
22
+ #== Validations
23
+ validate :names_cannot_contain_invalid_characters
24
+
25
+ def sub_class?
26
+ sub_class.to_s == 'true'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -9,7 +9,9 @@ module Quickbooks
9
9
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
10
10
  xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
11
11
  xml_accessor :doc_number, :from => 'DocNumber'
12
- xml_accessor :placed_on, :from => 'TxnDate', :as => Time
12
+ #xml_accessor :txn_date, :from => 'TxnDate', :as => Date
13
+ # TODO: Next major version 'placed_on' should be replaced by 'txn_date'
14
+ xml_accessor :placed_on, :from => 'TxnDate', :as => Date
13
15
 
14
16
  xml_accessor :line_items, :from => 'Line', :as => [Line]
15
17
 
@@ -30,6 +32,11 @@ module Quickbooks
30
32
 
31
33
  reference_setters :customer_ref, :sales_term_ref, :deposit_to_account_ref, :payment_method_ref
32
34
 
35
+ def initialize(*args)
36
+ ensure_line_items_initialization
37
+ super
38
+ end
39
+
33
40
  def email=(email)
34
41
  self.bill_email = EmailAddress.new(email)
35
42
  end
@@ -42,9 +42,9 @@ module Quickbooks
42
42
  xml_accessor :level, :from => 'Level'
43
43
  xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
44
44
  xml_accessor :payment_method_ref, :from => 'PaymentMethodRef', :as => BaseReference
45
- xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
45
+ xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => to_xml_big_decimal
46
46
  xml_accessor :open_balance_date, :from => 'OpenBalanceDate', :as => Date
47
- xml_accessor :balance_with_jobs, :from => 'BalanceWithJobs', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
47
+ xml_accessor :balance_with_jobs, :from => 'BalanceWithJobs', :as => BigDecimal, :to_xml => to_xml_big_decimal
48
48
  xml_accessor :preferred_delivery_method, :from => 'PreferredDeliveryMethod'
49
49
  xml_accessor :resale_num, :from => 'ResaleNum'
50
50
  xml_accessor :suffix, :from => 'Suffix'
@@ -0,0 +1,31 @@
1
+ module Quickbooks
2
+ module Model
3
+ class Department < BaseModel
4
+ XML_COLLECTION_NODE = "Department"
5
+ XML_NODE = "Department"
6
+ REST_RESOURCE = 'department'
7
+ include NameEntity::Quality
8
+ include NameEntity::PermitAlterations
9
+
10
+ xml_name XML_NODE
11
+ xml_accessor :id, :from => 'Id', :as => Integer
12
+ xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
13
+ xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
14
+ xml_accessor :name, :from => 'Name'
15
+ xml_accessor :sub_department, :from => 'SubDepartment'
16
+ xml_accessor :parent_ref, :from => 'ParentRef', :as => BaseReference
17
+ xml_accessor :fully_qualified_name, :from => 'FullyQualifiedName' # ReadOnly
18
+ xml_accessor :active?, :from => 'Active'
19
+
20
+ reference_setters :parent_ref
21
+
22
+ #== Validations
23
+ validate :names_cannot_contain_invalid_characters
24
+
25
+ def sub_department?
26
+ sub_department.to_s == 'true'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -4,7 +4,7 @@ module Quickbooks
4
4
  class DiscountLineDetail < BaseModel
5
5
  xml_accessor :discount_ref, :from => 'DiscountRef', :as => BaseReference
6
6
  xml_accessor :percent_based?, :from => 'PercentBased'
7
- xml_accessor :discount_percent, :from => 'DiscountPercent', :as => BigDecimal, :to_xml => Proc.new { |val| val && val.to_f }
7
+ xml_accessor :discount_percent, :from => 'DiscountPercent', :as => BigDecimal, :to_xml => to_xml_big_decimal
8
8
  xml_accessor :discount_account_ref, :from => 'DiscountAccountRef', :as => BaseReference
9
9
  xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
10
10
  xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
@@ -12,4 +12,4 @@ module Quickbooks
12
12
  reference_setters :tax_code_ref, :class_ref, :discount_ref, :discount_account_ref
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -3,7 +3,7 @@ module Quickbooks
3
3
  class DiscountOverride < BaseModel
4
4
  xml_accessor :discount_ref, :from => 'DiscountRef', :as => BaseReference
5
5
  xml_accessor :percent_based?, :from => 'PercentBased'
6
- xml_accessor :discount_percent, :from => 'DiscountPercent', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
6
+ xml_accessor :discount_percent, :from => 'DiscountPercent', :as => BigDecimal, :to_xml => to_xml_big_decimal
7
7
  xml_accessor :discount_account_ref, :from => 'DiscountAccountRef', :as => BaseReference
8
8
 
9
9
  reference_setters :discount_ref, :discount_account_ref
@@ -0,0 +1,18 @@
1
+ module DocumentNumbering
2
+
3
+ # Convenience method for proper AutoDocNumber tag
4
+ # construction, which should be blank if auto
5
+ # document numbering is desired.
6
+ def auto_doc_number!
7
+ self.auto_doc_number = ''
8
+ end
9
+
10
+ private
11
+
12
+ def document_numbering
13
+ if !auto_doc_number.nil? && !doc_number.nil?
14
+ errors.add(:doc_number, "DocumentNumber should not be specified if AutoDocNumber is.")
15
+ end
16
+ end
17
+
18
+ end
@@ -31,7 +31,7 @@ module Quickbooks
31
31
  xml_accessor :ssn, :from => 'SSN'
32
32
  xml_accessor :address, :from => 'PrimaryAddr', :as => PhysicalAddress
33
33
  xml_accessor :billable?, :from => 'BillableTime'
34
- xml_accessor :billable_rate, :from => 'BillRate', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
34
+ xml_accessor :billable_rate, :from => 'BillRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
35
35
  xml_accessor :birth_date, :from => 'BirthDate', :as => Date
36
36
  xml_accessor :gender, :from => 'Gender'
37
37
  xml_accessor :hired_date, :from => 'HiredDate', :as => Date
@@ -21,7 +21,7 @@ module Quickbooks
21
21
  xml_accessor :doc_number, :from => 'DocNumber'
22
22
  xml_accessor :txn_date, :from => 'TxnDate', :as => Date
23
23
  xml_accessor :private_note, :from => 'PrivateNote'
24
-
24
+
25
25
  xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
26
26
  xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
27
27
  xml_accessor :line_items, :from => 'Line', :as => [InvoiceLineItem]
@@ -34,10 +34,10 @@ module Quickbooks
34
34
  xml_accessor :shipping_address, :from => 'ShipAddr', :as => PhysicalAddress
35
35
  xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
36
36
  xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
37
- xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
37
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
38
38
  xml_accessor :ship_method_ref, :from => 'ShipMethodRef', :as => BaseReference
39
39
  xml_accessor :ship_date, :from => 'ShipDate', :as => Date
40
-
40
+
41
41
  xml_accessor :apply_tax_after_discount?, :from => 'ApplyTaxAfterDiscount'
42
42
  xml_accessor :print_status, :from => 'PrintStatus'
43
43
  xml_accessor :email_status, :from => 'EmailStatus'
@@ -65,9 +65,6 @@ module Quickbooks
65
65
  end
66
66
  end
67
67
 
68
- def ensure_line_items_initialization
69
- self.line_items ||= []
70
- end
71
68
  end
72
69
  end
73
70
  end
@@ -2,10 +2,10 @@ module Quickbooks
2
2
  module Model
3
3
  class GroupLineDetail < BaseModel
4
4
  xml_accessor :group_item_ref, :from => 'CustomerRef', :as => BaseReference
5
- xml_accessor :quantity, :from => 'Quantity', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
5
+ xml_accessor :quantity, :from => 'Quantity', :as => BigDecimal, :to_xml => to_xml_big_decimal
6
6
  xml_accessor :line_items, :from => 'Line', :as => [Line]
7
7
 
8
8
  reference_setters :group_item_ref
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -19,8 +19,10 @@ module Quickbooks
19
19
  xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
20
20
  xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
21
21
  xml_accessor :custom_fields, :from => 'CustomField', :as => [CustomField]
22
+ xml_accessor :auto_doc_number, :from => 'AutoDocNumber' # See auto_doc_number! method below for usage
22
23
  xml_accessor :doc_number, :from => 'DocNumber'
23
24
  xml_accessor :txn_date, :from => 'TxnDate', :as => Date
25
+ xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
24
26
  xml_accessor :private_note, :from => 'PrivateNote'
25
27
  xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
26
28
  xml_accessor :line_items, :from => 'Line', :as => [InvoiceLineItem]
@@ -36,12 +38,12 @@ module Quickbooks
36
38
  xml_accessor :ship_date, :from => 'ShipDate', :as => Date
37
39
  xml_accessor :tracking_num, :from => 'TrackingNum'
38
40
  xml_accessor :ar_account_ref, :from => 'ARAccountRef', :as => BaseReference
39
- xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
41
+ xml_accessor :total_amount, :from => 'TotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
40
42
  xml_accessor :apply_tax_after_discount?, :from => 'ApplyTaxAfterDiscount'
41
43
  xml_accessor :print_status, :from => 'PrintStatus'
42
44
  xml_accessor :email_status, :from => 'EmailStatus'
43
- xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
44
- xml_accessor :deposit, :from => 'Deposit', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
45
+ xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => to_xml_big_decimal
46
+ xml_accessor :deposit, :from => 'Deposit', :as => BigDecimal, :to_xml => to_xml_big_decimal
45
47
  xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
46
48
  xml_accessor :allow_ipn_payment?, :from => 'AllowIPNPayment'
47
49
  xml_accessor :bill_email, :from => 'BillEmail', :as => EmailAddress
@@ -49,13 +51,15 @@ module Quickbooks
49
51
  xml_accessor :allow_online_credit_card_payment?, :from => 'AllowOnlineCreditCardPayment'
50
52
  xml_accessor :allow_online_ach_payment?, :from => 'AllowOnlineACHPayment'
51
53
 
54
+ include DocumentNumbering
52
55
  reference_setters :customer_ref, :class_ref, :sales_term_ref, :ship_method_ref
53
- reference_setters :ar_account_ref, :department_ref, :ar_account_ref
56
+ reference_setters :ar_account_ref, :department_ref, :ar_account_ref, :currency_ref
54
57
 
55
58
  #== Validations
56
59
  validates_length_of :line_items, :minimum => 1
57
60
  validate :existence_of_customer_ref
58
61
  validate :required_bill_email_if_email_delivery
62
+ validate :document_numbering
59
63
 
60
64
  def initialize(*args)
61
65
  ensure_line_items_initialization
@@ -74,6 +78,7 @@ module Quickbooks
74
78
  self.bill_email = EmailAddress.new(email_address_string)
75
79
  end
76
80
 
81
+
77
82
  def wants_billing_email_sent!
78
83
  self.email_status = EMAIL_STATUS_NEED_TO_SEND
79
84
  end
@@ -82,7 +87,6 @@ module Quickbooks
82
87
  email_status == EMAIL_STATUS_NEED_TO_SEND
83
88
  end
84
89
 
85
- private
86
90
 
87
91
  def existence_of_customer_ref
88
92
  if customer_ref.nil? || (customer_ref && customer_ref.value == 0)
@@ -90,9 +94,6 @@ module Quickbooks
90
94
  end
91
95
  end
92
96
 
93
- def ensure_line_items_initialization
94
- self.line_items ||= []
95
- end
96
97
  end
97
98
  end
98
99
  end
@@ -11,7 +11,7 @@ module Quickbooks
11
11
  xml_accessor :id, :from => 'Id', :as => Integer
12
12
  xml_accessor :line_num, :from => 'LineNum', :as => Integer
13
13
  xml_accessor :description, :from => 'Description'
14
- xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
14
+ xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
15
15
  xml_accessor :detail_type, :from => 'DetailType'
16
16
 
17
17
  #== Various detail types
@@ -55,4 +55,4 @@ module Quickbooks
55
55
 
56
56
  end
57
57
  end
58
- end
58
+ end