ledger_sync 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -3
- data/lib/ledger_sync.rb +12 -6
- data/lib/ledger_sync/adaptors/ledger_serializer.rb +124 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_attribute.rb +148 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +51 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb +41 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_type/references_many_type.rb +24 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_type/value_type.rb +17 -0
- data/lib/ledger_sync/adaptors/operation.rb +15 -9
- data/lib/ledger_sync/adaptors/quickbooks_online/account/ledger_serializer.rb +21 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb +8 -36
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/find.rb +1 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/update.rb +4 -35
- data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +3 -44
- data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +75 -28
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/ledger_serializer.rb +40 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/create.rb +9 -48
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/find.rb +10 -21
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/update.rb +9 -52
- data/lib/ledger_sync/adaptors/quickbooks_online/bill_line_item/ledger_serializer.rb +27 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/ledger_serializer.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +2 -25
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +2 -14
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +3 -30
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/ledger_serializer.rb +35 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +2 -39
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +2 -14
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +4 -43
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit_line_item/ledger_serializer.rb +27 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/ledger_serializer.rb +48 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/create.rb +10 -51
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/find.rb +10 -22
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/update.rb +10 -55
- data/lib/ledger_sync/adaptors/quickbooks_online/expense_line_item/ledger_serializer.rb +27 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/ledger_serializer.rb +32 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/create.rb +4 -37
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/find.rb +4 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/update.rb +5 -42
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry_line_item/ledger_serializer.rb +31 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +103 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/{account/mapping.rb → ledger_serializer_type/account_sub_type.rb} +128 -148
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/account_type.rb +51 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/amount_type.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/classification_type.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/date_type.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/journal_entry_line_item_type.rb +20 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/payment_type.rb +21 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +2 -7
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/create.rb +29 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/find.rb +31 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +43 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/sparse_update.rb +29 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/ledger_serializer.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +1 -24
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +1 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +2 -29
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/ledger_serializer.rb +33 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb +1 -29
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/find.rb +1 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/update.rb +4 -35
- data/lib/ledger_sync/adaptors/quickbooks_online/util/adaptor_error_parser.rb +2 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +2 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +1 -23
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +1 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +2 -29
- data/lib/ledger_sync/adaptors/test/account/operations/create.rb +5 -1
- data/lib/ledger_sync/adaptors/test/account/operations/find.rb +5 -1
- data/lib/ledger_sync/adaptors/test/account/operations/invalid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/account/operations/update.rb +8 -2
- data/lib/ledger_sync/adaptors/test/account/operations/valid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +5 -1
- data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +5 -1
- data/lib/ledger_sync/adaptors/test/customer/operations/invalid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +1 -24
- data/lib/ledger_sync/adaptors/test/customer/operations/valid.rb +3 -6
- data/lib/ledger_sync/adaptors/test/expense/operations/create.rb +8 -3
- data/lib/ledger_sync/adaptors/test/expense/operations/find.rb +4 -14
- data/lib/ledger_sync/adaptors/test/expense/operations/update.rb +2 -32
- data/lib/ledger_sync/adaptors/test/ledger_serializer.rb +64 -0
- data/lib/ledger_sync/adaptors/test/operation/create.rb +27 -0
- data/lib/ledger_sync/adaptors/test/operation/find.rb +29 -0
- data/lib/ledger_sync/adaptors/test/operation/update.rb +34 -0
- data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +5 -1
- data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +5 -1
- data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +1 -23
- data/lib/ledger_sync/adaptors/test/transfer/operations/create.rb +1 -22
- data/lib/ledger_sync/adaptors/test/transfer/operations/find.rb +1 -13
- data/lib/ledger_sync/adaptors/test/transfer/operations/update.rb +1 -25
- data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +5 -1
- data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +7 -1
- data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +1 -23
- data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +1 -0
- data/lib/ledger_sync/error/adaptor_errors.rb +17 -5
- data/lib/ledger_sync/error/operation_errors.rb +12 -5
- data/lib/ledger_sync/error/resource_errors.rb +5 -1
- data/lib/ledger_sync/resource.rb +33 -6
- data/lib/ledger_sync/resource_attribute.rb +4 -0
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +16 -0
- data/lib/ledger_sync/resource_attribute/mixin.rb +19 -7
- data/lib/ledger_sync/resource_attribute/reference/many.rb +55 -1
- data/lib/ledger_sync/resource_attribute_set.rb +6 -7
- data/lib/ledger_sync/resources/account.rb +1 -1
- data/lib/ledger_sync/resources/bill.rb +1 -0
- data/lib/ledger_sync/resources/bill_line_item.rb +2 -0
- data/lib/ledger_sync/resources/expense.rb +5 -1
- data/lib/ledger_sync/resources/expense_line_item.rb +2 -0
- data/lib/ledger_sync/resources/journal_entry.rb +1 -0
- data/lib/ledger_sync/result.rb +4 -3
- data/lib/ledger_sync/type/id.rb +34 -0
- data/lib/ledger_sync/type/reference_many.rb +8 -2
- data/lib/ledger_sync/type/reference_one.rb +5 -0
- data/lib/ledger_sync/type/value_mixin.rb +12 -0
- data/lib/ledger_sync/util/hash_helpers.rb +16 -0
- data/lib/ledger_sync/version.rb +1 -1
- data/qa.rb +142 -0
- metadata +38 -5
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/mapping.rb +0 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/mapping.rb +0 -14
- data/lib/ledger_sync/error/sync_errors.rb +0 -22
@@ -3,9 +3,10 @@ module LedgerSync
|
|
3
3
|
module QuickBooksOnline
|
4
4
|
module Deposit
|
5
5
|
module Operations
|
6
|
-
class Find < Operation::Find
|
6
|
+
class Find < QuickBooksOnline::Operation::Find
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
8
8
|
schema do
|
9
|
+
required(:external_id).maybe(:string)
|
9
10
|
required(:ledger_id).filled(:string)
|
10
11
|
required(:account).hash(Types::Reference)
|
11
12
|
required(:currency).maybe(:string)
|
@@ -15,19 +16,6 @@ module LedgerSync
|
|
15
16
|
required(:line_items).array(Types::Reference)
|
16
17
|
end
|
17
18
|
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def operate
|
22
|
-
return failure(nil) if resource.ledger_id.nil?
|
23
|
-
|
24
|
-
response = adaptor.find(
|
25
|
-
resource: 'deposit',
|
26
|
-
id: resource.ledger_id
|
27
|
-
)
|
28
|
-
|
29
|
-
success(response: response)
|
30
|
-
end
|
31
19
|
end
|
32
20
|
end
|
33
21
|
end
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LedgerSync
|
2
4
|
module Adaptors
|
3
5
|
module QuickBooksOnline
|
4
6
|
module Deposit
|
5
7
|
module Operations
|
6
|
-
class Update < Operation::
|
8
|
+
class Update < QuickBooksOnline::Operation::FullUpdate
|
7
9
|
class Contract < LedgerSync::Adaptors::Contract
|
8
10
|
schema do
|
11
|
+
required(:external_id).maybe(:string)
|
9
12
|
required(:ledger_id).filled(:string)
|
10
13
|
required(:account).hash(Types::Reference)
|
11
14
|
required(:currency).filled(:string)
|
@@ -15,48 +18,6 @@ module LedgerSync
|
|
15
18
|
required(:line_items).array(Types::Reference)
|
16
19
|
end
|
17
20
|
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def operate
|
22
|
-
ledger_resource_data = adaptor.find(
|
23
|
-
resource: 'deposit',
|
24
|
-
id: resource.ledger_id
|
25
|
-
)
|
26
|
-
response = adaptor.post(
|
27
|
-
resource: 'deposit',
|
28
|
-
payload: merge_into(from: local_resource_data, to: ledger_resource_data)
|
29
|
-
)
|
30
|
-
|
31
|
-
resource.ledger_id = response.dig('Id')
|
32
|
-
success(response: response)
|
33
|
-
end
|
34
|
-
|
35
|
-
def local_resource_data
|
36
|
-
{
|
37
|
-
'CurrencyRef' => {
|
38
|
-
'value' => resource.currency,
|
39
|
-
},
|
40
|
-
'TxnDate' => resource.transaction_date.to_s, # Format: YYYY-MM-DD
|
41
|
-
'PrivateNote' => resource.memo,
|
42
|
-
'ExchangeRate' => resource.exchange_rate,
|
43
|
-
'DepositToAccountRef' => {
|
44
|
-
'value' => resource.account.ledger_id
|
45
|
-
},
|
46
|
-
'Line' => resource.line_items.map do |line_item|
|
47
|
-
{
|
48
|
-
'DetailType' => 'DepositLineDetail',
|
49
|
-
'DepositLineDetail' => {
|
50
|
-
'AccountRef' => {
|
51
|
-
'value' => line_item.account&.ledger_id
|
52
|
-
}
|
53
|
-
},
|
54
|
-
'Amount' => line_item.amount / 100.0,
|
55
|
-
'Description' => line_item.description
|
56
|
-
}
|
57
|
-
end
|
58
|
-
}
|
59
|
-
end
|
60
21
|
end
|
61
22
|
end
|
62
23
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module QuickBooksOnline
|
6
|
+
module DepositLineItem
|
7
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
8
|
+
id
|
9
|
+
|
10
|
+
attribute ledger_attribute: 'DetailType' do
|
11
|
+
'DepositLineDetail'
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute ledger_attribute: 'DepositLineDetail.AccountRef.value',
|
15
|
+
resource_attribute: 'account.ledger_id'
|
16
|
+
|
17
|
+
attribute ledger_attribute: 'Amount',
|
18
|
+
resource_attribute: :amount,
|
19
|
+
type: LedgerSerializerType::AmountType
|
20
|
+
|
21
|
+
attribute ledger_attribute: 'Description',
|
22
|
+
resource_attribute: :description
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../expense_line_item/ledger_serializer'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module QuickBooksOnline
|
8
|
+
module Expense
|
9
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
10
|
+
quickbooks_online_resource_type :purchase
|
11
|
+
|
12
|
+
id ledger_attribute: 'Id',
|
13
|
+
resource_attribute: :ledger_id
|
14
|
+
|
15
|
+
attribute ledger_attribute: 'CurrencyRef.value',
|
16
|
+
resource_attribute: :currency
|
17
|
+
|
18
|
+
attribute ledger_attribute: 'PaymentType',
|
19
|
+
resource_attribute: :payment_type,
|
20
|
+
type: LedgerSerializerType::PaymentType
|
21
|
+
|
22
|
+
attribute ledger_attribute: 'TxnDate',
|
23
|
+
resource_attribute: :transaction_date,
|
24
|
+
type: LedgerSerializerType::DateType
|
25
|
+
|
26
|
+
attribute ledger_attribute: 'PrivateNote',
|
27
|
+
resource_attribute: :memo
|
28
|
+
|
29
|
+
attribute ledger_attribute: 'ExchangeRate',
|
30
|
+
resource_attribute: :exchange_rate
|
31
|
+
|
32
|
+
attribute ledger_attribute: 'EntityRef.value',
|
33
|
+
resource_attribute: 'vendor.ledger_id'
|
34
|
+
|
35
|
+
attribute ledger_attribute: 'DocNumber',
|
36
|
+
resource_attribute: :reference_number
|
37
|
+
|
38
|
+
attribute ledger_attribute: 'AccountRef.value',
|
39
|
+
resource_attribute: 'account.ledger_id'
|
40
|
+
|
41
|
+
references_many ledger_attribute: 'Line',
|
42
|
+
resource_attribute: :line_items,
|
43
|
+
serializer: ExpenseLineItem::LedgerSerializer
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -3,63 +3,22 @@ module LedgerSync
|
|
3
3
|
module QuickBooksOnline
|
4
4
|
module Expense
|
5
5
|
module Operations
|
6
|
-
class Create < Operation::Create
|
6
|
+
class Create < QuickBooksOnline::Operation::Create
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
8
8
|
params do
|
9
|
-
required(:
|
10
|
-
required(:vendor).hash(Types::Reference)
|
9
|
+
required(:external_id).maybe(:string)
|
11
10
|
required(:account).hash(Types::Reference)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
required(:payment_type).filled(:string)
|
16
|
-
required(:transaction_date).filled(:date?)
|
17
|
-
required(:exchange_rate).maybe(:float)
|
11
|
+
optional(:currency).filled(:string)
|
12
|
+
optional(:exchange_rate).maybe(:float)
|
13
|
+
optional(:ledger_id).value(:nil)
|
18
14
|
required(:line_items).array(Types::Reference)
|
15
|
+
optional(:memo).filled(:string)
|
16
|
+
required(:payment_type).filled(:string)
|
17
|
+
optional(:reference_number).maybe(:string)
|
18
|
+
optional(:transaction_date).filled(:date?)
|
19
|
+
optional(:vendor).hash(Types::Reference)
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def operate
|
25
|
-
response = adaptor.post(
|
26
|
-
resource: 'purchase',
|
27
|
-
payload: local_resource_data
|
28
|
-
)
|
29
|
-
|
30
|
-
resource.ledger_id = response.dig('Id')
|
31
|
-
success(response: response)
|
32
|
-
end
|
33
|
-
|
34
|
-
def local_resource_data
|
35
|
-
{
|
36
|
-
'CurrencyRef' => {
|
37
|
-
'value' => resource.currency,
|
38
|
-
},
|
39
|
-
'PaymentType' => Mapping::PAYMENT_TYPES[resource.payment_type],
|
40
|
-
'TxnDate' => resource.transaction_date.to_s, # Format: YYYY-MM-DD
|
41
|
-
'PrivateNote' => resource.memo,
|
42
|
-
'ExchangeRate' => resource.exchange_rate,
|
43
|
-
'EntityRef' => {
|
44
|
-
'value' => resource.vendor.ledger_id,
|
45
|
-
},
|
46
|
-
'AccountRef' => {
|
47
|
-
'value' => resource.account.ledger_id
|
48
|
-
},
|
49
|
-
'Line' => resource.line_items.map do |line_item|
|
50
|
-
{
|
51
|
-
'DetailType' => 'AccountBasedExpenseLineDetail',
|
52
|
-
'AccountBasedExpenseLineDetail' => {
|
53
|
-
'AccountRef' => {
|
54
|
-
'value' => line_item.account&.ledger_id
|
55
|
-
}
|
56
|
-
},
|
57
|
-
'Amount' => line_item.amount / 100.0,
|
58
|
-
'Description' => line_item.description
|
59
|
-
}
|
60
|
-
end
|
61
|
-
}
|
62
|
-
end
|
63
22
|
end
|
64
23
|
end
|
65
24
|
end
|
@@ -6,31 +6,19 @@ module LedgerSync
|
|
6
6
|
class Find < Operation::Find
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
8
8
|
schema do
|
9
|
+
required(:external_id).maybe(:string)
|
10
|
+
optional(:account).hash(Types::Reference)
|
11
|
+
optional(:currency).maybe(:string)
|
12
|
+
optional(:exchange_rate).maybe(:float)
|
9
13
|
required(:ledger_id).filled(:string)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
required(:transaction_date).filled(:date?)
|
17
|
-
required(:exchange_rate).maybe(:float)
|
18
|
-
required(:line_items).array(Types::Reference)
|
14
|
+
optional(:line_items).array(Types::Reference)
|
15
|
+
optional(:memo).maybe(:string)
|
16
|
+
optional(:payment_type).maybe(:string)
|
17
|
+
optional(:reference_number).maybe(:string)
|
18
|
+
optional(:transaction_date).filled(:date?)
|
19
|
+
optional(:vendor).hash(Types::Reference)
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def operate
|
25
|
-
return failure(nil) if resource.ledger_id.nil?
|
26
|
-
|
27
|
-
response = adaptor.find(
|
28
|
-
resource: 'purchase',
|
29
|
-
id: resource.ledger_id
|
30
|
-
)
|
31
|
-
|
32
|
-
success(response: response)
|
33
|
-
end
|
34
22
|
end
|
35
23
|
end
|
36
24
|
end
|
@@ -3,67 +3,22 @@ module LedgerSync
|
|
3
3
|
module QuickBooksOnline
|
4
4
|
module Expense
|
5
5
|
module Operations
|
6
|
-
class Update < Operation::
|
6
|
+
class Update < Operation::FullUpdate
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
8
8
|
schema do
|
9
|
-
required(:
|
9
|
+
required(:external_id).maybe(:string)
|
10
10
|
required(:account).hash(Types::Reference)
|
11
|
-
|
12
|
-
|
13
|
-
required(:
|
14
|
-
required(:memo).filled(:string)
|
15
|
-
required(:payment_type).filled(:string)
|
16
|
-
required(:transaction_date).filled(:date?)
|
17
|
-
required(:exchange_rate).maybe(:float)
|
11
|
+
optional(:currency).filled(:string)
|
12
|
+
optional(:exchange_rate).maybe(:float)
|
13
|
+
required(:ledger_id).filled(:string)
|
18
14
|
required(:line_items).array(Types::Reference)
|
15
|
+
optional(:memo).filled(:string)
|
16
|
+
required(:payment_type).filled(:string)
|
17
|
+
optional(:reference_number).maybe(:string)
|
18
|
+
optional(:transaction_date).filled(:date?)
|
19
|
+
optional(:vendor).hash(Types::Reference)
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def operate
|
25
|
-
ledger_resource_data = adaptor.find(
|
26
|
-
resource: 'purchase',
|
27
|
-
id: resource.ledger_id
|
28
|
-
)
|
29
|
-
response = adaptor.post(
|
30
|
-
resource: 'purchase',
|
31
|
-
payload: merge_into(from: local_resource_data, to: ledger_resource_data)
|
32
|
-
)
|
33
|
-
|
34
|
-
resource.ledger_id = response.dig('Id')
|
35
|
-
success(response: response)
|
36
|
-
end
|
37
|
-
|
38
|
-
def local_resource_data
|
39
|
-
{
|
40
|
-
'CurrencyRef' => {
|
41
|
-
'value' => resource.currency,
|
42
|
-
},
|
43
|
-
'PaymentType' => Mapping::PAYMENT_TYPES[resource.payment_type],
|
44
|
-
'TxnDate' => resource.transaction_date.to_s, # Format: YYYY-MM-DD
|
45
|
-
'PrivateNote' => resource.memo,
|
46
|
-
'ExchangeRate' => resource.exchange_rate,
|
47
|
-
'EntityRef' => {
|
48
|
-
'value' => resource.vendor.ledger_id,
|
49
|
-
},
|
50
|
-
'AccountRef' => {
|
51
|
-
'value' => resource.account.ledger_id
|
52
|
-
},
|
53
|
-
'Line' => resource.line_items.map do |line_item|
|
54
|
-
{
|
55
|
-
'DetailType' => 'AccountBasedExpenseLineDetail',
|
56
|
-
'AccountBasedExpenseLineDetail' => {
|
57
|
-
'AccountRef' => {
|
58
|
-
'value' => line_item.account&.ledger_id
|
59
|
-
}
|
60
|
-
},
|
61
|
-
'Amount' => line_item.amount / 100.0,
|
62
|
-
'Description' => line_item.description
|
63
|
-
}
|
64
|
-
end
|
65
|
-
}
|
66
|
-
end
|
67
22
|
end
|
68
23
|
end
|
69
24
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module QuickBooksOnline
|
6
|
+
module ExpenseLineItem
|
7
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
8
|
+
attribute ledger_attribute: 'Id', resource_attribute: :ledger_id
|
9
|
+
|
10
|
+
attribute ledger_attribute: 'DetailType' do
|
11
|
+
'AccountBasedExpenseLineDetail'
|
12
|
+
end
|
13
|
+
|
14
|
+
attribute ledger_attribute: 'AccountBasedExpenseLineDetail.AccountRef.value',
|
15
|
+
resource_attribute: 'account.ledger_id'
|
16
|
+
|
17
|
+
attribute ledger_attribute: 'Amount',
|
18
|
+
resource_attribute: :amount,
|
19
|
+
type: LedgerSerializerType::AmountType
|
20
|
+
|
21
|
+
attribute ledger_attribute: 'Description',
|
22
|
+
resource_attribute: :description
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../journal_entry_line_item/ledger_serializer'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module QuickBooksOnline
|
8
|
+
module JournalEntry
|
9
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
10
|
+
id
|
11
|
+
|
12
|
+
attribute ledger_attribute: 'CurrencyRef.value',
|
13
|
+
resource_attribute: :currency
|
14
|
+
|
15
|
+
attribute ledger_attribute: 'TxnDate',
|
16
|
+
resource_attribute: :transaction_date,
|
17
|
+
type: LedgerSerializerType::DateType
|
18
|
+
|
19
|
+
attribute ledger_attribute: 'PrivateNote',
|
20
|
+
resource_attribute: :memo
|
21
|
+
|
22
|
+
attribute ledger_attribute: 'DocNumber',
|
23
|
+
resource_attribute: :reference_number
|
24
|
+
|
25
|
+
references_many ledger_attribute: 'Line',
|
26
|
+
resource_attribute: :line_items,
|
27
|
+
serializer: JournalEntryLineItem::LedgerSerializer
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -6,48 +6,15 @@ module LedgerSync
|
|
6
6
|
class Create < Operation::Create
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
8
8
|
params do
|
9
|
-
required(:
|
9
|
+
required(:external_id).maybe(:string)
|
10
10
|
optional(:currency).filled(:string)
|
11
|
+
required(:ledger_id).value(:nil)
|
12
|
+
optional(:line_items).array(Types::Reference)
|
11
13
|
optional(:memo).filled(:string)
|
14
|
+
optional(:reference_number).filled(:string)
|
12
15
|
optional(:transaction_date).filled(:date?)
|
13
|
-
optional(:line_items).array(Types::Reference)
|
14
16
|
end
|
15
17
|
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def operate
|
20
|
-
response = adaptor.post(
|
21
|
-
resource: 'journal_entry',
|
22
|
-
payload: local_resource_data
|
23
|
-
)
|
24
|
-
|
25
|
-
resource.ledger_id = response.dig('Id')
|
26
|
-
success(response: response)
|
27
|
-
end
|
28
|
-
|
29
|
-
def local_resource_data
|
30
|
-
{
|
31
|
-
'CurrencyRef' => {
|
32
|
-
'value' => resource.currency,
|
33
|
-
},
|
34
|
-
'TxnDate' => resource.transaction_date.to_s, # Format: YYYY-MM-DD
|
35
|
-
'PrivateNote' => resource.memo,
|
36
|
-
'Line' => resource.line_items.map do |line_item|
|
37
|
-
{
|
38
|
-
'DetailType' => 'JournalEntryLineDetail',
|
39
|
-
'JournalEntryLineDetail' => {
|
40
|
-
'PostingType': Mapping::LINE_ITEM_TYPES[line_item.entry_type],
|
41
|
-
'AccountRef' => {
|
42
|
-
'value' => line_item.account&.ledger_id
|
43
|
-
}
|
44
|
-
},
|
45
|
-
'Amount' => line_item.amount / 100.0,
|
46
|
-
'Description' => line_item.description
|
47
|
-
}
|
48
|
-
end
|
49
|
-
}
|
50
|
-
end
|
51
18
|
end
|
52
19
|
end
|
53
20
|
end
|