rconomic 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +1 -2
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/economic/account.rb +2 -2
- data/lib/economic/cash_book.rb +1 -1
- data/lib/economic/cash_book_entry.rb +33 -36
- data/lib/economic/creditor.rb +2 -2
- data/lib/economic/creditor_contact.rb +3 -3
- data/lib/economic/current_invoice.rb +26 -25
- data/lib/economic/current_invoice_line.rb +17 -17
- data/lib/economic/debtor.rb +3 -3
- data/lib/economic/debtor_contact.rb +4 -4
- data/lib/economic/debtor_entry.rb +1 -2
- data/lib/economic/entity/handle.rb +30 -8
- data/lib/economic/entity.rb +23 -3
- data/lib/economic/entry.rb +1 -2
- data/lib/economic/invoice.rb +2 -2
- data/lib/economic/proxies/actions/find_by_ci_number.rb +25 -0
- data/lib/economic/proxies/actions/find_by_date_interval.rb +27 -0
- data/lib/economic/proxies/actions/find_by_handle_with_number.rb +12 -0
- data/lib/economic/proxies/actions/find_by_number.rb +21 -0
- data/lib/economic/proxies/creditor_contact_proxy.rb +1 -1
- data/lib/economic/proxies/creditor_proxy.rb +6 -53
- data/lib/economic/proxies/current_invoice_line_proxy.rb +1 -1
- data/lib/economic/proxies/current_invoice_proxy.rb +2 -17
- data/lib/economic/proxies/debtor_contact_proxy.rb +2 -2
- data/lib/economic/proxies/debtor_proxy.rb +6 -53
- data/lib/economic/proxies/entity_proxy.rb +27 -11
- data/lib/economic/proxies/invoice_proxy.rb +4 -26
- data/lib/rconomic/version.rb +1 -1
- data/spec/economic/cash_book_entry_spec.rb +8 -0
- data/spec/economic/current_invoice_line_spec.rb +27 -0
- data/spec/economic/current_invoice_spec.rb +24 -1
- data/spec/economic/entity/handle_spec.rb +53 -3
- data/spec/economic/entity_spec.rb +41 -13
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +0 -7
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +4 -9
- data/spec/economic/proxies/debtor_proxy_spec.rb +1 -1
- data/spec/economic/proxies/invoice_proxy_spec.rb +4 -9
- data/spec/fixtures/invoice_get_data_array/multiple.xml +143 -0
- data/spec/fixtures/invoice_get_data_array/single.xml +75 -0
- metadata +64 -80
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTMxZDg2MjQyNWQ5ZmY1MWIzZmI3YmFhNWZkYmJkODBjOTJkMTc1OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGYxYjM4MjI1N2E1MmM4ZWY4ZWJhZTVlMWRkOWZmM2E4MmVkNWNlMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGFlMzg5YTc1MDZhOTA2NjdjMmJlYWFjMGQzZWE4NjlkY2Y4OTJjYTQ1Yzkx
|
10
|
+
MWQ0OTY2YjRlNmZjODljZjk2ZDBiOTg0N2U1OTgwZGZhYjM2MzkyY2ExM2Nk
|
11
|
+
ZGE1NTkyZjg2NWEyNzM0MTJiMmE0NzVhOTY1ZDI0ZjhjOWNiYmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmJkOTk0MmExOTgwYmIwMGQyMGNkMjdhODUwZTY5MWY1OGQwYzNlNGJmMGNh
|
14
|
+
NjU1ZjdkYWVmNTNmYjJlYzcyZjRiZmMxYTRiNzUzZWRhODZlNWE5MzAwY2Rh
|
15
|
+
NDA3YTFlODExYjM0NjFiZGUyNjM3MDk4YjNmNTM3M2FlNWNkZGM=
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ r-conomic
|
|
3
3
|
|
4
4
|
Ruby wrapper for the [e-conomic](http://www.e-conomic.co.uk) SOAP API, that aims at making working with the API bearable.
|
5
5
|
|
6
|
-
E-conomic is a web-based accounting system. For their marketing speak, see [http://www.e-conomic.co.uk/about/](). More details about their API at [http://www.e-conomic.
|
6
|
+
E-conomic is a web-based accounting system. For their marketing speak, see [http://www.e-conomic.co.uk/about/](). More details about their API at [http://www.e-conomic.com/developer]().
|
7
7
|
|
8
8
|
[![Build Status](https://secure.travis-ci.org/lokalebasen/rconomic.png?branch=master)](http://travis-ci.org/lokalebasen/rconomic)
|
9
9
|
|
data/lib/economic/account.rb
CHANGED
data/lib/economic/cash_book.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'economic/entity'
|
2
2
|
|
3
3
|
module Economic
|
4
|
-
|
5
4
|
# Represents a cash book in E-conomic.
|
6
5
|
#
|
7
6
|
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICashBook.html
|
@@ -37,8 +36,39 @@ module Economic
|
|
37
36
|
:vat_account_handle,
|
38
37
|
:voucher_number
|
39
38
|
|
39
|
+
defaults(
|
40
|
+
:account_handle => nil,
|
41
|
+
:amount => 0,
|
42
|
+
:amount_default_currency => 0,
|
43
|
+
:bank_payment_creditor_id => nil,
|
44
|
+
:bank_payment_creditor_invoice_id => nil,
|
45
|
+
:bank_payment_type_handle => nil,
|
46
|
+
:capitalise_handle => nil,
|
47
|
+
:cash_book_handle => nil,
|
48
|
+
:contra_account_handle => nil,
|
49
|
+
:contra_vat_account_handle => nil,
|
50
|
+
:cost_type_handle => nil,
|
51
|
+
:creditor_handle => nil,
|
52
|
+
:creditor_invoice_number => nil,
|
53
|
+
:currency_handle => nil,
|
54
|
+
:date => Time.now,
|
55
|
+
:debtor_handle => nil,
|
56
|
+
:debtor_invoice_number => nil,
|
57
|
+
:department_handle => nil,
|
58
|
+
:distribution_key_handle => nil,
|
59
|
+
:due_date => nil,
|
60
|
+
:employee_handle => nil,
|
61
|
+
:end_date => nil,
|
62
|
+
:project_handle => nil,
|
63
|
+
:start_date => Time.now,
|
64
|
+
:text => "",
|
65
|
+
:type => "",
|
66
|
+
:vat_account_handle => nil,
|
67
|
+
:voucher_number => 0
|
68
|
+
)
|
69
|
+
|
40
70
|
def handle
|
41
|
-
Handle.new(:id1 => @id1, :id2 => @id2)
|
71
|
+
@handle ||= Handle.new(:id1 => @id1, :id2 => @id2)
|
42
72
|
end
|
43
73
|
|
44
74
|
protected
|
@@ -46,7 +76,7 @@ module Economic
|
|
46
76
|
def build_soap_data
|
47
77
|
data = ActiveSupport::OrderedHash.new
|
48
78
|
|
49
|
-
data['Handle'] = handle.to_hash unless handle.
|
79
|
+
data['Handle'] = handle.to_hash unless handle.empty?
|
50
80
|
data['Id1'] = id1 unless id1.blank?
|
51
81
|
data['Id2'] = id2 unless id2.blank?
|
52
82
|
data['Type'] = type unless type.blank?
|
@@ -80,38 +110,5 @@ module Economic
|
|
80
110
|
|
81
111
|
return data
|
82
112
|
end
|
83
|
-
|
84
|
-
def initialize_defaults
|
85
|
-
self.account_handle = nil
|
86
|
-
self.amount = 0
|
87
|
-
self.amount_default_currency = 0
|
88
|
-
self.bank_payment_creditor_id = nil
|
89
|
-
self.bank_payment_creditor_invoice_id = nil
|
90
|
-
self.bank_payment_type_handle = nil
|
91
|
-
self.capitalise_handle = nil
|
92
|
-
self.cash_book_handle = nil
|
93
|
-
self.contra_account_handle = nil
|
94
|
-
self.contra_vat_account_handle = nil
|
95
|
-
self.cost_type_handle = nil
|
96
|
-
self.creditor_handle = nil
|
97
|
-
self.creditor_invoice_number = nil
|
98
|
-
self.currency_handle = nil
|
99
|
-
self.date = Time.now
|
100
|
-
self.debtor_handle = nil
|
101
|
-
self.debtor_invoice_number = nil
|
102
|
-
self.department_handle = nil
|
103
|
-
self.distribution_key_handle = nil
|
104
|
-
self.due_date = nil
|
105
|
-
self.employee_handle = nil
|
106
|
-
self.end_date = nil
|
107
|
-
self.project_handle = nil
|
108
|
-
self.start_date = Time.now
|
109
|
-
self.text = ""
|
110
|
-
self.type = ""
|
111
|
-
self.vat_account_handle = nil
|
112
|
-
self.voucher_number = 0
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
113
|
end
|
117
114
|
end
|
data/lib/economic/creditor.rb
CHANGED
@@ -22,10 +22,10 @@ module Economic
|
|
22
22
|
# creditor.term_of_payment = 1
|
23
23
|
# creditor.save
|
24
24
|
class Creditor < Entity
|
25
|
-
has_properties :
|
25
|
+
has_properties :number, :creditor_group_handle, :name, :vat_zone, :currency_handle, :term_of_payment_handle, :is_accessible, :ci_number, :email, :address, :postal_code, :city, :country, :bank_account, :attention_handle, :your_reference_handle, :our_reference_handle, :default_payment_type_handle, :default_payment_creditor_id, :county, :auto_contra_account_handle
|
26
26
|
|
27
27
|
def handle
|
28
|
-
Handle.
|
28
|
+
@handle ||= Handle.build({:number => @number})
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns the Creditors contacts
|
@@ -18,10 +18,10 @@ module Economic
|
|
18
18
|
# contact.name = 'John Appleseed'
|
19
19
|
# contact.save
|
20
20
|
class CreditorContact < Entity
|
21
|
-
has_properties :
|
21
|
+
has_properties :id, :creditor_handle, :name, :number, :telephone_number, :email, :comments, :external_id
|
22
22
|
|
23
23
|
def creditor
|
24
|
-
return nil if creditor_handle.
|
24
|
+
return nil if creditor_handle.nil?
|
25
25
|
@creditor ||= session.creditors.find(creditor_handle[:number])
|
26
26
|
end
|
27
27
|
|
@@ -36,7 +36,7 @@ module Economic
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def handle
|
39
|
-
Handle.
|
39
|
+
@handle ||= Handle.build({:id => @id})
|
40
40
|
end
|
41
41
|
|
42
42
|
protected
|
@@ -28,12 +28,30 @@ module Economic
|
|
28
28
|
class CurrentInvoice < Entity
|
29
29
|
has_properties :id, :debtor_handle, :debtor_name, :debtor_address, :debtor_postal_code, :debtor_city, :debtor_country, :attention_handle, :date, :term_of_payment_handle, :due_date, :currency_handle, :exchange_rate, :is_vat_included, :layout_handle, :delivery_date, :net_amount, :vat_amount, :gross_amount, :margin, :margin_as_percent, :heading
|
30
30
|
|
31
|
+
defaults(
|
32
|
+
:id => 0,
|
33
|
+
:date => Time.now,
|
34
|
+
:term_of_payment_handle => nil,
|
35
|
+
:due_date => nil,
|
36
|
+
:currency_handle => nil,
|
37
|
+
:exchange_rate => 100, # Why am _I_ inputting this?
|
38
|
+
:is_vat_included => nil,
|
39
|
+
:layout_handle => nil,
|
40
|
+
:delivery_date => nil,
|
41
|
+
:heading => nil,
|
42
|
+
:net_amount => 0,
|
43
|
+
:vat_amount => 0,
|
44
|
+
:gross_amount => 0,
|
45
|
+
:margin => 0,
|
46
|
+
:margin_as_percent => 0 # Why do I have to input both Margin and MarginAsPercent? Shouldn't powerful Windows machines running ASP.NET be able to compute this?
|
47
|
+
)
|
48
|
+
|
31
49
|
def initialize(properties = {})
|
32
50
|
super
|
33
51
|
end
|
34
52
|
|
35
53
|
def attention
|
36
|
-
return nil if attention_handle.
|
54
|
+
return nil if attention_handle.nil?
|
37
55
|
@attention ||= session.contacts.find(attention_handle)
|
38
56
|
end
|
39
57
|
|
@@ -78,7 +96,7 @@ module Economic
|
|
78
96
|
end
|
79
97
|
|
80
98
|
def debtor
|
81
|
-
return nil if debtor_handle.
|
99
|
+
return nil if debtor_handle.nil?
|
82
100
|
@debtor ||= session.debtors.find(debtor_handle)
|
83
101
|
end
|
84
102
|
|
@@ -93,19 +111,21 @@ module Economic
|
|
93
111
|
end
|
94
112
|
|
95
113
|
def handle
|
96
|
-
Handle.new(:id => @id)
|
114
|
+
@handle ||= Handle.new(:id => @id)
|
97
115
|
end
|
98
116
|
|
99
|
-
# Returns the current invoice lines of CurrentInvoice
|
100
117
|
def lines
|
101
118
|
@lines ||= CurrentInvoiceLineProxy.new(self)
|
102
119
|
end
|
103
120
|
|
104
121
|
def save
|
122
|
+
lines = self.lines
|
123
|
+
|
105
124
|
result = super
|
106
|
-
id = result[:id]
|
125
|
+
self.id = result[:id].to_i
|
126
|
+
@handle = nil # Reset a memoized handle, leaving it up to #handle to recreate it with correct id
|
107
127
|
|
108
|
-
|
128
|
+
lines.each do |invoice_line|
|
109
129
|
invoice_line.session = session
|
110
130
|
invoice_line.invoice = self
|
111
131
|
invoice_line.save
|
@@ -114,24 +134,6 @@ module Economic
|
|
114
134
|
|
115
135
|
protected
|
116
136
|
|
117
|
-
def initialize_defaults
|
118
|
-
self.id = 0
|
119
|
-
self.date = Time.now
|
120
|
-
self.term_of_payment_handle = nil
|
121
|
-
self.due_date = nil
|
122
|
-
self.currency_handle = nil
|
123
|
-
self.exchange_rate = 100 # Why am _I_ inputting this?
|
124
|
-
self.is_vat_included = nil
|
125
|
-
self.layout_handle = nil
|
126
|
-
self.delivery_date = nil
|
127
|
-
self.heading = nil
|
128
|
-
self.net_amount = 0
|
129
|
-
self.vat_amount = 0
|
130
|
-
self.gross_amount = 0
|
131
|
-
self.margin = 0
|
132
|
-
self.margin_as_percent = 0 # Why do I have to input both Margin and MarginAsPercent? Shouldn't powerful Windows machines running ASP.NET be able to compute this?
|
133
|
-
end
|
134
|
-
|
135
137
|
# Returns OrderedHash with the properties of CurrentInvoice in the correct order, camelcased and ready
|
136
138
|
# to be sent via SOAP
|
137
139
|
def build_soap_data
|
@@ -162,7 +164,6 @@ module Economic
|
|
162
164
|
|
163
165
|
return data
|
164
166
|
end
|
165
|
-
|
166
167
|
end
|
167
168
|
|
168
169
|
end
|
@@ -9,10 +9,25 @@ module Economic
|
|
9
9
|
#
|
10
10
|
# See Economic::CurrentInvoice for usage example
|
11
11
|
class CurrentInvoiceLine < Entity
|
12
|
-
has_properties :invoice_handle, :description, :delivery_date, :unit_handle, :product_handle, :quantity, :unit_net_price, :discount_as_percent, :unit_cost_price, :total_net_amount, :total_margin, :margin_as_percent
|
12
|
+
has_properties :number, :invoice_handle, :description, :delivery_date, :unit_handle, :product_handle, :quantity, :unit_net_price, :discount_as_percent, :unit_cost_price, :total_net_amount, :total_margin, :margin_as_percent
|
13
|
+
|
14
|
+
defaults(
|
15
|
+
:invoice_handle => nil,
|
16
|
+
:description => nil,
|
17
|
+
:delivery_date => nil,
|
18
|
+
:unit_handle => nil,
|
19
|
+
:product_handle => nil,
|
20
|
+
:quantity => nil,
|
21
|
+
:unit_net_price => nil,
|
22
|
+
:discount_as_percent => 0,
|
23
|
+
:unit_cost_price => 0,
|
24
|
+
:total_net_amount => nil,
|
25
|
+
:total_margin => 0,
|
26
|
+
:margin_as_percent => 0
|
27
|
+
)
|
13
28
|
|
14
29
|
def handle
|
15
|
-
Handle.
|
30
|
+
@handle ||= Handle.build(:number => number)
|
16
31
|
end
|
17
32
|
|
18
33
|
def invoice
|
@@ -32,21 +47,6 @@ module Economic
|
|
32
47
|
|
33
48
|
protected
|
34
49
|
|
35
|
-
def initialize_defaults
|
36
|
-
self.invoice_handle = nil
|
37
|
-
self.description = nil
|
38
|
-
self.delivery_date = nil
|
39
|
-
self.unit_handle = nil
|
40
|
-
self.product_handle = nil
|
41
|
-
self.quantity = nil
|
42
|
-
self.unit_net_price = nil
|
43
|
-
self.discount_as_percent = 0
|
44
|
-
self.unit_cost_price = 0
|
45
|
-
self.total_net_amount = nil
|
46
|
-
self.total_margin = 0
|
47
|
-
self.margin_as_percent = 0
|
48
|
-
end
|
49
|
-
|
50
50
|
# Returns OrderedHash with the properties of CurrentInvoice in the correct order, camelcased and ready
|
51
51
|
# to be sent via SOAP
|
52
52
|
def build_soap_data
|
data/lib/economic/debtor.rb
CHANGED
@@ -25,10 +25,10 @@ module Economic
|
|
25
25
|
# debtor.layout_handle = { :id => 16 }
|
26
26
|
# debtor.save
|
27
27
|
class Debtor < Entity
|
28
|
-
has_properties :
|
28
|
+
has_properties :number, :debtor_group_handle, :name, :vat_zone, :currency_handle, :price_group_handle, :is_accessible, :ean, :public_entry_number, :email, :telephone_and_fax_number, :website, :address, :postal_code, :city, :country, :credit_maximum, :vat_number, :county, :ci_number, :term_of_payment_handle, :layout_handle, :attention_handle, :your_reference_handle, :our_reference_handle, :balance
|
29
29
|
|
30
30
|
def handle
|
31
|
-
Handle.new({:number => @number})
|
31
|
+
@handle ||= Handle.new({:number => @number})
|
32
32
|
end
|
33
33
|
|
34
34
|
# Returns the Debtors contacts
|
@@ -79,4 +79,4 @@ module Economic
|
|
79
79
|
|
80
80
|
end
|
81
81
|
|
82
|
-
end
|
82
|
+
end
|
@@ -18,10 +18,10 @@ module Economic
|
|
18
18
|
# contact.name = 'John Appleseed'
|
19
19
|
# contact.save
|
20
20
|
class DebtorContact < Entity
|
21
|
-
has_properties :
|
21
|
+
has_properties :id, :debtor_handle, :name, :number, :telephone_number, :email, :comments, :external_id, :is_to_receive_email_copy_of_order, :is_to_receive_email_copy_of_invoice
|
22
22
|
|
23
23
|
def debtor
|
24
|
-
return nil if debtor_handle.
|
24
|
+
return nil if debtor_handle.nil?
|
25
25
|
@debtor ||= session.debtors.find(debtor_handle[:number])
|
26
26
|
end
|
27
27
|
|
@@ -36,7 +36,7 @@ module Economic
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def handle
|
39
|
-
Handle.new({:id => @id})
|
39
|
+
@handle ||= Handle.new({:id => @id})
|
40
40
|
end
|
41
41
|
|
42
42
|
protected
|
@@ -61,4 +61,4 @@ module Economic
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
-
end
|
64
|
+
end
|
@@ -7,8 +7,7 @@ module Economic
|
|
7
7
|
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_IDebtorEntry.html
|
8
8
|
|
9
9
|
class DebtorEntry < Entity
|
10
|
-
has_properties :
|
11
|
-
:serial_number,
|
10
|
+
has_properties :serial_number,
|
12
11
|
:type,
|
13
12
|
:date,
|
14
13
|
:debtor_handle,
|
@@ -1,6 +1,19 @@
|
|
1
1
|
class Economic::Entity
|
2
2
|
class Handle
|
3
|
-
attr_accessor :id, :id1, :id2, :number
|
3
|
+
attr_accessor :id, :id1, :id2, :number, :serial_number
|
4
|
+
|
5
|
+
def self.build(options)
|
6
|
+
return options if options.is_a?(Handle)
|
7
|
+
return nil if options.nil?
|
8
|
+
new(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns true if Handle hasn't been initialized with any values yet. This
|
12
|
+
# usually happens when the handle is constructed for an entity whose id
|
13
|
+
# properties (id, number, etc) haven't been set yet.
|
14
|
+
def empty?
|
15
|
+
to_hash.empty?
|
16
|
+
end
|
4
17
|
|
5
18
|
def initialize(hash)
|
6
19
|
verify_sanity_of_arguments!(hash)
|
@@ -10,29 +23,38 @@ class Economic::Entity
|
|
10
23
|
@id1 = hash[:id1].to_i if hash[:id1]
|
11
24
|
@id2 = hash[:id2].to_i if hash[:id2]
|
12
25
|
@number = hash[:number].to_i if hash[:number]
|
26
|
+
@serial_number = hash[:serial_number].to_i if hash[:serial_number]
|
13
27
|
end
|
14
28
|
|
15
|
-
def to_hash
|
29
|
+
def to_hash(only_keys = id_properties.keys)
|
30
|
+
only_keys = [only_keys].flatten
|
16
31
|
hash = {}
|
17
|
-
hash['Id'] = id
|
18
|
-
hash['Id1'] = id1 unless id1.blank?
|
19
|
-
hash['Id2'] = id2 unless id2.blank?
|
20
|
-
hash['Number'] = number unless number.blank?
|
32
|
+
hash['Id'] = id if only_keys.include?(:id) && !id.blank?
|
33
|
+
hash['Id1'] = id1 unless id1.blank? if only_keys.include?(:id1)
|
34
|
+
hash['Id2'] = id2 unless id2.blank? if only_keys.include?(:id2)
|
35
|
+
hash['Number'] = number unless number.blank? if only_keys.include?(:number)
|
36
|
+
hash['SerialNumber'] = serial_number unless serial_number.blank? if only_keys.include?(:serial_number)
|
21
37
|
hash
|
22
38
|
end
|
23
39
|
|
24
40
|
def [](key)
|
25
|
-
{:id => @id, :id1 => @id1, :id2 => @id2, :number => @number}[key]
|
41
|
+
{:id => @id, :id1 => @id1, :id2 => @id2, :number => @number, :serial_number => @serial_number}[key]
|
26
42
|
end
|
27
43
|
|
28
44
|
def ==(other)
|
45
|
+
return true if self.object_id == other.object_id
|
29
46
|
return false if other.nil?
|
47
|
+
return false if empty? || (other.respond_to?(:empty?) && other.empty?)
|
30
48
|
return false unless other.respond_to?(:id) && other.respond_to?(:number)
|
31
49
|
self.id == other.id && self.number == other.number && self.id1 == other.id1 && self.id2 == other.id2
|
32
50
|
end
|
33
51
|
|
34
52
|
private
|
35
53
|
|
54
|
+
def id_properties
|
55
|
+
{:id => 'Id', :id1 => 'Id1', :id2 => 'Id2', :number => 'Number', :serial_number => 'SerialNumber'}
|
56
|
+
end
|
57
|
+
|
36
58
|
# Raises exceptions if hash doesn't contain values we can use to construct a new handle
|
37
59
|
def verify_sanity_of_arguments!(hash)
|
38
60
|
return if hash.is_a?(self.class)
|
@@ -42,7 +64,7 @@ class Economic::Entity
|
|
42
64
|
end
|
43
65
|
|
44
66
|
if hash.respond_to?(:keys)
|
45
|
-
unknown_keys = hash.keys -
|
67
|
+
unknown_keys = hash.keys - id_properties.keys - id_properties.values
|
46
68
|
raise ArgumentError.new("Unknown keys in handle: #{unknown_keys.inspect}") unless unknown_keys.empty?
|
47
69
|
|
48
70
|
not_to_iable = hash.select { |k, v| !v.respond_to?(:to_i) }
|
data/lib/economic/entity.rb
CHANGED
@@ -6,6 +6,16 @@ module Economic
|
|
6
6
|
attr_accessor :persisted, :session, :partial
|
7
7
|
|
8
8
|
class << self
|
9
|
+
# Sets default property values that an entity should be initialized with
|
10
|
+
def defaults(default_values)
|
11
|
+
@default_values = default_values
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the default values for properties
|
15
|
+
def default_values
|
16
|
+
@default_values || {}
|
17
|
+
end
|
18
|
+
|
9
19
|
def properties_not_triggering_full_load
|
10
20
|
[:id, :number, :handle]
|
11
21
|
end
|
@@ -13,7 +23,7 @@ module Economic
|
|
13
23
|
def has_properties(*properties)
|
14
24
|
@properties = properties
|
15
25
|
properties.each do |property|
|
16
|
-
unless properties_not_triggering_full_load.include?(property)
|
26
|
+
unless properties_not_triggering_full_load.include?(property)
|
17
27
|
# Create property accessors that loads the full Entity from the API if necessary
|
18
28
|
define_method "#{property}" do
|
19
29
|
value = instance_variable_get("@#{property}")
|
@@ -61,7 +71,11 @@ module Economic
|
|
61
71
|
end
|
62
72
|
|
63
73
|
def handle
|
64
|
-
Handle.
|
74
|
+
@handle ||= Handle.build({:number => @number, :id => @id})
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle=(handle)
|
78
|
+
@handle = Handle.build(handle)
|
65
79
|
end
|
66
80
|
|
67
81
|
def initialize(properties = {})
|
@@ -173,6 +187,10 @@ module Economic
|
|
173
187
|
return response
|
174
188
|
end
|
175
189
|
|
190
|
+
def defaults
|
191
|
+
self.class.default_values
|
192
|
+
end
|
193
|
+
|
176
194
|
def update
|
177
195
|
response = session.request soap_action(:update_from_data) do
|
178
196
|
soap.body = {'data' => build_soap_data}
|
@@ -201,7 +219,9 @@ module Economic
|
|
201
219
|
end
|
202
220
|
|
203
221
|
def initialize_defaults
|
204
|
-
|
222
|
+
defaults.each do |property_name, default_value|
|
223
|
+
self.send("#{property_name}=", default_value)
|
224
|
+
end
|
205
225
|
end
|
206
226
|
end
|
207
227
|
|
data/lib/economic/entry.rb
CHANGED
@@ -7,8 +7,7 @@ module Economic
|
|
7
7
|
# API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_IEntry.html
|
8
8
|
|
9
9
|
class Entry < Entity
|
10
|
-
has_properties :
|
11
|
-
:serial_number,
|
10
|
+
has_properties :serial_number,
|
12
11
|
:account_handle,
|
13
12
|
:amount,
|
14
13
|
:amount_default_currency,
|
data/lib/economic/invoice.rb
CHANGED
@@ -5,7 +5,7 @@ module Economic
|
|
5
5
|
has_properties :number, :net_amount, :vat_amount, :due_date, :debtor_handle, :debtor_name, :debtor_name, :debtor_address, :debtor_postal_code, :debtor_city, :debtor_country, :debtor_ean, :attention_handle, :heading
|
6
6
|
|
7
7
|
def attention
|
8
|
-
return nil if attention_handle.
|
8
|
+
return nil if attention_handle.nil?
|
9
9
|
@attention ||= session.contacts.find(attention_handle)
|
10
10
|
end
|
11
11
|
|
@@ -20,7 +20,7 @@ module Economic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def debtor
|
23
|
-
return nil if debtor_handle.
|
23
|
+
return nil if debtor_handle.nil?
|
24
24
|
@debtor ||= session.debtors.find(debtor_handle)
|
25
25
|
end
|
26
26
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FindByCiNumber
|
2
|
+
# Returns Debtors that have the given ci_number. The Debtor objects will only be partially loaded
|
3
|
+
def find_by_ci_number(ci_number)
|
4
|
+
# Get a list of handles from e-conomic
|
5
|
+
response = session.request entity_class.soap_action('FindByCINumber') do
|
6
|
+
soap.body = {
|
7
|
+
'ciNumber' => ci_number
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Make sure we always have an array of handles even if the result only contains one
|
12
|
+
handle_key = "#{entity_class_name.downcase}_handle".intern
|
13
|
+
handles = [response[handle_key]].flatten.reject(&:blank?)
|
14
|
+
|
15
|
+
# Create partial Debtor entities
|
16
|
+
handles.collect do |handle|
|
17
|
+
entity = build
|
18
|
+
entity.partial = true
|
19
|
+
entity.persisted = true
|
20
|
+
entity.handle = handle
|
21
|
+
entity.number = handle[:number]
|
22
|
+
entity
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Economic
|
2
|
+
module FindByDateInterval
|
3
|
+
|
4
|
+
# Returns entity objects for a given interval of days.
|
5
|
+
def find_by_date_interval(from, unto)
|
6
|
+
response = session.request entity_class.soap_action("FindByDateInterval") do
|
7
|
+
soap.body = {
|
8
|
+
'first' => from.iso8601,
|
9
|
+
'last' => unto.iso8601,
|
10
|
+
:order! => ['first', 'last']
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
handle_key = "#{Support::String.underscore(entity_class_name)}_handle".intern
|
15
|
+
handles = [ response[handle_key] ].flatten.reject(&:blank?).collect do |handle|
|
16
|
+
Entity::Handle.build(handle)
|
17
|
+
end
|
18
|
+
|
19
|
+
get_data_array(handles).collect do |entity_hash|
|
20
|
+
entity = build(entity_hash)
|
21
|
+
entity.persisted = true
|
22
|
+
entity
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Use FindByHandleWithNumber when the SOAP action to find entity requires
|
2
|
+
# `Number` to be passed rather than the default `Id`
|
3
|
+
module FindByHandleWithNumber
|
4
|
+
def find(handle)
|
5
|
+
handle = if handle.respond_to?(:to_i)
|
6
|
+
Economic::Entity::Handle.build(:number => handle.to_i)
|
7
|
+
else
|
8
|
+
Economic::Entity::Handle.build(handle)
|
9
|
+
end
|
10
|
+
super(handle)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module FindByNumber
|
2
|
+
# Returns handle with a given number.
|
3
|
+
def find_by_number(number)
|
4
|
+
response = session.request(entity_class.soap_action('FindByNumber')) do
|
5
|
+
soap.body = {
|
6
|
+
'number' => number
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
if response == {}
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
entity = build
|
14
|
+
entity.partial = true
|
15
|
+
entity.persisted = true
|
16
|
+
entity.handle = response
|
17
|
+
entity.number = response[:number].to_i
|
18
|
+
entity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -12,7 +12,7 @@ module Economic
|
|
12
12
|
|
13
13
|
# Gets data for CreditorContact from the API
|
14
14
|
def find(handle)
|
15
|
-
handle = Entity::Handle.
|
15
|
+
handle = Entity::Handle.build(:id => handle) unless handle.is_a?(Entity::Handle)
|
16
16
|
super(handle)
|
17
17
|
end
|
18
18
|
|