rconomic 0.4.1 → 0.5.0
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 +8 -8
- data/.travis.yml +1 -2
- data/Gemfile +1 -0
- data/README.md +6 -1
- data/lib/economic/account.rb +5 -7
- data/lib/economic/cash_book.rb +8 -10
- data/lib/economic/cash_book_entry.rb +1 -1
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +2 -2
- data/lib/economic/current_invoice.rb +10 -13
- data/lib/economic/current_invoice_line.rb +3 -3
- data/lib/economic/debtor.rb +1 -1
- data/lib/economic/debtor_contact.rb +2 -2
- data/lib/economic/entity.rb +19 -19
- data/lib/economic/invoice.rb +6 -6
- data/lib/economic/proxies/account_proxy.rb +4 -6
- data/lib/economic/proxies/actions/find_by_ci_number.rb +3 -5
- data/lib/economic/proxies/actions/find_by_date_interval.rb +4 -7
- data/lib/economic/proxies/actions/find_by_name.rb +71 -0
- data/lib/economic/proxies/actions/find_by_number.rb +3 -5
- data/lib/economic/proxies/cash_book_entry_proxy.rb +16 -13
- data/lib/economic/proxies/cash_book_proxy.rb +7 -23
- data/lib/economic/proxies/creditor_contact_proxy.rb +6 -49
- data/lib/economic/proxies/creditor_entry_proxy.rb +13 -19
- data/lib/economic/proxies/creditor_proxy.rb +6 -8
- data/lib/economic/proxies/current_invoice_line_proxy.rb +3 -9
- data/lib/economic/proxies/current_invoice_proxy.rb +12 -20
- data/lib/economic/proxies/debtor_contact_proxy.rb +6 -49
- data/lib/economic/proxies/debtor_entry_proxy.rb +9 -14
- data/lib/economic/proxies/debtor_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +21 -20
- data/lib/economic/proxies/entry_proxy.rb +14 -20
- data/lib/economic/session.rb +21 -12
- data/lib/economic/support/string.rb +5 -1
- data/lib/rconomic.rb +2 -1
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +0 -2
- data/spec/economic/current_invoice_spec.rb +1 -1
- data/spec/economic/entity_spec.rb +4 -3
- data/spec/economic/proxies/actions/find_by_name_spec.rb +48 -0
- data/spec/economic/proxies/cash_book_proxy_spec.rb +30 -5
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +10 -0
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +3 -3
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +5 -5
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +10 -1
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +2 -2
- data/spec/economic/proxies/invoice_proxy_spec.rb +3 -3
- data/spec/economic/session_spec.rb +44 -3
- data/spec/fixtures/cash_book_get_data/success.xml +14 -0
- data/spec/fixtures/cash_book_get_data_array/multiple.xml +23 -0
- data/spec/fixtures/creditor_contact_find_by_name/multiple.xml +15 -0
- data/spec/fixtures/creditor_contact_find_by_name/none.xml +9 -0
- data/spec/fixtures/debtor_contact_find_by_name/multiple.xml +15 -0
- data/spec/fixtures/debtor_contact_find_by_name/none.xml +9 -0
- data/spec/spec_helper.rb +6 -0
- metadata +10 -16
@@ -1,11 +1,9 @@
|
|
1
1
|
module FindByNumber
|
2
2
|
# Returns handle with a given number.
|
3
3
|
def find_by_number(number)
|
4
|
-
response =
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
end
|
4
|
+
response = request('FindByNumber', {
|
5
|
+
'number' => number
|
6
|
+
})
|
9
7
|
|
10
8
|
if response == {}
|
11
9
|
nil
|
@@ -3,9 +3,10 @@ require 'economic/proxies/entity_proxy'
|
|
3
3
|
module Economic
|
4
4
|
class CashBookEntryProxy < EntityProxy
|
5
5
|
def all
|
6
|
-
entity_hash = session.request(
|
7
|
-
|
8
|
-
|
6
|
+
entity_hash = session.request(
|
7
|
+
CashBookProxy.entity_class.soap_action_name(:get_entries),
|
8
|
+
{"cashBookHandle" => owner.handle.to_hash}
|
9
|
+
)
|
9
10
|
|
10
11
|
if entity_hash != {}
|
11
12
|
[ entity_hash.values.first ].flatten.each do |id_hash|
|
@@ -56,9 +57,12 @@ module Economic
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def set_due_date(id, date)
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
request("SetDueDate", {
|
61
|
+
'cashBookEntryHandle' => {
|
62
|
+
'Id1' => owner.handle[:number], 'Id2' => id
|
63
|
+
},
|
64
|
+
:value => date
|
65
|
+
})
|
62
66
|
end
|
63
67
|
|
64
68
|
protected
|
@@ -67,13 +71,12 @@ module Economic
|
|
67
71
|
handle_name = handle_name_for_action(action)
|
68
72
|
handle_key = Economic::Support::String.underscore(handle_name).intern
|
69
73
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
74
|
+
data = {}
|
75
|
+
data["cashBookHandle"] = { 'Number' => owner.handle[:number] }
|
76
|
+
data[handle_name] = { 'Number' => handles[handle_key][:number] } if handles[handle_key]
|
77
|
+
data["contraAccountHandle"] = { 'Number' => handles[:contra_account_handle][:number] } if handles[:contra_account_handle]
|
78
|
+
|
79
|
+
response = request(action, data)
|
77
80
|
|
78
81
|
find(response)
|
79
82
|
end
|
@@ -3,11 +3,9 @@ require 'economic/proxies/entity_proxy'
|
|
3
3
|
module Economic
|
4
4
|
class CashBookProxy < EntityProxy
|
5
5
|
def find_by_name(name)
|
6
|
-
response =
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
end
|
6
|
+
response = request('FindByName', {
|
7
|
+
'name' => name
|
8
|
+
})
|
11
9
|
|
12
10
|
cash_book = build
|
13
11
|
cash_book.partial = true
|
@@ -16,27 +14,13 @@ module Economic
|
|
16
14
|
cash_book
|
17
15
|
|
18
16
|
end
|
19
|
-
|
20
|
-
def all
|
21
|
-
response = session.request entity_class.soap_action('GetAll')
|
22
17
|
|
23
|
-
handles = [response[:cash_book_handle]].flatten.reject(&:blank?)
|
24
|
-
cash_books = []
|
25
|
-
handles.each do |handle|
|
26
|
-
cash_books << get_name(handle[:number])
|
27
|
-
end
|
28
|
-
|
29
|
-
cash_books
|
30
|
-
end
|
31
|
-
|
32
18
|
def get_name(id)
|
33
|
-
response =
|
34
|
-
|
35
|
-
'
|
36
|
-
'Number' => id
|
37
|
-
}
|
19
|
+
response = request("GetName", {
|
20
|
+
'cashBookHandle' => {
|
21
|
+
'Number' => id
|
38
22
|
}
|
39
|
-
|
23
|
+
})
|
40
24
|
|
41
25
|
cash_book = build
|
42
26
|
cash_book.number = id
|
@@ -2,63 +2,20 @@ require 'economic/proxies/entity_proxy'
|
|
2
2
|
|
3
3
|
module Economic
|
4
4
|
class CreditorContactProxy < EntityProxy
|
5
|
-
|
6
|
-
#
|
7
|
-
def build(properties = {})
|
8
|
-
contact = super
|
9
|
-
initialize_properties_with_values_from_owner(contact) if owner.is_a?(Creditor)
|
10
|
-
contact
|
11
|
-
end
|
12
|
-
|
13
|
-
# Gets data for CreditorContact from the API
|
14
|
-
def find(handle)
|
15
|
-
handle = Entity::Handle.build(:id => handle) unless handle.is_a?(Entity::Handle)
|
16
|
-
super(handle)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns CreditorContact that have the given name. The objects will only be partially loaded
|
5
|
+
# Returns CreditorContact that have the given name. The objects will only be
|
6
|
+
# partially loaded
|
20
7
|
def find_by_name(name)
|
21
|
-
|
22
|
-
response = session.request entity_class.soap_action('FindByName') do
|
23
|
-
soap.body = {
|
24
|
-
'name' => name
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# Make sure we always have an array of handles even if the result only contains one
|
29
|
-
handles = [response[:creditor_contact_handle]].flatten.reject(&:blank?)
|
30
|
-
|
31
|
-
# Create partial CreditorContact entities
|
32
|
-
contacts = handles.collect do |handle|
|
33
|
-
creditor_contact = build
|
34
|
-
creditor_contact.partial = true
|
35
|
-
creditor_contact.persisted = true
|
36
|
-
creditor_contact.handle = handle
|
37
|
-
creditor_contact.id = handle[:id]
|
38
|
-
creditor_contact.number = handle[:number]
|
39
|
-
creditor_contact
|
40
|
-
end
|
41
|
-
|
42
|
-
if owner.is_a?(Creditor)
|
43
|
-
# Scope to the owner
|
44
|
-
contacts.select do |creditor_contact|
|
45
|
-
creditor_contact.get_data
|
46
|
-
creditor_contact.creditor.handle == owner.handle
|
47
|
-
end
|
48
|
-
else
|
49
|
-
contacts
|
50
|
-
end
|
51
|
-
|
8
|
+
Proxies::Actions::FindByName.new(self, name).call
|
52
9
|
end
|
53
10
|
|
54
|
-
|
55
11
|
private
|
56
12
|
|
57
13
|
# Initialize properties in contact with values from owner. Returns contact.
|
58
14
|
def initialize_properties_with_values_from_owner(contact)
|
59
|
-
|
15
|
+
if owner.is_a?(Creditor)
|
16
|
+
contact.creditor = owner
|
17
|
+
end
|
60
18
|
contact
|
61
19
|
end
|
62
|
-
|
63
20
|
end
|
64
21
|
end
|
@@ -3,11 +3,9 @@ require 'economic/proxies/entity_proxy'
|
|
3
3
|
module Economic
|
4
4
|
class CreditorEntryProxy < EntityProxy
|
5
5
|
def find_by_invoice_number(invoice_number)
|
6
|
-
response =
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
end
|
6
|
+
response = request('FindByInvoiceNumber', {
|
7
|
+
'invoiceNumber' => invoice_number
|
8
|
+
})
|
11
9
|
|
12
10
|
response[:creditor_entry_handle].map do |creditor_entry_handle|
|
13
11
|
# Kinda ugly, but we get an array instead of a hash when there's only one result. :)
|
@@ -16,27 +14,23 @@ module Economic
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def find(serial_number)
|
19
|
-
response =
|
20
|
-
|
21
|
-
'
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
end
|
17
|
+
response = request('GetData', {
|
18
|
+
'entityHandle' => {
|
19
|
+
'SerialNumber' => serial_number
|
20
|
+
}
|
21
|
+
})
|
26
22
|
|
27
23
|
build(response)
|
28
24
|
end
|
29
25
|
|
30
26
|
def match(*serial_numbers)
|
31
|
-
response =
|
32
|
-
|
33
|
-
|
34
|
-
"
|
35
|
-
{ "SerialNumber" => serial_number }
|
36
|
-
}
|
27
|
+
response = request('MatchEntries', {
|
28
|
+
:entries => {
|
29
|
+
"CreditorEntryHandle" => serial_numbers.map { |serial_number|
|
30
|
+
{ "SerialNumber" => serial_number }
|
37
31
|
}
|
38
32
|
}
|
39
|
-
|
33
|
+
})
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
@@ -10,14 +10,12 @@ module Economic
|
|
10
10
|
include FindByNumber
|
11
11
|
|
12
12
|
def create_simple(opts)
|
13
|
-
response =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
end
|
13
|
+
response = request('Create', {
|
14
|
+
'number' => opts[:number],
|
15
|
+
'creditorGroupHandle' => { 'Number' => opts[:creditor_group_handle][:number] },
|
16
|
+
:name => opts[:name],
|
17
|
+
:vatZone => opts[:vat_zone]
|
18
|
+
})
|
21
19
|
|
22
20
|
find(response)
|
23
21
|
end
|
@@ -2,13 +2,6 @@ require 'economic/proxies/entity_proxy'
|
|
2
2
|
|
3
3
|
module Economic
|
4
4
|
class CurrentInvoiceLineProxy < EntityProxy
|
5
|
-
# Returns a new, unpersisted Economic::CurrentInvoiceLine
|
6
|
-
def build(properties = {})
|
7
|
-
invoice_line = super
|
8
|
-
initialize_properties_with_values_from_owner(invoice_line) if owner.is_a?(CurrentInvoice)
|
9
|
-
invoice_line
|
10
|
-
end
|
11
|
-
|
12
5
|
# Gets data for CurrentInvoiceLine from the API
|
13
6
|
def find(handle)
|
14
7
|
handle = Entity::Handle.build(:number => handle) unless handle.is_a?(Entity::Handle)
|
@@ -19,9 +12,10 @@ module Economic
|
|
19
12
|
|
20
13
|
# Initialize properties in invoice_line with values from owner
|
21
14
|
def initialize_properties_with_values_from_owner(invoice_line)
|
22
|
-
|
15
|
+
if owner.is_a?(CurrentInvoice)
|
16
|
+
invoice_line.invoice = owner
|
17
|
+
end
|
23
18
|
invoice_line
|
24
19
|
end
|
25
|
-
|
26
20
|
end
|
27
21
|
end
|
@@ -5,30 +5,22 @@ module Economic
|
|
5
5
|
class CurrentInvoiceProxy < EntityProxy
|
6
6
|
include FindByDateInterval
|
7
7
|
|
8
|
-
# Returns a new, unpersisted Economic::CurrentInvoice
|
9
|
-
def build(properties = {})
|
10
|
-
invoice = super
|
11
|
-
initialize_properties_with_values_from_owner(invoice) if owner.is_a?(Debtor)
|
12
|
-
invoice
|
13
|
-
end
|
14
|
-
|
15
8
|
private
|
16
9
|
|
17
10
|
# Initialize properties in invoice with values from owner
|
18
11
|
def initialize_properties_with_values_from_owner(invoice)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
if owner.is_a?(Debtor)
|
13
|
+
invoice.debtor = owner
|
14
|
+
|
15
|
+
invoice.debtor_name ||= owner.name
|
16
|
+
invoice.debtor_address ||= owner.address
|
17
|
+
invoice.debtor_postal_code ||= owner.postal_code
|
18
|
+
invoice.debtor_city ||= owner.city
|
19
|
+
|
20
|
+
invoice.term_of_payment_handle ||= owner.term_of_payment_handle
|
21
|
+
invoice.layout_handle ||= owner.layout_handle
|
22
|
+
invoice.currency_handle ||= owner.currency_handle
|
23
|
+
end
|
31
24
|
end
|
32
|
-
|
33
25
|
end
|
34
26
|
end
|
@@ -2,63 +2,20 @@ require 'economic/proxies/entity_proxy'
|
|
2
2
|
|
3
3
|
module Economic
|
4
4
|
class DebtorContactProxy < EntityProxy
|
5
|
-
|
6
|
-
#
|
7
|
-
def build(properties = {})
|
8
|
-
contact = super
|
9
|
-
initialize_properties_with_values_from_owner(contact) if owner.is_a?(Debtor)
|
10
|
-
contact
|
11
|
-
end
|
12
|
-
|
13
|
-
# Gets data for DebtorContact from the API
|
14
|
-
def find(handle)
|
15
|
-
handle = Entity::Handle.build(:id => handle) unless handle.is_a?(Entity::Handle)
|
16
|
-
super(handle)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns DebtorContact that have the given name. The objects will only be partially loaded
|
5
|
+
# Returns DebtorContact that have the given name. The objects will only be
|
6
|
+
# partially loaded
|
20
7
|
def find_by_name(name)
|
21
|
-
|
22
|
-
response = session.request entity_class.soap_action('FindByName') do
|
23
|
-
soap.body = {
|
24
|
-
'name' => name
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# Make sure we always have an array of handles even if the result only contains one
|
29
|
-
handles = [response[:debtor_contact_handle]].flatten.reject(&:blank?)
|
30
|
-
|
31
|
-
# Create partial DebtorContact entities
|
32
|
-
contacts = handles.collect do |handle|
|
33
|
-
debtor_contact = build
|
34
|
-
debtor_contact.partial = true
|
35
|
-
debtor_contact.persisted = true
|
36
|
-
debtor_contact.handle = handle
|
37
|
-
debtor_contact.id = handle[:id]
|
38
|
-
debtor_contact.number = handle[:number]
|
39
|
-
debtor_contact
|
40
|
-
end
|
41
|
-
|
42
|
-
if owner.is_a?(Debtor)
|
43
|
-
# Scope to the owner
|
44
|
-
contacts.select do |debtor_contact|
|
45
|
-
debtor_contact.get_data
|
46
|
-
debtor_contact.debtor.handle == owner.handle
|
47
|
-
end
|
48
|
-
else
|
49
|
-
contacts
|
50
|
-
end
|
51
|
-
|
8
|
+
Proxies::Actions::FindByName.new(self, name).call
|
52
9
|
end
|
53
10
|
|
54
|
-
|
55
11
|
private
|
56
12
|
|
57
13
|
# Initialize properties in contact with values from owner. Returns contact.
|
58
14
|
def initialize_properties_with_values_from_owner(contact)
|
59
|
-
|
15
|
+
if owner.is_a?(Debtor)
|
16
|
+
contact.debtor = owner
|
17
|
+
end
|
60
18
|
contact
|
61
19
|
end
|
62
|
-
|
63
20
|
end
|
64
21
|
end
|
@@ -3,13 +3,10 @@ require 'economic/proxies/entity_proxy'
|
|
3
3
|
module Economic
|
4
4
|
class DebtorEntryProxy < EntityProxy
|
5
5
|
def find_by_invoice_number(from, to = from)
|
6
|
-
response =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:order! => [ 'from', 'to' ]
|
11
|
-
}
|
12
|
-
end
|
6
|
+
response = request('FindByInvoiceNumber', {
|
7
|
+
'from' => from,
|
8
|
+
'to' => to
|
9
|
+
})
|
13
10
|
|
14
11
|
response[:debtor_entry_handle].map do |debtor_entry_handle|
|
15
12
|
# Kinda ugly, but we get an array instead of a hash when there's only one result. :)
|
@@ -18,15 +15,13 @@ module Economic
|
|
18
15
|
end
|
19
16
|
|
20
17
|
def match(*serial_numbers)
|
21
|
-
response =
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
{ "SerialNumber" => serial_number }
|
26
|
-
}
|
18
|
+
response = request('MatchEntries', {
|
19
|
+
:entries => {
|
20
|
+
"DebtorEntryHandle" => serial_numbers.map { |serial_number|
|
21
|
+
{ "SerialNumber" => serial_number }
|
27
22
|
}
|
28
23
|
}
|
29
|
-
|
24
|
+
})
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -14,7 +14,10 @@ module Economic
|
|
14
14
|
|
15
15
|
include Enumerable
|
16
16
|
|
17
|
-
|
17
|
+
extend Forwardable
|
18
|
+
def_delegators :@items, :each, :empty?, :last, :size, :[]
|
19
|
+
|
20
|
+
attr_reader :owner
|
18
21
|
|
19
22
|
def initialize(owner)
|
20
23
|
@owner = owner
|
@@ -27,7 +30,7 @@ module Economic
|
|
27
30
|
|
28
31
|
# Fetches all entities from the API.
|
29
32
|
def all
|
30
|
-
response =
|
33
|
+
response = request(:get_all)
|
31
34
|
handles = response.values.flatten.collect { |handle| Entity::Handle.build(handle) }
|
32
35
|
|
33
36
|
if handles.size == 1
|
@@ -55,6 +58,7 @@ module Economic
|
|
55
58
|
entity.partial = false
|
56
59
|
|
57
60
|
self.append(entity)
|
61
|
+
initialize_properties_with_values_from_owner(entity)
|
58
62
|
|
59
63
|
entity
|
60
64
|
end
|
@@ -82,11 +86,9 @@ module Economic
|
|
82
86
|
def get_data(handle)
|
83
87
|
handle = Entity::Handle.new(handle)
|
84
88
|
|
85
|
-
entity_hash =
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
end
|
89
|
+
entity_hash = request(:get_data, {
|
90
|
+
'entityHandle' => handle.to_hash
|
91
|
+
})
|
90
92
|
entity_hash
|
91
93
|
end
|
92
94
|
|
@@ -96,30 +98,29 @@ module Economic
|
|
96
98
|
end
|
97
99
|
alias :<< :append
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
# Requests an action from the API endpoint
|
102
|
+
def request(action, data = nil)
|
103
|
+
session.request(entity_class.soap_action_name(action), data)
|
101
104
|
end
|
102
105
|
|
103
|
-
|
104
|
-
items.empty?
|
105
|
-
end
|
106
|
+
protected
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
items.size
|
108
|
+
def items
|
109
|
+
@items
|
110
110
|
end
|
111
111
|
|
112
|
-
protected
|
113
|
-
|
114
112
|
# Fetches all data for the given handles. Returns Array with hashes of entity data
|
115
113
|
def get_data_array(handles)
|
116
114
|
return [] unless handles && handles.any?
|
117
115
|
|
118
116
|
entity_class_name_for_soap_request = entity_class.name.split('::').last
|
119
|
-
response =
|
120
|
-
soap.body = {'entityHandles' => {"#{entity_class_name_for_soap_request}Handle" => handles.collect(&:to_hash)}}
|
121
|
-
end
|
117
|
+
response = request(:get_data_array, {'entityHandles' => {"#{entity_class_name_for_soap_request}Handle" => handles.collect(&:to_hash)}})
|
122
118
|
[response["#{entity_class.key}_data".intern]].flatten
|
123
119
|
end
|
120
|
+
|
121
|
+
# Initialize properties of entity with values from owner. Returns entity
|
122
|
+
def initialize_properties_with_values_from_owner(entity)
|
123
|
+
entity
|
124
|
+
end
|
124
125
|
end
|
125
126
|
end
|