ledger_sync 1.0.10 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +36 -20
- data/README.md +105 -66
- data/ledger_sync.gemspec +1 -0
- data/lib/ledger_sync.rb +23 -4
- data/lib/ledger_sync/adaptors/operation.rb +28 -28
- data/lib/ledger_sync/adaptors/quickbooks_online/account/mapping.rb +325 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb +54 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/find.rb +38 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/update.rb +61 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +67 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +18 -16
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/create.rb +65 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/find.rb +37 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/update.rb +69 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +6 -6
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -3
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +6 -9
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -38
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +61 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +36 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +65 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/mapping.rb +15 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/create.rb +68 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/find.rb +39 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/update.rb +72 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/mapping.rb +14 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/create.rb +56 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/find.rb +34 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/update.rb +60 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +30 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +8 -22
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +0 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +6 -22
- data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +45 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb +52 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/find.rb +36 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/update.rb +57 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +46 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +36 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +51 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +64 -0
- data/lib/ledger_sync/adaptors/searcher.rb +3 -1
- data/lib/ledger_sync/adaptors/test/account/operations/create.rb +53 -0
- data/lib/ledger_sync/adaptors/test/account/operations/find.rb +38 -0
- data/lib/ledger_sync/adaptors/test/account/operations/invalid.rb +25 -0
- data/lib/ledger_sync/adaptors/test/account/operations/update.rb +50 -0
- data/lib/ledger_sync/adaptors/test/account/operations/valid.rb +31 -0
- data/lib/ledger_sync/adaptors/test/account/searcher.rb +40 -0
- data/lib/ledger_sync/adaptors/test/adaptor.rb +4 -4
- data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +4 -6
- data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +0 -2
- data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +4 -6
- data/lib/ledger_sync/adaptors/test/customer/searcher.rb +2 -2
- data/lib/ledger_sync/adaptors/test/expense/operations/create.rb +54 -0
- data/lib/ledger_sync/adaptors/test/expense/operations/find.rb +39 -0
- data/lib/ledger_sync/adaptors/test/expense/operations/update.rb +57 -0
- data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +4 -20
- data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +0 -2
- data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +4 -20
- data/lib/ledger_sync/adaptors/test/transfer/operations/create.rb +45 -0
- data/lib/ledger_sync/adaptors/test/transfer/operations/find.rb +36 -0
- data/lib/ledger_sync/adaptors/test/transfer/operations/update.rb +48 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +47 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +34 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +21 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +44 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +27 -0
- data/lib/ledger_sync/adaptors/test/vendor/searcher.rb +41 -0
- data/lib/ledger_sync/error/resource_errors.rb +24 -0
- data/lib/ledger_sync/resource.rb +24 -64
- data/lib/ledger_sync/resource_attribute.rb +50 -0
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +49 -0
- data/lib/ledger_sync/resource_attribute/mixin.rb +90 -0
- data/lib/ledger_sync/resource_attribute/reference.rb +9 -0
- data/lib/ledger_sync/resource_attribute/reference/many.rb +34 -0
- data/lib/ledger_sync/resource_attribute/reference/one.rb +33 -0
- data/lib/ledger_sync/resource_attribute_set.rb +58 -0
- data/lib/ledger_sync/resources/account.rb +14 -0
- data/lib/ledger_sync/resources/bill.rb +17 -0
- data/lib/ledger_sync/resources/bill_line_item.rb +11 -0
- data/lib/ledger_sync/resources/customer.rb +5 -4
- data/lib/ledger_sync/resources/deposit.rb +16 -0
- data/lib/ledger_sync/resources/deposit_line_item.rb +11 -0
- data/lib/ledger_sync/resources/expense.rb +19 -0
- data/lib/ledger_sync/resources/expense_line_item.rb +11 -0
- data/lib/ledger_sync/resources/journal_entry.rb +13 -0
- data/lib/ledger_sync/resources/journal_entry_line_item.rb +12 -0
- data/lib/ledger_sync/resources/payment.rb +5 -3
- data/lib/ledger_sync/resources/transfer.rb +15 -0
- data/lib/ledger_sync/resources/vendor.rb +12 -0
- data/lib/ledger_sync/result.rb +0 -24
- data/lib/ledger_sync/type/boolean.rb +17 -0
- data/lib/ledger_sync/type/date.rb +17 -0
- data/lib/ledger_sync/type/float.rb +17 -0
- data/lib/ledger_sync/type/integer.rb +17 -0
- data/lib/ledger_sync/type/reference_many.rb +27 -0
- data/lib/ledger_sync/type/reference_one.rb +26 -0
- data/lib/ledger_sync/type/string.rb +17 -0
- data/lib/ledger_sync/type/value.rb +12 -0
- data/lib/ledger_sync/type/value_mixin.rb +19 -0
- data/lib/ledger_sync/util/hash_helpers.rb +16 -1
- data/lib/ledger_sync/util/resources_builder.rb +36 -9
- data/lib/ledger_sync/version.rb +1 -1
- metadata +92 -7
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/upsert.rb +0 -42
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb +0 -53
- data/lib/ledger_sync/adaptors/test/customer/operations/upsert.rb +0 -42
- data/lib/ledger_sync/adaptors/test/payment/operations/upsert.rb +0 -53
- data/lib/ledger_sync/sync.rb +0 -108
- data/lib/ledger_sync/util/coordinator.rb +0 -72
@@ -0,0 +1,38 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Account
|
5
|
+
module Operations
|
6
|
+
class Find < Operation::Find
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
params do
|
9
|
+
required(:ledger_id).filled(:string)
|
10
|
+
required(:name).maybe(:string)
|
11
|
+
required(:classification).maybe(:string)
|
12
|
+
required(:account_type).maybe(:string)
|
13
|
+
required(:account_sub_type).maybe(:string)
|
14
|
+
required(:number).maybe(:integer)
|
15
|
+
required(:currency).maybe(:string)
|
16
|
+
required(:description).maybe(:string)
|
17
|
+
required(:active).maybe(:bool)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def operate
|
24
|
+
return failure(nil) if resource.ledger_id.nil?
|
25
|
+
|
26
|
+
response = adaptor.find(
|
27
|
+
resource: 'account',
|
28
|
+
id: resource.ledger_id
|
29
|
+
)
|
30
|
+
|
31
|
+
success(response: response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Account
|
5
|
+
module Operations
|
6
|
+
class Invalid < Operation::Create
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
schema do
|
9
|
+
required(:ledger_id).filled(:string)
|
10
|
+
required(:name).maybe(:string)
|
11
|
+
required(:classification).maybe(:string)
|
12
|
+
required(:account_type).maybe(:string)
|
13
|
+
required(:account_sub_type).maybe(:string)
|
14
|
+
required(:number).maybe(:integer)
|
15
|
+
required(:currency).maybe(:string)
|
16
|
+
required(:description).maybe(:string)
|
17
|
+
required(:active).maybe(:bool)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Account
|
5
|
+
module Operations
|
6
|
+
class Update < Operation::Update
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
schema do
|
9
|
+
required(:ledger_id).filled(:string)
|
10
|
+
required(:name).filled(:string)
|
11
|
+
required(:classification).filled(:string)
|
12
|
+
required(:account_type).filled(:string)
|
13
|
+
required(:account_sub_type).filled(:string)
|
14
|
+
required(:number).maybe(:integer)
|
15
|
+
required(:currency).maybe(:string)
|
16
|
+
required(:description).maybe(:string)
|
17
|
+
required(:active).maybe(:bool)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def operate
|
24
|
+
ledger_resource_data = adaptor.find(
|
25
|
+
resource: 'account',
|
26
|
+
id: resource.ledger_id
|
27
|
+
)
|
28
|
+
|
29
|
+
response = adaptor.post(
|
30
|
+
resource: 'account',
|
31
|
+
payload: merge_into(from: local_resource_data, to: ledger_resource_data)
|
32
|
+
)
|
33
|
+
|
34
|
+
success(response: response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def local_resource_data
|
38
|
+
{
|
39
|
+
'name' => resource.name,
|
40
|
+
'classification' => resource.classification,
|
41
|
+
'account_type' => resource.account_type,
|
42
|
+
'account_sub_type' => resource.account_sub_type
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Account
|
5
|
+
module Operations
|
6
|
+
class Valid < Operation::Create
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
schema do
|
9
|
+
optional(:ledger_id).maybe(:string)
|
10
|
+
required(:name).filled(:string)
|
11
|
+
required(:classification).filled(:string)
|
12
|
+
required(:account_type).filled(:string)
|
13
|
+
required(:account_sub_type).filled(:string)
|
14
|
+
required(:number).maybe(:integer)
|
15
|
+
required(:currency).maybe(:string)
|
16
|
+
required(:description).maybe(:string)
|
17
|
+
required(:active).maybe(:bool)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def operate
|
24
|
+
success(response: :foo)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Account
|
5
|
+
class Searcher < LedgerSync::Adaptors::Searcher
|
6
|
+
def next_searcher
|
7
|
+
paginate(cursor: 'asdf')
|
8
|
+
end
|
9
|
+
|
10
|
+
def previous_searcher
|
11
|
+
paginate(cursor: 'asdf')
|
12
|
+
end
|
13
|
+
|
14
|
+
def resources
|
15
|
+
@resources ||= begin
|
16
|
+
adaptor
|
17
|
+
.query(
|
18
|
+
resource: 'account',
|
19
|
+
query: "name LIKE '#{query}%'"
|
20
|
+
)
|
21
|
+
.map do |a|
|
22
|
+
LedgerSync::Account.new(
|
23
|
+
ledger_id: a.fetch('id'),
|
24
|
+
name: a.fetch('name', ''),
|
25
|
+
account_type: a.fetch('account_type', '')
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def search
|
32
|
+
super
|
33
|
+
rescue OAuth2::Error => e
|
34
|
+
failure(e)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -8,6 +8,10 @@ module LedgerSync
|
|
8
8
|
{ 'id' => id }
|
9
9
|
end
|
10
10
|
|
11
|
+
def post(resource:, payload:)
|
12
|
+
payload
|
13
|
+
end
|
14
|
+
|
11
15
|
def query(resource:, query:)
|
12
16
|
resource_klass = LedgerSync.resources[resource.to_sym]
|
13
17
|
|
@@ -25,10 +29,6 @@ module LedgerSync
|
|
25
29
|
self
|
26
30
|
end
|
27
31
|
|
28
|
-
def upsert(resource:, payload:)
|
29
|
-
payload
|
30
|
-
end
|
31
|
-
|
32
32
|
def url_for(resource:)
|
33
33
|
case resource
|
34
34
|
when LedgerSync::Customer
|
@@ -21,14 +21,14 @@ module LedgerSync
|
|
21
21
|
|
22
22
|
def local_resource_data
|
23
23
|
{
|
24
|
-
'name'
|
25
|
-
|
26
|
-
|
24
|
+
'name' => resource.name,
|
25
|
+
'phone_number' => resource.phone_number,
|
26
|
+
'email' => resource.email
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
30
|
def operate
|
31
|
-
response = adaptor.
|
31
|
+
response = adaptor.post(
|
32
32
|
resource: 'customer',
|
33
33
|
payload: local_resource_data.merge(
|
34
34
|
'id' => id
|
@@ -38,8 +38,6 @@ module LedgerSync
|
|
38
38
|
resource.ledger_id = response.dig('id')
|
39
39
|
|
40
40
|
success(response: response)
|
41
|
-
rescue OAuth2::Error => e
|
42
|
-
failure(e)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -21,21 +21,19 @@ module LedgerSync
|
|
21
21
|
id: resource.ledger_id
|
22
22
|
)
|
23
23
|
|
24
|
-
response = adaptor.
|
24
|
+
response = adaptor.post(
|
25
25
|
resource: 'customer',
|
26
26
|
payload: merge_into(from: local_resource_data, to: ledger_resource_data)
|
27
27
|
)
|
28
28
|
|
29
29
|
success(response: response)
|
30
|
-
rescue OAuth2::Error => e
|
31
|
-
failure(e)
|
32
30
|
end
|
33
31
|
|
34
32
|
def local_resource_data
|
35
33
|
{
|
36
|
-
'name'
|
37
|
-
|
38
|
-
|
34
|
+
'name' => resource.name,
|
35
|
+
'phone_number' => resource.phone_number,
|
36
|
+
'email' => resource.email
|
39
37
|
}
|
40
38
|
end
|
41
39
|
end
|
@@ -4,11 +4,11 @@ module LedgerSync
|
|
4
4
|
module Customer
|
5
5
|
class Searcher < LedgerSync::Adaptors::Searcher
|
6
6
|
def next_searcher
|
7
|
-
paginate(cursor: '
|
7
|
+
paginate(cursor: 'next_page')
|
8
8
|
end
|
9
9
|
|
10
10
|
def previous_searcher
|
11
|
-
paginate(cursor: '
|
11
|
+
paginate(cursor: 'previous_page')
|
12
12
|
end
|
13
13
|
|
14
14
|
def resources
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Expense
|
5
|
+
module Operations
|
6
|
+
class Create < Operation::Create
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
schema do
|
9
|
+
required(:ledger_id).value(:nil)
|
10
|
+
required(:account).hash(Types::Reference)
|
11
|
+
required(:vendor).hash(Types::Reference)
|
12
|
+
required(:amount).filled(:integer)
|
13
|
+
required(:currency).filled(:string)
|
14
|
+
required(:memo).filled(:string)
|
15
|
+
required(:payment_type).filled(:string)
|
16
|
+
required(:transaction_date).filled(:date?)
|
17
|
+
required(:exchange_rate).maybe(:float)
|
18
|
+
required(:line_items).array(Types::Reference)
|
19
|
+
end
|
20
|
+
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
|
+
'amount' => resource.amount,
|
37
|
+
'currency' => resource.currency,
|
38
|
+
'account_id' => resource.account.ledger_id,
|
39
|
+
'vendor_id' => resource.vendor.ledger_id,
|
40
|
+
'line_items' => resource.line_items.map do |line_item|
|
41
|
+
{
|
42
|
+
'account_id' => line_item.account&.ledger_id,
|
43
|
+
'Amount' => line_item.amount / 100.0,
|
44
|
+
'description' => line_item.description
|
45
|
+
}
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Expense
|
5
|
+
module Operations
|
6
|
+
class Find < Operation::Find
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
schema do
|
9
|
+
required(:ledger_id).filled(:string)
|
10
|
+
required(:account).hash(Types::Reference)
|
11
|
+
required(:vendor).hash(Types::Reference)
|
12
|
+
required(:amount).maybe(:integer)
|
13
|
+
required(:currency).maybe(:string)
|
14
|
+
required(:memo).maybe(:string)
|
15
|
+
required(:payment_type).maybe(:string)
|
16
|
+
required(:transaction_date).maybe(:date?)
|
17
|
+
required(:exchange_rate).maybe(:float)
|
18
|
+
required(:line_items).array(Types::Reference)
|
19
|
+
end
|
20
|
+
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
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module LedgerSync
|
2
|
+
module Adaptors
|
3
|
+
module Test
|
4
|
+
module Expense
|
5
|
+
module Operations
|
6
|
+
class Update < Operation::Update
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
8
|
+
params do
|
9
|
+
required(:ledger_id).filled(:string)
|
10
|
+
required(:account).hash(Types::Reference)
|
11
|
+
required(:vendor).hash(Types::Reference)
|
12
|
+
required(:amount).filled(:integer)
|
13
|
+
required(:currency).filled(:string)
|
14
|
+
required(:memo).filled(:string)
|
15
|
+
required(:payment_type).filled(:string)
|
16
|
+
required(:transaction_date).filled(:date?)
|
17
|
+
required(:exchange_rate).maybe(:float)
|
18
|
+
required(:line_items).array(Types::Reference)
|
19
|
+
end
|
20
|
+
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
|
+
success(response: response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def local_resource_data
|
38
|
+
{
|
39
|
+
'amount' => resource.amount,
|
40
|
+
'currency' => resource.currency,
|
41
|
+
'account_id' => resource.account.ledger_id,
|
42
|
+
'vendor_id' => resource.vendor.ledger_id,
|
43
|
+
'line_items' => resource.line_items.map do |line_item|
|
44
|
+
{
|
45
|
+
'account_id' => line_item.account&.ledger_id,
|
46
|
+
'Amount' => line_item.amount / 100.0,
|
47
|
+
'description' => line_item.description
|
48
|
+
}
|
49
|
+
end
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -15,37 +15,21 @@ module LedgerSync
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def build
|
19
|
-
build_customer_operation
|
20
|
-
add_root_operation(self)
|
21
|
-
end
|
22
|
-
|
23
18
|
def operate
|
24
|
-
response = adaptor.
|
19
|
+
response = adaptor.post(
|
25
20
|
resource: 'payment',
|
26
21
|
payload: local_resource_data
|
27
22
|
)
|
28
23
|
|
29
24
|
resource.ledger_id = response.dig('id')
|
30
25
|
success(response: response)
|
31
|
-
rescue OAuth2::Error => e
|
32
|
-
failure(e)
|
33
|
-
end
|
34
|
-
|
35
|
-
def build_customer_operation
|
36
|
-
customer = Customer::Operations::Upsert.new(
|
37
|
-
adaptor: adaptor,
|
38
|
-
resource: resource.customer
|
39
|
-
)
|
40
|
-
|
41
|
-
add_before_operation(customer)
|
42
26
|
end
|
43
27
|
|
44
28
|
def local_resource_data
|
45
29
|
{
|
46
|
-
'amount'
|
47
|
-
'currency'
|
48
|
-
'customer_id'
|
30
|
+
'amount' => resource.amount,
|
31
|
+
'currency' => resource.currency,
|
32
|
+
'customer_id' => resource.customer.ledger_id
|
49
33
|
}
|
50
34
|
end
|
51
35
|
end
|