ledger_sync-netsuite 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.test +14 -0
- data/.github/workflows/gem-workflow.yml +63 -0
- data/.gitignore +20 -0
- data/.overcommit.yml +29 -0
- data/.rubocop.yml +78 -0
- data/.rubocop_todo.yml +25 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +203 -0
- data/README.md +19 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ledger_sync-netsuite.gemspec +44 -0
- data/lib/ledger_sync/netsuite.rb +13 -0
- data/lib/ledger_sync/netsuite/account/deserializer.rb +21 -0
- data/lib/ledger_sync/netsuite/account/operations/create.rb +26 -0
- data/lib/ledger_sync/netsuite/account/operations/find.rb +26 -0
- data/lib/ledger_sync/netsuite/account/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/account/searcher_deserializer.rb +27 -0
- data/lib/ledger_sync/netsuite/account/serializer.rb +19 -0
- data/lib/ledger_sync/netsuite/check/deserializer.rb +27 -0
- data/lib/ledger_sync/netsuite/check/operations/create.rb +25 -0
- data/lib/ledger_sync/netsuite/check/operations/delete.rb +25 -0
- data/lib/ledger_sync/netsuite/check/operations/find.rb +25 -0
- data/lib/ledger_sync/netsuite/check/operations/update.rb +25 -0
- data/lib/ledger_sync/netsuite/check/searcher.rb +13 -0
- data/lib/ledger_sync/netsuite/check/searcher_deserializer.rb +14 -0
- data/lib/ledger_sync/netsuite/check/serializer.rb +49 -0
- data/lib/ledger_sync/netsuite/check_line_item/deserializer.rb +16 -0
- data/lib/ledger_sync/netsuite/check_line_item/serializer.rb +24 -0
- data/lib/ledger_sync/netsuite/client.rb +186 -0
- data/lib/ledger_sync/netsuite/config.rb +12 -0
- data/lib/ledger_sync/netsuite/currency/deserializer.rb +21 -0
- data/lib/ledger_sync/netsuite/currency/operations/create.rb +23 -0
- data/lib/ledger_sync/netsuite/currency/operations/delete.rb +21 -0
- data/lib/ledger_sync/netsuite/currency/operations/find.rb +25 -0
- data/lib/ledger_sync/netsuite/currency/operations/update.rb +21 -0
- data/lib/ledger_sync/netsuite/currency/serializer.rb +19 -0
- data/lib/ledger_sync/netsuite/customer/deserializer.rb +20 -0
- data/lib/ledger_sync/netsuite/customer/operations/create.rb +24 -0
- data/lib/ledger_sync/netsuite/customer/operations/delete.rb +24 -0
- data/lib/ledger_sync/netsuite/customer/operations/find.rb +24 -0
- data/lib/ledger_sync/netsuite/customer/operations/update.rb +24 -0
- data/lib/ledger_sync/netsuite/customer/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/customer/searcher_deserializer.rb +16 -0
- data/lib/ledger_sync/netsuite/customer/serializer.rb +27 -0
- data/lib/ledger_sync/netsuite/customer_deposit/deserializer.rb +18 -0
- data/lib/ledger_sync/netsuite/customer_deposit/operations/create.rb +22 -0
- data/lib/ledger_sync/netsuite/customer_deposit/operations/delete.rb +22 -0
- data/lib/ledger_sync/netsuite/customer_deposit/operations/find.rb +22 -0
- data/lib/ledger_sync/netsuite/customer_deposit/operations/update.rb +22 -0
- data/lib/ledger_sync/netsuite/customer_deposit/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/customer_deposit/searcher_deserializer.rb +14 -0
- data/lib/ledger_sync/netsuite/customer_deposit/serializer.rb +23 -0
- data/lib/ledger_sync/netsuite/dashboard_url_helper.rb +26 -0
- data/lib/ledger_sync/netsuite/department/deserializer.rb +13 -0
- data/lib/ledger_sync/netsuite/department/operations/create.rb +23 -0
- data/lib/ledger_sync/netsuite/department/operations/delete.rb +23 -0
- data/lib/ledger_sync/netsuite/department/operations/find.rb +23 -0
- data/lib/ledger_sync/netsuite/department/operations/update.rb +23 -0
- data/lib/ledger_sync/netsuite/department/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/department/searcher_deserializer.rb +17 -0
- data/lib/ledger_sync/netsuite/department/serializer.rb +11 -0
- data/lib/ledger_sync/netsuite/deserializer.rb +16 -0
- data/lib/ledger_sync/netsuite/error.rb +17 -0
- data/lib/ledger_sync/netsuite/journal_entry/deserializer.rb +29 -0
- data/lib/ledger_sync/netsuite/journal_entry/operations/create.rb +24 -0
- data/lib/ledger_sync/netsuite/journal_entry/operations/delete.rb +24 -0
- data/lib/ledger_sync/netsuite/journal_entry/operations/find.rb +24 -0
- data/lib/ledger_sync/netsuite/journal_entry/operations/update.rb +28 -0
- data/lib/ledger_sync/netsuite/journal_entry/serializer.rb +34 -0
- data/lib/ledger_sync/netsuite/journal_entry_line_item/deserializer.rb +18 -0
- data/lib/ledger_sync/netsuite/journal_entry_line_item/serializer.rb +18 -0
- data/lib/ledger_sync/netsuite/ledger_class/deserializer.rb +13 -0
- data/lib/ledger_sync/netsuite/ledger_class/operations/create.rb +23 -0
- data/lib/ledger_sync/netsuite/ledger_class/operations/delete.rb +23 -0
- data/lib/ledger_sync/netsuite/ledger_class/operations/find.rb +23 -0
- data/lib/ledger_sync/netsuite/ledger_class/operations/update.rb +23 -0
- data/lib/ledger_sync/netsuite/ledger_class/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/ledger_class/searcher_deserializer.rb +17 -0
- data/lib/ledger_sync/netsuite/ledger_class/serializer.rb +11 -0
- data/lib/ledger_sync/netsuite/location/deserializer.rb +13 -0
- data/lib/ledger_sync/netsuite/location/operations/create.rb +19 -0
- data/lib/ledger_sync/netsuite/location/operations/delete.rb +19 -0
- data/lib/ledger_sync/netsuite/location/operations/find.rb +19 -0
- data/lib/ledger_sync/netsuite/location/operations/update.rb +19 -0
- data/lib/ledger_sync/netsuite/location/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/location/serializer.rb +11 -0
- data/lib/ledger_sync/netsuite/operation.rb +38 -0
- data/lib/ledger_sync/netsuite/operation/create.rb +56 -0
- data/lib/ledger_sync/netsuite/operation/delete.rb +47 -0
- data/lib/ledger_sync/netsuite/operation/find.rb +68 -0
- data/lib/ledger_sync/netsuite/operation/update.rb +59 -0
- data/lib/ledger_sync/netsuite/record/http_method.rb +31 -0
- data/lib/ledger_sync/netsuite/record/metadata.rb +107 -0
- data/lib/ledger_sync/netsuite/record/parameter.rb +18 -0
- data/lib/ledger_sync/netsuite/record/property.rb +20 -0
- data/lib/ledger_sync/netsuite/reference/serializer.rb +11 -0
- data/lib/ledger_sync/netsuite/resource.rb +8 -0
- data/lib/ledger_sync/netsuite/resources/account.rb +41 -0
- data/lib/ledger_sync/netsuite/resources/check.rb +21 -0
- data/lib/ledger_sync/netsuite/resources/check_line_item.rb +13 -0
- data/lib/ledger_sync/netsuite/resources/currency.rb +11 -0
- data/lib/ledger_sync/netsuite/resources/customer.rb +17 -0
- data/lib/ledger_sync/netsuite/resources/customer_deposit.rb +13 -0
- data/lib/ledger_sync/netsuite/resources/department.rb +14 -0
- data/lib/ledger_sync/netsuite/resources/deposit.rb +26 -0
- data/lib/ledger_sync/netsuite/resources/deposit_line_item.rb +23 -0
- data/lib/ledger_sync/netsuite/resources/invoice.rb +26 -0
- data/lib/ledger_sync/netsuite/resources/invoice_line_item.rb +19 -0
- data/lib/ledger_sync/netsuite/resources/item.rb +9 -0
- data/lib/ledger_sync/netsuite/resources/journal_entry.rb +24 -0
- data/lib/ledger_sync/netsuite/resources/journal_entry_line_item.rb +22 -0
- data/lib/ledger_sync/netsuite/resources/ledger_class.rb +14 -0
- data/lib/ledger_sync/netsuite/resources/location.rb +9 -0
- data/lib/ledger_sync/netsuite/resources/subsidiary.rb +10 -0
- data/lib/ledger_sync/netsuite/resources/vendor.rb +21 -0
- data/lib/ledger_sync/netsuite/searcher.rb +64 -0
- data/lib/ledger_sync/netsuite/serializer.rb +11 -0
- data/lib/ledger_sync/netsuite/subsidiary/deserializer.rb +15 -0
- data/lib/ledger_sync/netsuite/subsidiary/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/subsidiary/searcher_deserializer.rb +13 -0
- data/lib/ledger_sync/netsuite/subsidiary/serializer.rb +13 -0
- data/lib/ledger_sync/netsuite/token.rb +156 -0
- data/lib/ledger_sync/netsuite/type/deserializer_active_type.rb +30 -0
- data/lib/ledger_sync/netsuite/type/deserializer_customer_type.rb +33 -0
- data/lib/ledger_sync/netsuite/type/deserializer_entity_type.rb +28 -0
- data/lib/ledger_sync/netsuite/type/deserializer_subsidiary_type.rb +33 -0
- data/lib/ledger_sync/netsuite/vendor/deserializer.rb +28 -0
- data/lib/ledger_sync/netsuite/vendor/operations/create.rb +25 -0
- data/lib/ledger_sync/netsuite/vendor/operations/delete.rb +25 -0
- data/lib/ledger_sync/netsuite/vendor/operations/find.rb +25 -0
- data/lib/ledger_sync/netsuite/vendor/operations/update.rb +25 -0
- data/lib/ledger_sync/netsuite/vendor/searcher.rb +10 -0
- data/lib/ledger_sync/netsuite/vendor/searcher_deserializer.rb +19 -0
- data/lib/ledger_sync/netsuite/vendor/serializer.rb +28 -0
- data/lib/ledger_sync/netsuite/version.rb +17 -0
- data/license.txt +4 -0
- metadata +392 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Parser for OpenAPI 3.0 data for a given record method
|
5
|
+
#
|
6
|
+
module LedgerSync
|
7
|
+
module NetSuite
|
8
|
+
class Record
|
9
|
+
class Parameter < Util::ReadOnlyObject
|
10
|
+
attribute :description
|
11
|
+
attribute :location, source: :in
|
12
|
+
attribute :name
|
13
|
+
attribute :required
|
14
|
+
attribute :schema
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Parser for OpenAPI 3.0 data for a given record method
|
5
|
+
#
|
6
|
+
module LedgerSync
|
7
|
+
module NetSuite
|
8
|
+
class Record
|
9
|
+
class Property < Util::ReadOnlyObject
|
10
|
+
attribute :enum, default: nil
|
11
|
+
attribute :format, default: nil
|
12
|
+
attribute :key
|
13
|
+
attribute :nullable, default: false
|
14
|
+
attribute :read_only, default: false, source: :readOnly
|
15
|
+
attribute :title
|
16
|
+
attribute :type
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'currency'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module NetSuite
|
7
|
+
class Account < NetSuite::Resource
|
8
|
+
TYPES = {
|
9
|
+
'bank' => 'Bank',
|
10
|
+
'other_current_assets' => 'OthCurrAsset',
|
11
|
+
'fixed_asset' => 'FixedAsset',
|
12
|
+
'other_asset' => 'OthAsset',
|
13
|
+
'accounts_receivable' => 'AcctRec',
|
14
|
+
'equity' => 'Equity',
|
15
|
+
'expense' => 'Expense',
|
16
|
+
'other_expense' => 'OthExpense',
|
17
|
+
'cost_of_goods_sold' => 'COGS',
|
18
|
+
'accounts_payable' => 'AcctPay',
|
19
|
+
'credit_card' => 'CredCard',
|
20
|
+
'long_term_liability' => 'LongTermLiab',
|
21
|
+
'other_current_liability' => 'OthCurrLiab',
|
22
|
+
'income' => 'Income',
|
23
|
+
'other_income' => 'OthIncome',
|
24
|
+
'deferred_expense' => 'DeferExpense',
|
25
|
+
'unbilled_recievable' => 'UnbilledRec',
|
26
|
+
'deferred_revenue' => 'DeferRevenue',
|
27
|
+
'non_posting' => 'NonPosting'
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
attribute :name, type: Type::String
|
31
|
+
attribute :classification, type: Type::String
|
32
|
+
attribute :account_type, type: Type::StringFromSet.new(values: TYPES.keys)
|
33
|
+
attribute :account_sub_type, type: Type::String
|
34
|
+
attribute :number, type: Type::String
|
35
|
+
attribute :description, type: Type::String
|
36
|
+
attribute :active, type: Type::Boolean
|
37
|
+
|
38
|
+
references_one :currency, to: Currency
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'check_line_item'
|
4
|
+
require_relative 'customer'
|
5
|
+
require_relative 'vendor'
|
6
|
+
|
7
|
+
module LedgerSync
|
8
|
+
module NetSuite
|
9
|
+
class Check < NetSuite::Resource
|
10
|
+
attribute :memo, type: Type::String
|
11
|
+
attribute :trandate, type: Type::String
|
12
|
+
|
13
|
+
references_one :account
|
14
|
+
references_one :department
|
15
|
+
references_one :entity, to: [Customer, Vendor]
|
16
|
+
references_one :currency
|
17
|
+
|
18
|
+
references_many :line_items, to: CheckLineItem
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module NetSuite
|
5
|
+
class CheckLineItem < NetSuite::Resource
|
6
|
+
references_one :account
|
7
|
+
references_one :ledger_class
|
8
|
+
references_one :department
|
9
|
+
attribute :amount, type: Type::Float
|
10
|
+
attribute :memo, type: Type::String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'subsidiary'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module NetSuite
|
7
|
+
class Customer < NetSuite::Resource
|
8
|
+
attribute :email, type: LedgerSync::Type::String
|
9
|
+
attribute :companyName, type: LedgerSync::Type::String
|
10
|
+
attribute :firstName, type: LedgerSync::Type::String
|
11
|
+
attribute :lastName, type: LedgerSync::Type::String
|
12
|
+
attribute :phone, type: LedgerSync::Type::String
|
13
|
+
|
14
|
+
references_one :subsidiary, to: Subsidiary
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module NetSuite
|
5
|
+
class CustomerDeposit < NetSuite::Resource
|
6
|
+
attribute :payment, type: Type::Float
|
7
|
+
attribute :undepFunds, type: Type::Boolean
|
8
|
+
|
9
|
+
references_one :account, to: Account
|
10
|
+
references_one :customer, to: Customer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module NetSuite
|
5
|
+
class Department < NetSuite::Resource
|
6
|
+
attribute :name, type: Type::String
|
7
|
+
attribute :fully_qualified_name, type: Type::String
|
8
|
+
attribute :active, type: Type::Boolean
|
9
|
+
attribute :sub_department, type: Type::Boolean
|
10
|
+
|
11
|
+
references_one :parent, to: Department
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'account'
|
4
|
+
require_relative 'currency'
|
5
|
+
require_relative 'department'
|
6
|
+
require_relative 'deposit_line_item'
|
7
|
+
|
8
|
+
module LedgerSync
|
9
|
+
module NetSuite
|
10
|
+
class Deposit < NetSuite::Resource
|
11
|
+
attribute :memo, type: Type::String
|
12
|
+
attribute :transaction_date, type: Type::Date
|
13
|
+
attribute :exchange_rate, type: Type::Float
|
14
|
+
|
15
|
+
references_one :account, to: Account
|
16
|
+
references_one :department, to: Department
|
17
|
+
references_one :currency, to: Currency
|
18
|
+
|
19
|
+
references_many :line_items, to: DepositLineItem
|
20
|
+
|
21
|
+
def name
|
22
|
+
"Deposit: #{currency}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'account'
|
4
|
+
require_relative 'customer'
|
5
|
+
require_relative 'ledger_class'
|
6
|
+
require_relative 'vendor'
|
7
|
+
|
8
|
+
module LedgerSync
|
9
|
+
module NetSuite
|
10
|
+
class DepositLineItem < NetSuite::Resource
|
11
|
+
references_one :account, to: Account
|
12
|
+
references_one :ledger_class, to: LedgerClass
|
13
|
+
attribute :amount, type: Type::Integer
|
14
|
+
attribute :description, type: Type::String
|
15
|
+
|
16
|
+
references_one :entity, to: [Customer, Vendor]
|
17
|
+
|
18
|
+
def name
|
19
|
+
description
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'account'
|
4
|
+
require_relative 'currency'
|
5
|
+
require_relative 'customer'
|
6
|
+
require_relative 'invoice_line_item'
|
7
|
+
|
8
|
+
module LedgerSync
|
9
|
+
module NetSuite
|
10
|
+
class Invoice < NetSuite::Resource
|
11
|
+
attribute :memo, type: Type::String
|
12
|
+
attribute :transaction_date, type: Type::Date
|
13
|
+
attribute :deposit, type: Type::Integer
|
14
|
+
|
15
|
+
references_one :customer, to: Customer
|
16
|
+
references_one :account, to: Account
|
17
|
+
references_one :currency, to: Currency
|
18
|
+
|
19
|
+
references_many :line_items, to: InvoiceLineItem
|
20
|
+
|
21
|
+
def name
|
22
|
+
"Invoice: #{transaction_date}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'item'
|
4
|
+
require_relative 'ledger_class'
|
5
|
+
|
6
|
+
module LedgerSync
|
7
|
+
module NetSuite
|
8
|
+
class InvoiceLineItem < NetSuite::Resource
|
9
|
+
references_one :item, to: Item
|
10
|
+
references_one :ledger_class, to: LedgerClass
|
11
|
+
attribute :amount, type: Type::Integer
|
12
|
+
attribute :description, type: Type::String
|
13
|
+
|
14
|
+
def name
|
15
|
+
description
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'currency'
|
4
|
+
require_relative 'subsidiary'
|
5
|
+
require_relative 'journal_entry_line_item'
|
6
|
+
|
7
|
+
module LedgerSync
|
8
|
+
module NetSuite
|
9
|
+
class JournalEntry < NetSuite::Resource
|
10
|
+
attribute :memo, type: Type::String
|
11
|
+
attribute :trandate, type: Type::Date
|
12
|
+
attribute :tranId, type: Type::String
|
13
|
+
|
14
|
+
references_one :currency, to: Currency
|
15
|
+
references_one :subsidiary, to: Subsidiary
|
16
|
+
|
17
|
+
references_many :line_items, to: JournalEntryLineItem
|
18
|
+
|
19
|
+
def name
|
20
|
+
"JournalEntry: #{transaction_date}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 NetSuite
|
9
|
+
class JournalEntryLineItem < NetSuite::Resource
|
10
|
+
references_one :account, to: Account
|
11
|
+
attribute :line, type: Type::Integer
|
12
|
+
attribute :credit, type: Type::Float
|
13
|
+
attribute :debit, type: Type::Float
|
14
|
+
attribute :entitytype, type: Type::String
|
15
|
+
attribute :memo, type: Type::String
|
16
|
+
|
17
|
+
def name
|
18
|
+
description
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module NetSuite
|
5
|
+
class LedgerClass < NetSuite::Resource
|
6
|
+
attribute :name, type: Type::String
|
7
|
+
attribute :fully_qualified_name, type: Type::String
|
8
|
+
attribute :active, type: Type::Boolean
|
9
|
+
attribute :sub_class, type: Type::Boolean
|
10
|
+
|
11
|
+
references_one :parent, to: LedgerClass
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'subsidiary'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module NetSuite
|
7
|
+
class Vendor < NetSuite::Resource
|
8
|
+
attribute :company_name, type: Type::String
|
9
|
+
attribute :email, type: Type::String
|
10
|
+
attribute :display_name, type: Type::String
|
11
|
+
attribute :first_name, type: Type::String
|
12
|
+
attribute :last_name, type: Type::String
|
13
|
+
attribute :phone_number, type: Type::String
|
14
|
+
references_one :subsidiary, to: Subsidiary
|
15
|
+
|
16
|
+
def name
|
17
|
+
display_name.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module NetSuite
|
5
|
+
class Searcher < Ledgers::Searcher
|
6
|
+
include LedgerSync::Ledgers::Mixins::OffsetAndLimitPaginationSearcherMixin
|
7
|
+
|
8
|
+
def query_attributes
|
9
|
+
@query_attributes ||= searcher_deserializer_class.attributes.values.map(&:hash_attribute)
|
10
|
+
end
|
11
|
+
|
12
|
+
def query_string
|
13
|
+
"SELECT #{query_attributes.join(', ')} FROM #{query_table}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def query_table
|
17
|
+
@query_table ||= client.class.ledger_resource_type_for(resource_class: self.class.inferred_resource_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_url
|
21
|
+
client.api_base_url.gsub('/record/v1', '') + "/query/v1/suiteql?limit=#{limit}&offset=#{offset}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def resources
|
25
|
+
resource_class = self.class.inferred_resource_class
|
26
|
+
|
27
|
+
@resources ||= begin
|
28
|
+
@request = client
|
29
|
+
.post(
|
30
|
+
body: { q: query_string.to_s },
|
31
|
+
request_url: request_url
|
32
|
+
)
|
33
|
+
|
34
|
+
case request.status
|
35
|
+
when 200
|
36
|
+
request.body
|
37
|
+
.fetch('items')
|
38
|
+
.map do |c|
|
39
|
+
searcher_deserializer_class.new.deserialize(hash: c, resource: resource_class.new)
|
40
|
+
end
|
41
|
+
when 404
|
42
|
+
[]
|
43
|
+
when 400
|
44
|
+
if request.body['title'].include?(
|
45
|
+
'Invalid search query Search error occurred: Record ‘subsidiary’ was not found'
|
46
|
+
)
|
47
|
+
raise LedgerSync::NetSuite::Error::SubsidiariesNotEnabled
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def searcher_deserializer_class
|
54
|
+
@searcher_deserializer_class ||= self.class.inferred_serialization_class(type: 'SearcherDeserializer')
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def default_offset
|
60
|
+
0
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|