ledger_sync-quickbooks_online 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.env.test +9 -0
  4. data/.gitignore +21 -0
  5. data/.overcommit.yml +29 -0
  6. data/.rubocop.yml +78 -0
  7. data/.rubocop_todo.yml +25 -0
  8. data/.travis.yml +25 -0
  9. data/Gemfile +8 -0
  10. data/Gemfile.lock +211 -0
  11. data/README.md +19 -0
  12. data/Rakefile +8 -0
  13. data/bin/console +15 -0
  14. data/bin/quickbooks_online_oauth_server.rb +104 -0
  15. data/bin/setup +8 -0
  16. data/ledger_sync-quickbooks_online.gemspec +46 -0
  17. data/lib/ledger_sync/quickbooks_online.rb +14 -0
  18. data/lib/ledger_sync/quickbooks_online/account/deserializer.rb +29 -0
  19. data/lib/ledger_sync/quickbooks_online/account/operations/create.rb +26 -0
  20. data/lib/ledger_sync/quickbooks_online/account/operations/find.rb +26 -0
  21. data/lib/ledger_sync/quickbooks_online/account/operations/update.rb +28 -0
  22. data/lib/ledger_sync/quickbooks_online/account/searcher.rb +13 -0
  23. data/lib/ledger_sync/quickbooks_online/account/serializer.rb +29 -0
  24. data/lib/ledger_sync/quickbooks_online/account_based_expense_line_detail/deserializer.rb +19 -0
  25. data/lib/ledger_sync/quickbooks_online/account_based_expense_line_detail/serializer.rb +19 -0
  26. data/lib/ledger_sync/quickbooks_online/bill/deserializer.rb +39 -0
  27. data/lib/ledger_sync/quickbooks_online/bill/operations/create.rb +27 -0
  28. data/lib/ledger_sync/quickbooks_online/bill/operations/find.rb +27 -0
  29. data/lib/ledger_sync/quickbooks_online/bill/operations/update.rb +27 -0
  30. data/lib/ledger_sync/quickbooks_online/bill/searcher.rb +12 -0
  31. data/lib/ledger_sync/quickbooks_online/bill/serializer.rb +39 -0
  32. data/lib/ledger_sync/quickbooks_online/bill_line/deserializer.rb +20 -0
  33. data/lib/ledger_sync/quickbooks_online/bill_line/serializer.rb +24 -0
  34. data/lib/ledger_sync/quickbooks_online/bill_payment/deserializer.rb +53 -0
  35. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/create.rb +31 -0
  36. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/find.rb +31 -0
  37. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/update.rb +31 -0
  38. data/lib/ledger_sync/quickbooks_online/bill_payment/serializer.rb +53 -0
  39. data/lib/ledger_sync/quickbooks_online/bill_payment_line/deserializer.rb +14 -0
  40. data/lib/ledger_sync/quickbooks_online/bill_payment_line/serializer.rb +14 -0
  41. data/lib/ledger_sync/quickbooks_online/check_payment/deserializer.rb +15 -0
  42. data/lib/ledger_sync/quickbooks_online/check_payment/serializer.rb +15 -0
  43. data/lib/ledger_sync/quickbooks_online/client.rb +235 -0
  44. data/lib/ledger_sync/quickbooks_online/config.rb +15 -0
  45. data/lib/ledger_sync/quickbooks_online/credit_card_payment/deserializer.rb +15 -0
  46. data/lib/ledger_sync/quickbooks_online/credit_card_payment/serializer.rb +15 -0
  47. data/lib/ledger_sync/quickbooks_online/currency/deserializer.rb +14 -0
  48. data/lib/ledger_sync/quickbooks_online/currency/serializer.rb +15 -0
  49. data/lib/ledger_sync/quickbooks_online/customer/deserializer.rb +24 -0
  50. data/lib/ledger_sync/quickbooks_online/customer/operations/create.rb +24 -0
  51. data/lib/ledger_sync/quickbooks_online/customer/operations/find.rb +24 -0
  52. data/lib/ledger_sync/quickbooks_online/customer/operations/update.rb +24 -0
  53. data/lib/ledger_sync/quickbooks_online/customer/searcher.rb +13 -0
  54. data/lib/ledger_sync/quickbooks_online/customer/serializer.rb +24 -0
  55. data/lib/ledger_sync/quickbooks_online/dashboard_url_helper.rb +32 -0
  56. data/lib/ledger_sync/quickbooks_online/department/deserializer.rb +20 -0
  57. data/lib/ledger_sync/quickbooks_online/department/operations/create.rb +23 -0
  58. data/lib/ledger_sync/quickbooks_online/department/operations/find.rb +23 -0
  59. data/lib/ledger_sync/quickbooks_online/department/operations/update.rb +23 -0
  60. data/lib/ledger_sync/quickbooks_online/department/searcher.rb +15 -0
  61. data/lib/ledger_sync/quickbooks_online/department/serializer.rb +39 -0
  62. data/lib/ledger_sync/quickbooks_online/deposit/deserializer.rb +34 -0
  63. data/lib/ledger_sync/quickbooks_online/deposit/operations/create.rb +25 -0
  64. data/lib/ledger_sync/quickbooks_online/deposit/operations/find.rb +25 -0
  65. data/lib/ledger_sync/quickbooks_online/deposit/operations/update.rb +25 -0
  66. data/lib/ledger_sync/quickbooks_online/deposit/searcher.rb +12 -0
  67. data/lib/ledger_sync/quickbooks_online/deposit/serializer.rb +34 -0
  68. data/lib/ledger_sync/quickbooks_online/deposit_line/deserializer.rb +20 -0
  69. data/lib/ledger_sync/quickbooks_online/deposit_line/serializer.rb +24 -0
  70. data/lib/ledger_sync/quickbooks_online/deposit_line_detail/deserializer.rb +32 -0
  71. data/lib/ledger_sync/quickbooks_online/deposit_line_detail/serializer.rb +33 -0
  72. data/lib/ledger_sync/quickbooks_online/deserializer.rb +97 -0
  73. data/lib/ledger_sync/quickbooks_online/expense/deserializer.rb +52 -0
  74. data/lib/ledger_sync/quickbooks_online/expense/operations/create.rb +28 -0
  75. data/lib/ledger_sync/quickbooks_online/expense/operations/find.rb +28 -0
  76. data/lib/ledger_sync/quickbooks_online/expense/operations/update.rb +28 -0
  77. data/lib/ledger_sync/quickbooks_online/expense/searcher.rb +12 -0
  78. data/lib/ledger_sync/quickbooks_online/expense/serializer.rb +51 -0
  79. data/lib/ledger_sync/quickbooks_online/expense_line/deserializer.rb +20 -0
  80. data/lib/ledger_sync/quickbooks_online/expense_line/serializer.rb +24 -0
  81. data/lib/ledger_sync/quickbooks_online/invoice/deserializer.rb +33 -0
  82. data/lib/ledger_sync/quickbooks_online/invoice/operations/create.rb +25 -0
  83. data/lib/ledger_sync/quickbooks_online/invoice/operations/find.rb +25 -0
  84. data/lib/ledger_sync/quickbooks_online/invoice/operations/update.rb +25 -0
  85. data/lib/ledger_sync/quickbooks_online/invoice/serializer.rb +33 -0
  86. data/lib/ledger_sync/quickbooks_online/invoice_line/deserializer.rb +19 -0
  87. data/lib/ledger_sync/quickbooks_online/invoice_line/serializer.rb +23 -0
  88. data/lib/ledger_sync/quickbooks_online/item/deserializer.rb +11 -0
  89. data/lib/ledger_sync/quickbooks_online/item/serializer.rb +10 -0
  90. data/lib/ledger_sync/quickbooks_online/journal_entry/deserializer.rb +26 -0
  91. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/create.rb +23 -0
  92. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/find.rb +23 -0
  93. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/update.rb +23 -0
  94. data/lib/ledger_sync/quickbooks_online/journal_entry/searcher.rb +12 -0
  95. data/lib/ledger_sync/quickbooks_online/journal_entry/serializer.rb +26 -0
  96. data/lib/ledger_sync/quickbooks_online/journal_entry_line/deserializer.rb +18 -0
  97. data/lib/ledger_sync/quickbooks_online/journal_entry_line/serializer.rb +22 -0
  98. data/lib/ledger_sync/quickbooks_online/journal_entry_line_detail/deserializer.rb +27 -0
  99. data/lib/ledger_sync/quickbooks_online/journal_entry_line_detail/serializer.rb +27 -0
  100. data/lib/ledger_sync/quickbooks_online/ledger_class/deserializer.rb +22 -0
  101. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/create.rb +23 -0
  102. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/find.rb +23 -0
  103. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/update.rb +23 -0
  104. data/lib/ledger_sync/quickbooks_online/ledger_class/searcher.rb +13 -0
  105. data/lib/ledger_sync/quickbooks_online/ledger_class/serializer.rb +22 -0
  106. data/lib/ledger_sync/quickbooks_online/oauth_client.rb +91 -0
  107. data/lib/ledger_sync/quickbooks_online/operation.rb +59 -0
  108. data/lib/ledger_sync/quickbooks_online/operation/create.rb +24 -0
  109. data/lib/ledger_sync/quickbooks_online/operation/find.rb +23 -0
  110. data/lib/ledger_sync/quickbooks_online/operation/full_update.rb +40 -0
  111. data/lib/ledger_sync/quickbooks_online/operation/sparse_update.rb +27 -0
  112. data/lib/ledger_sync/quickbooks_online/payment/deserializer.rb +40 -0
  113. data/lib/ledger_sync/quickbooks_online/payment/operations/create.rb +28 -0
  114. data/lib/ledger_sync/quickbooks_online/payment/operations/find.rb +28 -0
  115. data/lib/ledger_sync/quickbooks_online/payment/operations/update.rb +28 -0
  116. data/lib/ledger_sync/quickbooks_online/payment/serializer.rb +40 -0
  117. data/lib/ledger_sync/quickbooks_online/payment_line/deserializer.rb +15 -0
  118. data/lib/ledger_sync/quickbooks_online/payment_line/serializer.rb +15 -0
  119. data/lib/ledger_sync/quickbooks_online/preferences/deserializer.rb +22 -0
  120. data/lib/ledger_sync/quickbooks_online/preferences/operations/find.rb +28 -0
  121. data/lib/ledger_sync/quickbooks_online/preferences/serializer.rb +22 -0
  122. data/lib/ledger_sync/quickbooks_online/primary_email_addr/deserializer.rb +11 -0
  123. data/lib/ledger_sync/quickbooks_online/primary_email_addr/serializer.rb +11 -0
  124. data/lib/ledger_sync/quickbooks_online/primary_phone/deserializer.rb +11 -0
  125. data/lib/ledger_sync/quickbooks_online/primary_phone/serializer.rb +11 -0
  126. data/lib/ledger_sync/quickbooks_online/reference/deserializer.rb +11 -0
  127. data/lib/ledger_sync/quickbooks_online/reference/serializer.rb +11 -0
  128. data/lib/ledger_sync/quickbooks_online/request.rb +96 -0
  129. data/lib/ledger_sync/quickbooks_online/resource.rb +8 -0
  130. data/lib/ledger_sync/quickbooks_online/resources/account.rb +357 -0
  131. data/lib/ledger_sync/quickbooks_online/resources/account_based_expense_line_detail.rb +17 -0
  132. data/lib/ledger_sync/quickbooks_online/resources/bill.rb +29 -0
  133. data/lib/ledger_sync/quickbooks_online/resources/bill_line.rb +17 -0
  134. data/lib/ledger_sync/quickbooks_online/resources/bill_payment.rb +42 -0
  135. data/lib/ledger_sync/quickbooks_online/resources/bill_payment_line.rb +17 -0
  136. data/lib/ledger_sync/quickbooks_online/resources/check_payment.rb +11 -0
  137. data/lib/ledger_sync/quickbooks_online/resources/credit_card_payment.rb +11 -0
  138. data/lib/ledger_sync/quickbooks_online/resources/currency.rb +15 -0
  139. data/lib/ledger_sync/quickbooks_online/resources/customer.rb +22 -0
  140. data/lib/ledger_sync/quickbooks_online/resources/department.rb +20 -0
  141. data/lib/ledger_sync/quickbooks_online/resources/deposit.rb +26 -0
  142. data/lib/ledger_sync/quickbooks_online/resources/deposit_line.rb +17 -0
  143. data/lib/ledger_sync/quickbooks_online/resources/deposit_line_detail.rb +20 -0
  144. data/lib/ledger_sync/quickbooks_online/resources/expense.rb +38 -0
  145. data/lib/ledger_sync/quickbooks_online/resources/expense_line.rb +17 -0
  146. data/lib/ledger_sync/quickbooks_online/resources/invoice.rb +26 -0
  147. data/lib/ledger_sync/quickbooks_online/resources/invoice_line.rb +17 -0
  148. data/lib/ledger_sync/quickbooks_online/resources/item.rb +9 -0
  149. data/lib/ledger_sync/quickbooks_online/resources/journal_entry.rb +22 -0
  150. data/lib/ledger_sync/quickbooks_online/resources/journal_entry_line.rb +18 -0
  151. data/lib/ledger_sync/quickbooks_online/resources/journal_entry_line_detail.rb +25 -0
  152. data/lib/ledger_sync/quickbooks_online/resources/ledger_class.rb +18 -0
  153. data/lib/ledger_sync/quickbooks_online/resources/payment.rb +29 -0
  154. data/lib/ledger_sync/quickbooks_online/resources/payment_line.rb +17 -0
  155. data/lib/ledger_sync/quickbooks_online/resources/preferences.rb +22 -0
  156. data/lib/ledger_sync/quickbooks_online/resources/primary_email_addr.rb +9 -0
  157. data/lib/ledger_sync/quickbooks_online/resources/primary_phone.rb +9 -0
  158. data/lib/ledger_sync/quickbooks_online/resources/sales_item_line_detail.rb +17 -0
  159. data/lib/ledger_sync/quickbooks_online/resources/transfer.rb +22 -0
  160. data/lib/ledger_sync/quickbooks_online/resources/vendor.rb +23 -0
  161. data/lib/ledger_sync/quickbooks_online/sales_item_line_detail/deserializer.rb +19 -0
  162. data/lib/ledger_sync/quickbooks_online/sales_item_line_detail/serializer.rb +19 -0
  163. data/lib/ledger_sync/quickbooks_online/searcher.rb +58 -0
  164. data/lib/ledger_sync/quickbooks_online/serialization/type/amount_float_to_integer_type.rb +19 -0
  165. data/lib/ledger_sync/quickbooks_online/serialization/type/deserialize_transaction_reference_type.rb +28 -0
  166. data/lib/ledger_sync/quickbooks_online/serialization/type/integer_to_amount_float_type.rb +19 -0
  167. data/lib/ledger_sync/quickbooks_online/serialization/type/serialize_transaction_reference_type.rb +28 -0
  168. data/lib/ledger_sync/quickbooks_online/serializer.rb +69 -0
  169. data/lib/ledger_sync/quickbooks_online/serialziation/type/mapping_type.rb +27 -0
  170. data/lib/ledger_sync/quickbooks_online/transfer/deserializer.rb +29 -0
  171. data/lib/ledger_sync/quickbooks_online/transfer/operations/create.rb +24 -0
  172. data/lib/ledger_sync/quickbooks_online/transfer/operations/find.rb +24 -0
  173. data/lib/ledger_sync/quickbooks_online/transfer/operations/update.rb +24 -0
  174. data/lib/ledger_sync/quickbooks_online/transfer/serializer.rb +29 -0
  175. data/lib/ledger_sync/quickbooks_online/util/error_matcher.rb +68 -0
  176. data/lib/ledger_sync/quickbooks_online/util/error_parser.rb +25 -0
  177. data/lib/ledger_sync/quickbooks_online/util/ledger_error_parser.rb +101 -0
  178. data/lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb +97 -0
  179. data/lib/ledger_sync/quickbooks_online/vendor/deserializer.rb +25 -0
  180. data/lib/ledger_sync/quickbooks_online/vendor/operations/create.rb +25 -0
  181. data/lib/ledger_sync/quickbooks_online/vendor/operations/find.rb +25 -0
  182. data/lib/ledger_sync/quickbooks_online/vendor/operations/update.rb +25 -0
  183. data/lib/ledger_sync/quickbooks_online/vendor/searcher.rb +13 -0
  184. data/lib/ledger_sync/quickbooks_online/vendor/serializer.rb +25 -0
  185. data/lib/ledger_sync/quickbooks_online/version.rb +19 -0
  186. data/lib/ledger_sync/quickbooks_online/webhook.rb +56 -0
  187. data/lib/ledger_sync/quickbooks_online/webhook_event.rb +79 -0
  188. data/lib/ledger_sync/quickbooks_online/webhook_notification.rb +41 -0
  189. data/license.txt +4 -0
  190. metadata +456 -0
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'department'
5
+ require_relative 'ledger_class'
6
+
7
+ module LedgerSync
8
+ module QuickBooksOnline
9
+ class JournalEntryLineDetail < QuickBooksOnline::Resource
10
+ TYPES = {
11
+ 'debit' => 'Debit',
12
+ 'credit' => 'Credit'
13
+ }.freeze
14
+
15
+ references_one :Account, to: Account
16
+ references_one :Department, to: Department
17
+ references_one :Class, to: LedgerClass
18
+ attribute :PostingType, type: Type::StringFromSet.new(values: TYPES.keys)
19
+
20
+ def name
21
+ "#{self.PostingType} #{self.Account.try(:name)}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class LedgerClass < QuickBooksOnline::Resource
6
+ attribute :Name, type: Type::String
7
+ attribute :FullyQualifiedName, type: Type::String
8
+ attribute :Active, type: Type::Boolean
9
+ attribute :SubClass, type: Type::Boolean
10
+
11
+ references_one :Parent, to: LedgerClass
12
+
13
+ def name
14
+ self.Name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'currency'
5
+ require_relative 'customer'
6
+ require_relative 'payment_line'
7
+
8
+ module LedgerSync
9
+ module QuickBooksOnline
10
+ class Payment < QuickBooksOnline::Resource
11
+ attribute :TotalAmt, type: Type::Integer
12
+ attribute :PrivateNote, type: Type::String
13
+ attribute :TxnDate, type: Type::Date
14
+ attribute :ExchangeRate, type: Type::Float
15
+ attribute :PaymentRefNum, type: Type::String
16
+
17
+ references_one :Customer, to: Customer
18
+ references_one :DepositToAccount, to: Account
19
+ references_one :ARAccount, to: Account
20
+ references_one :Currency, to: Currency
21
+
22
+ references_many :Line, to: PaymentLine
23
+
24
+ def name
25
+ "Payment: #{self.TotalAmt} #{self.Currency}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'invoice'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class PaymentLine < QuickBooksOnline::Resource
8
+ attribute :Amount, type: Type::Integer
9
+
10
+ references_many :LinkedTxn, to: [Invoice]
11
+
12
+ def name
13
+ self.Amount
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Preferences < QuickBooksOnline::Resource
6
+ attribute :AccountingInfoPrefs, type: Type::Hash
7
+ attribute :ProductAndServicesPrefs, type: Type::Hash
8
+ attribute :SalesFormsPrefs, type: Type::Hash
9
+ attribute :EmailMessagesPrefs, type: Type::Hash
10
+ attribute :VendorAndPurchasesPrefs, type: Type::Hash
11
+ attribute :TimeTrackingPrefs, type: Type::Hash
12
+ attribute :TaxPrefs, type: Type::Hash
13
+ attribute :CurrencyPrefs, type: Type::Hash
14
+ attribute :ReportPrefs, type: Type::Hash
15
+ attribute :OtherPrefs, type: Type::Hash
16
+
17
+ def name
18
+ 'Preference'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class PrimaryEmailAddr < QuickBooksOnline::Resource
6
+ attribute :Address, type: LedgerSync::Type::String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class PrimaryPhone < QuickBooksOnline::Resource
6
+ attribute :FreeFormNumber, type: LedgerSync::Type::String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'item'
4
+ require_relative 'ledger_class'
5
+
6
+ module LedgerSync
7
+ module QuickBooksOnline
8
+ class SalesItemLineDetail < QuickBooksOnline::Resource
9
+ references_one :Item, to: Item
10
+ references_one :Class, to: LedgerClass
11
+
12
+ def name
13
+ "#{self.Item.try(:name)} #{self.Class.try(:name)}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'currency'
5
+
6
+ module LedgerSync
7
+ module QuickBooksOnline
8
+ class Transfer < QuickBooksOnline::Resource
9
+ attribute :Amount, type: Type::Integer
10
+ attribute :PrivateNote, type: Type::String
11
+ attribute :TxnDate, type: Type::Date
12
+
13
+ references_one :FromAccount, to: Account
14
+ references_one :ToAccount, to: Account
15
+ references_one :Currency, to: Currency
16
+
17
+ def name
18
+ "Transfer: #{self.Amount} #{self.Currency}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'primary_phone'
4
+ require_relative 'primary_email_addr'
5
+
6
+ module LedgerSync
7
+ module QuickBooksOnline
8
+ class Vendor < QuickBooksOnline::Resource
9
+ attribute :DisplayName, type: Type::String
10
+ attribute :GivenName, type: Type::String
11
+ attribute :MiddleName, type: Type::String
12
+ attribute :FamilyName, type: Type::String
13
+ attribute :CompanyName, type: Type::String
14
+
15
+ references_one :PrimaryPhone, to: PrimaryPhone
16
+ references_one :PrimaryEmailAddr, to: PrimaryEmailAddr
17
+
18
+ def name
19
+ self.DisplayName
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reference/deserializer'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class SalesItemLineDetail
8
+ class Deserializer < QuickBooksOnline::Deserializer
9
+ references_one :Item,
10
+ hash_attribute: 'ItemRef',
11
+ deserializer: Reference::Deserializer
12
+
13
+ references_one :Class,
14
+ hash_attribute: 'ClassRef',
15
+ deserializer: Reference::Deserializer
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reference/serializer'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class SalesItemLineDetail
8
+ class Serializer < QuickBooksOnline::Serializer
9
+ references_one 'ItemRef',
10
+ resource_attribute: :Item,
11
+ serializer: Reference::Serializer
12
+
13
+ references_one 'ClassRef',
14
+ resource_attribute: :Class,
15
+ serializer: Reference::Serializer
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Searcher < Ledgers::Searcher
6
+ include LedgerSync::Ledgers::Mixins::OffsetAndLimitPaginationSearcherMixin
7
+
8
+ def query_string
9
+ ''
10
+ end
11
+
12
+ def resources
13
+ resource_class = self.class.inferred_resource_class
14
+
15
+ response = client.query(
16
+ limit: limit,
17
+ offset: offset,
18
+ query: query_string,
19
+ resource_class: resource_class
20
+ )
21
+ return [] if response.body.blank?
22
+
23
+ (response.body.dig(
24
+ 'QueryResponse',
25
+ client.class.ledger_resource_type_for(
26
+ resource_class: resource_class
27
+ ).classify
28
+ ) || []).map do |c|
29
+ self.class.inferred_deserializer_class.new.deserialize(
30
+ hash: c,
31
+ resource: resource_class.new
32
+ )
33
+ end
34
+ end
35
+
36
+ def search
37
+ super
38
+ rescue OAuth2::Error => e
39
+ @response = e # TODO: Better catch/raise errors as LedgerSync::Error
40
+ failure
41
+ end
42
+
43
+ private
44
+
45
+ # Pagination uses notation of limit and offset
46
+ # limit: number of results per page
47
+ #
48
+ # offset: position of first result in a list.
49
+ # starts from 1, not 0
50
+ #
51
+ # More here:
52
+ # https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/data-queries#pagination
53
+ def default_offset
54
+ 1
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ module Serialization
6
+ module Type
7
+ class AmountFloatToIntegerType < LedgerSync::Type::Value
8
+ def cast_value(args = {})
9
+ value = args.fetch(:value)
10
+
11
+ return if value.nil?
12
+
13
+ (value * 100).to_i
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ module Serialization
6
+ module Type
7
+ class DeserializeTransactionReferenceType < LedgerSync::Type::Value
8
+ def cast_value(value:)
9
+ return if value.nil?
10
+
11
+ raise "Unknown value type. Array expected. Given: #{value.class.name}" unless value.is_a?(Array)
12
+ return if value.empty?
13
+
14
+ value.map do |item|
15
+ resource_class = Client.resource_from_ledger_type(type: item['TxnType'])
16
+
17
+ raise "Unknown QuickBooks Online resource type: #{item['TxnType']}" if resource_class.blank?
18
+
19
+ resource_class.new(
20
+ ledger_id: item['TxnId']
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ module Serialization
6
+ module Type
7
+ class IntegerToAmountFloatType < LedgerSync::Type::Value
8
+ def cast_value(args = {})
9
+ value = args.fetch(:value)
10
+
11
+ return if value.nil?
12
+
13
+ value / 100.0
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ module Serialization
6
+ module Type
7
+ class SerializeTransactionReferenceType < LedgerSync::Type::Value
8
+ def cast_value(value:)
9
+ return if value.nil?
10
+ raise "List expected. Given: #{value.class.name}" unless value.is_a?(Array)
11
+ unless value.all?(LedgerSync::Resource)
12
+ raise "Resources expected. Given: #{value.map { |i| i.class.name }.join(', ')}"
13
+ end
14
+
15
+ value.map do |resource|
16
+ {
17
+ 'TxnId' => resource.ledger_id,
18
+ 'TxnType' => Client.ledger_resource_type_for(
19
+ resource_class: resource.class
20
+ ).classify
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Gem.find_files('ledger_sync/ledgers/quickbooks_online/serializer_type/**/*.rb').each { |path| require path }
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class Serializer < LedgerSync::Serializer
8
+ def serialize(args = {})
9
+ deep_merge_unmapped_values = args.fetch(:deep_merge_unmapped_values, {})
10
+ only_changes = args.fetch(:only_changes, false)
11
+ resource = args.fetch(:resource)
12
+
13
+ ret = super(
14
+ only_changes: only_changes,
15
+ resource: resource
16
+ )
17
+ return ret unless deep_merge_unmapped_values.any?
18
+
19
+ deep_merge_if_not_mapped(
20
+ current_hash: ret,
21
+ hash_to_search: deep_merge_unmapped_values
22
+ )
23
+ end
24
+
25
+ def self.amount(hash_attribute, args = {})
26
+ attribute(
27
+ hash_attribute,
28
+ {
29
+ type: Serialization::Type::IntegerToAmountFloatType.new
30
+ }.merge(args)
31
+ )
32
+ end
33
+
34
+ def self.date(hash_attribute, args = {})
35
+ attribute(
36
+ hash_attribute,
37
+ {
38
+ type: LedgerSync::Serialization::Type::FormatDateType.new(format: '%Y-%m-%d')
39
+ }.merge(args)
40
+ )
41
+ end
42
+
43
+ def self.id
44
+ attribute('Id', resource_attribute: :ledger_id)
45
+ end
46
+
47
+ private
48
+
49
+ def deep_merge_if_not_mapped(current_hash:, hash_to_search:)
50
+ hash_to_search.each do |key, value|
51
+ current_hash[key] = if current_hash.key?(key)
52
+ if value.is_a?(Hash) && current_hash[key].present?
53
+ deep_merge_if_not_mapped(
54
+ current_hash: current_hash[key],
55
+ hash_to_search: value
56
+ )
57
+ else
58
+ current_hash[key]
59
+ end
60
+ else
61
+ value
62
+ end
63
+ end
64
+
65
+ current_hash
66
+ end
67
+ end
68
+ end
69
+ end