invoicexpress 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +0 -0
- data/README.md +322 -0
- data/Rakefile +19 -0
- data/invoicexpress.gemspec +26 -0
- data/lib/faraday/response/parse_xml.rb +23 -0
- data/lib/faraday/response/raise_invoicexpress_errors.rb +20 -0
- data/lib/invoicexpress.rb +26 -0
- data/lib/invoicexpress/authentication.rb +15 -0
- data/lib/invoicexpress/client.rb +56 -0
- data/lib/invoicexpress/client/cash_invoices.rb +110 -0
- data/lib/invoicexpress/client/charts.rb +57 -0
- data/lib/invoicexpress/client/clients.rb +215 -0
- data/lib/invoicexpress/client/credit_notes.rb +128 -0
- data/lib/invoicexpress/client/debit_notes.rb +129 -0
- data/lib/invoicexpress/client/invoices.rb +107 -0
- data/lib/invoicexpress/client/items.rb +82 -0
- data/lib/invoicexpress/client/purchase_orders.rb +126 -0
- data/lib/invoicexpress/client/schedules.rb +110 -0
- data/lib/invoicexpress/client/sequences.rb +71 -0
- data/lib/invoicexpress/client/simplified_invoices.rb +130 -0
- data/lib/invoicexpress/client/taxes.rb +82 -0
- data/lib/invoicexpress/client/users.rb +48 -0
- data/lib/invoicexpress/configuration.rb +51 -0
- data/lib/invoicexpress/connection.rb +40 -0
- data/lib/invoicexpress/error.rb +68 -0
- data/lib/invoicexpress/models.rb +29 -0
- data/lib/invoicexpress/models/chart.rb +41 -0
- data/lib/invoicexpress/models/client.rb +24 -0
- data/lib/invoicexpress/models/filter.rb +60 -0
- data/lib/invoicexpress/models/invoice.rb +235 -0
- data/lib/invoicexpress/models/purchase_order.rb +72 -0
- data/lib/invoicexpress/models/quarterly_result.rb +45 -0
- data/lib/invoicexpress/models/schedule.rb +87 -0
- data/lib/invoicexpress/models/sequence.rb +17 -0
- data/lib/invoicexpress/models/supplier.rb +17 -0
- data/lib/invoicexpress/models/top_client.rb +15 -0
- data/lib/invoicexpress/models/top_debtor.rb +14 -0
- data/lib/invoicexpress/models/user.rb +31 -0
- data/lib/invoicexpress/request.rb +63 -0
- data/lib/invoicexpress/version.rb +3 -0
- data/spec/fixtures/charts.invoicing.xml +21 -0
- data/spec/fixtures/charts.quarterly-results.xml +25 -0
- data/spec/fixtures/charts.top-clients.xml +10 -0
- data/spec/fixtures/charts.top-debtors.xml +10 -0
- data/spec/fixtures/charts.treasury.xml +49 -0
- data/spec/fixtures/clients.create.xml +6 -0
- data/spec/fixtures/clients.get.xml +21 -0
- data/spec/fixtures/clients.invoices.xml +11 -0
- data/spec/fixtures/clients.list.xml +18 -0
- data/spec/fixtures/clients.update.xml +1 -0
- data/spec/fixtures/credit_notes.create.xml +53 -0
- data/spec/fixtures/credit_notes.email_document.xml +9 -0
- data/spec/fixtures/credit_notes.list.xml +114 -0
- data/spec/fixtures/credit_notes.update_state.xml +7 -0
- data/spec/fixtures/invoices.create.xml +37 -0
- data/spec/fixtures/invoices.get.xml +50 -0
- data/spec/fixtures/invoices.list.xml +537 -0
- data/spec/fixtures/invoices.update_state.xml +7 -0
- data/spec/fixtures/ok.xml +0 -0
- data/spec/fixtures/po.create.xml +42 -0
- data/spec/fixtures/po.email_document.xml +0 -0
- data/spec/fixtures/po.get.xml +42 -0
- data/spec/fixtures/po.list.xml +44 -0
- data/spec/fixtures/po.update_state.xml +7 -0
- data/spec/fixtures/schedules.create.xml +48 -0
- data/spec/fixtures/schedules.get.xml +57 -0
- data/spec/fixtures/schedules.list.xml +40 -0
- data/spec/fixtures/sequences.create.xml +9 -0
- data/spec/fixtures/sequences.get.xml +10 -0
- data/spec/fixtures/sequences.list.xml +12 -0
- data/spec/fixtures/sequences.update.xml +10 -0
- data/spec/fixtures/simplified_invoices.create.xml +53 -0
- data/spec/fixtures/simplified_invoices.email_document.xml +9 -0
- data/spec/fixtures/simplified_invoices.get.xml +74 -0
- data/spec/fixtures/simplified_invoices.list.xml +114 -0
- data/spec/fixtures/simplified_invoices.update.xml +0 -0
- data/spec/fixtures/simplified_invoices.update_state.xml +7 -0
- data/spec/fixtures/taxes.create.xml +7 -0
- data/spec/fixtures/taxes.list.xml +18 -0
- data/spec/fixtures/taxes.update.xml +7 -0
- data/spec/fixtures/users.accounts.xml +12 -0
- data/spec/fixtures/users.change-account.xml +0 -0
- data/spec/fixtures/users.login.xml +11 -0
- data/spec/helper.rb +62 -0
- data/spec/invoicexpress/client/charts_spec.rb +69 -0
- data/spec/invoicexpress/client/clients_spec.rb +108 -0
- data/spec/invoicexpress/client/credit_notes_spec.rb +104 -0
- data/spec/invoicexpress/client/invoices_spec.rb +110 -0
- data/spec/invoicexpress/client/purchase_orders_spec.rb +116 -0
- data/spec/invoicexpress/client/schedules_spec.rb +111 -0
- data/spec/invoicexpress/client/sequences_spec.rb +68 -0
- data/spec/invoicexpress/client/simplified_invoices_spec.rb +116 -0
- data/spec/invoicexpress/client/taxes_spec.rb +70 -0
- data/spec/invoicexpress/client/users_spec.rb +40 -0
- data/spec/invoicexpress/client_spec.rb +24 -0
- data/spec/invoicexpress_spec.rb +19 -0
- metadata +279 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<simplified_invoices>
|
3
|
+
<results>
|
4
|
+
<current_page>1</current_page>
|
5
|
+
<entries>2</entries>
|
6
|
+
<total_entries>2</total_entries>
|
7
|
+
</results>
|
8
|
+
<simplified_invoice>
|
9
|
+
<id>1425061</id>
|
10
|
+
<status>settled</status>
|
11
|
+
<archived>false</archived>
|
12
|
+
<type>SimplifiedInvoice</type>
|
13
|
+
<sequence_number>1/2013</sequence_number>
|
14
|
+
<date>01/05/2013</date>
|
15
|
+
<reference></reference>
|
16
|
+
<observations>Artigo 16º nº 6 do CIVA. </observations>
|
17
|
+
<retention></retention>
|
18
|
+
<permalink>http://www.invoicexpress.net/documents/9c21e2aa2fd5a9f999673bc993407a562177fecb</permalink>
|
19
|
+
<client>
|
20
|
+
<id>550611</id>
|
21
|
+
<name>Pedro Sousa</name>
|
22
|
+
<email>psousa@thinkorange.pt</email>
|
23
|
+
<address>Rua Luisa de Camões 18</address>
|
24
|
+
<postal_code>1231-123</postal_code>
|
25
|
+
<country>Portugal</country>
|
26
|
+
<fiscal_id>210533382</fiscal_id>
|
27
|
+
</client>
|
28
|
+
<currency>Euro</currency>
|
29
|
+
<items type="array">
|
30
|
+
<item>
|
31
|
+
<name>Item 1</name>
|
32
|
+
<description></description>
|
33
|
+
<unit_price>60.0</unit_price>
|
34
|
+
<unit>unit</unit>
|
35
|
+
<quantity>2.0</quantity>
|
36
|
+
<tax>
|
37
|
+
<name></name>
|
38
|
+
<value>0.0</value>
|
39
|
+
</tax>
|
40
|
+
<discount>0.0</discount>
|
41
|
+
</item>
|
42
|
+
<item>
|
43
|
+
<name>Item 2</name>
|
44
|
+
<description></description>
|
45
|
+
<unit_price>50.0</unit_price>
|
46
|
+
<unit>unit</unit>
|
47
|
+
<quantity>1.0</quantity>
|
48
|
+
<tax>
|
49
|
+
<name></name>
|
50
|
+
<value>0.0</value>
|
51
|
+
</tax>
|
52
|
+
<discount>0.0</discount>
|
53
|
+
</item>
|
54
|
+
</items>
|
55
|
+
<sum>170.0</sum>
|
56
|
+
<discount>0.0</discount>
|
57
|
+
<before_taxes>170.0</before_taxes>
|
58
|
+
<taxes>0.0</taxes>
|
59
|
+
<total>170.0</total>
|
60
|
+
</simplified_invoice>
|
61
|
+
<simplified_invoice>
|
62
|
+
<id>1425061</id>
|
63
|
+
<status>settled</status>
|
64
|
+
<archived>false</archived>
|
65
|
+
<type>SimplifiedInvoice</type>
|
66
|
+
<sequence_number>1/2013</sequence_number>
|
67
|
+
<date>01/05/2013</date>
|
68
|
+
<reference></reference>
|
69
|
+
<observations>Artigo 16º nº 6 do CIVA. </observations>
|
70
|
+
<retention></retention>
|
71
|
+
<permalink>http://www.invoicexpress.net/documents/9c21e2aa2fd5a9f999673bc993407a562177fecb</permalink>
|
72
|
+
<client>
|
73
|
+
<id>550611</id>
|
74
|
+
<name>Pedro Sousa</name>
|
75
|
+
<email>psousa@thinkorange.pt</email>
|
76
|
+
<address>Rua Luisa de Camões 18</address>
|
77
|
+
<postal_code>1231-123</postal_code>
|
78
|
+
<country>Portugal</country>
|
79
|
+
<fiscal_id>210533382</fiscal_id>
|
80
|
+
</client>
|
81
|
+
<currency>Euro</currency>
|
82
|
+
<items type="array">
|
83
|
+
<item>
|
84
|
+
<name>Item 1</name>
|
85
|
+
<description></description>
|
86
|
+
<unit_price>60.0</unit_price>
|
87
|
+
<unit>unit</unit>
|
88
|
+
<quantity>2.0</quantity>
|
89
|
+
<tax>
|
90
|
+
<name></name>
|
91
|
+
<value>0.0</value>
|
92
|
+
</tax>
|
93
|
+
<discount>0.0</discount>
|
94
|
+
</item>
|
95
|
+
<item>
|
96
|
+
<name>Item 2</name>
|
97
|
+
<description></description>
|
98
|
+
<unit_price>50.0</unit_price>
|
99
|
+
<unit>unit</unit>
|
100
|
+
<quantity>1.0</quantity>
|
101
|
+
<tax>
|
102
|
+
<name></name>
|
103
|
+
<value>0.0</value>
|
104
|
+
</tax>
|
105
|
+
<discount>0.0</discount>
|
106
|
+
</item>
|
107
|
+
</items>
|
108
|
+
<sum>170.0</sum>
|
109
|
+
<discount>0.0</discount>
|
110
|
+
<before_taxes>170.0</before_taxes>
|
111
|
+
<taxes>0.0</taxes>
|
112
|
+
<total>170.0</total>
|
113
|
+
</simplified_invoice>
|
114
|
+
</simplified_invoices>
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<taxes>
|
3
|
+
<tax>
|
4
|
+
<id>1</id>
|
5
|
+
<name>IVA20</name>
|
6
|
+
<value>20</value>
|
7
|
+
<region>PT</region>
|
8
|
+
<default_tax>1</default_tax>
|
9
|
+
<!-- default tax -->
|
10
|
+
</tax>
|
11
|
+
<tax>
|
12
|
+
<id>2</id>
|
13
|
+
<name>IVA21</name>
|
14
|
+
<value>21</value>
|
15
|
+
<region>PT</region>
|
16
|
+
<default_tax>0</default_tax>
|
17
|
+
</tax>
|
18
|
+
</taxes>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<accounts>
|
3
|
+
<account>
|
4
|
+
<id>13233</id>
|
5
|
+
<name>thinkorangeteste</name>
|
6
|
+
<url>https://thinkorangeteste.invoicexpress.net</url>
|
7
|
+
<api_key>xptoxpto</api_key>
|
8
|
+
<country>Portugal</country>
|
9
|
+
<state>active</state>
|
10
|
+
<blocked>false</blocked>
|
11
|
+
</account>
|
12
|
+
</accounts>
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<accounts>
|
3
|
+
<account>
|
4
|
+
<id>13233</id>
|
5
|
+
<name>thinkorangeteste</name>
|
6
|
+
<url>https://thinkorangeteste.invoicexpress.net</url>
|
7
|
+
<api_key>xptoxpto</api_key>
|
8
|
+
<state>active</state>
|
9
|
+
<blocked>false</blocked>
|
10
|
+
</account>
|
11
|
+
</accounts>
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
if ENV['COVERAGE']
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/spec"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'invoicexpress'
|
10
|
+
require 'rspec'
|
11
|
+
require 'webmock/rspec'
|
12
|
+
|
13
|
+
def stub_get(url)
|
14
|
+
stub_request(:get, invoicexpress_url(url))
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_post(url)
|
18
|
+
stub_request(:post, invoicexpress_url(url))
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_put(url)
|
22
|
+
stub_request(:put, invoicexpress_url(url))
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_delete(url)
|
26
|
+
stub_request(:delete, invoicexpress_url(url))
|
27
|
+
end
|
28
|
+
|
29
|
+
def fixture_path
|
30
|
+
File.expand_path("../fixtures", __FILE__)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fixture(file)
|
34
|
+
File.new(fixture_path + "/" + file)
|
35
|
+
end
|
36
|
+
|
37
|
+
def empty_xml_response
|
38
|
+
{
|
39
|
+
:body => "",
|
40
|
+
:headers => {
|
41
|
+
:content_type => "application/xml; charset=utf-8"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def xml_response(file)
|
47
|
+
{
|
48
|
+
:body => fixture(file),
|
49
|
+
:headers => {
|
50
|
+
:content_type => "application/xml; charset=utf-8"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def invoicexpress_url(url)
|
56
|
+
if url =~ /^http/
|
57
|
+
url
|
58
|
+
else
|
59
|
+
"https://thinkorangeteste.invoicexpress.net#{url}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Invoicexpress::Client::Charts do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".invoicing_chart" do
|
10
|
+
it "Returns the invoicing chart data." do
|
11
|
+
stub_get("/api/charts/invoicing.xml").
|
12
|
+
to_return(xml_response("charts.invoicing.xml"))
|
13
|
+
|
14
|
+
chart = @client.invoicing_chart
|
15
|
+
chart.series.values.count.should == 6
|
16
|
+
chart.graphs.first.values.count.should == 6
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".treasury_chart" do
|
21
|
+
it "Returns the treasury chart data." do
|
22
|
+
stub_get("/api/charts/treasury.xml").
|
23
|
+
to_return(xml_response("charts.treasury.xml"))
|
24
|
+
|
25
|
+
chart = @client.treasury_chart
|
26
|
+
#all there
|
27
|
+
chart.series.values.count.should == 7
|
28
|
+
#4 graphs
|
29
|
+
chart.graphs.count.should ==4
|
30
|
+
#count values
|
31
|
+
chart.graphs.first.values.count.should ==7
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".top_clients" do
|
37
|
+
it "Returns the top 5 clients." do
|
38
|
+
stub_get("/api/charts/top-clients.xml").
|
39
|
+
to_return(xml_response("charts.top-clients.xml"))
|
40
|
+
|
41
|
+
chart = @client.top_clients
|
42
|
+
chart.clients.first.name.should =="Ruben Fonseca"
|
43
|
+
chart.clients.size.should ==1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".top_debtors" do
|
48
|
+
it "Returns the top 5 debtors." do
|
49
|
+
stub_get("/api/charts/top-debtors.xml").
|
50
|
+
to_return(xml_response("charts.top-debtors.xml"))
|
51
|
+
|
52
|
+
chart = @client.top_debtors
|
53
|
+
chart.clients.size.should ==1
|
54
|
+
chart.clients.first.name.should =="Ruben Fonseca"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".quarterly_results" do
|
59
|
+
it "return all the quarterly results." do
|
60
|
+
stub_get("/api/charts/quarterly-results.xml?year=2010").
|
61
|
+
to_return(xml_response("charts.quarterly-results.xml"))
|
62
|
+
|
63
|
+
list = @client.quarterly_results(2010)
|
64
|
+
list.quarter01.invoicing.should ==60.0
|
65
|
+
list.year.should ==2010
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Invoicexpress::Client::Clients do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".clients" do
|
10
|
+
it "returns all the clients" do
|
11
|
+
stub_get("/clients.xml?per_page=30&page=1").
|
12
|
+
to_return(xml_response("clients.list.xml"))
|
13
|
+
|
14
|
+
list = @client.clients
|
15
|
+
list.count.should == 1
|
16
|
+
list.first.name.should == "Ruben Fonseca"
|
17
|
+
list.first.email.should == "fonseka@gmail.com"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".create_client" do
|
22
|
+
it "creates a new client" do
|
23
|
+
stub_post("/clients.xml").
|
24
|
+
to_return(xml_response("clients.create.xml"))
|
25
|
+
|
26
|
+
model_client = Invoicexpress::Models::Client.new({
|
27
|
+
:name => "Ruben Fonseca",
|
28
|
+
:email => "fonseka@gmail.com"
|
29
|
+
})
|
30
|
+
|
31
|
+
new_client = @client.create_client(model_client)
|
32
|
+
new_client.name.should == "Ruben Fonseca"
|
33
|
+
new_client.email.should == "fonseka@gmail.com"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises if no client is passed" do
|
37
|
+
expect {
|
38
|
+
@client.create_client(nil)
|
39
|
+
}.to raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises if the client has no name" do
|
43
|
+
expect {
|
44
|
+
@client.create_client(Invoicexpress::Models::Client.new)
|
45
|
+
}.to raise_error(ArgumentError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".update_client" do
|
50
|
+
it "updates the client" do
|
51
|
+
stub_put("/clients/123.xml").
|
52
|
+
to_return(xml_response("clients.update.xml"))
|
53
|
+
|
54
|
+
model = Invoicexpress::Models::Client.new(:id => 123)
|
55
|
+
|
56
|
+
expect { @client.update_client(model) }.to_not raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it "raises if no client is passed" do
|
60
|
+
expect {
|
61
|
+
@client.update_client(nil)
|
62
|
+
}.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises if the client to update has no id" do
|
66
|
+
expect {
|
67
|
+
@client.update_client(Invoicexpress::Models::Client.new)
|
68
|
+
}.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".client" do
|
73
|
+
it "gets a client" do
|
74
|
+
stub_get("/clients/1.xml").
|
75
|
+
to_return(xml_response("clients.get.xml"))
|
76
|
+
|
77
|
+
c = @client.client(1)
|
78
|
+
c.name.should == "Bruce Norris"
|
79
|
+
c.code.should == 1337
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ".client_invoices" do
|
84
|
+
it "gets the client's invoices" do
|
85
|
+
stub_post("/clients/1/invoices.xml").
|
86
|
+
to_return(xml_response("clients.invoices.xml"))
|
87
|
+
|
88
|
+
invoices = @client.client_invoices(1)
|
89
|
+
invoices.results.entries.should == 0
|
90
|
+
invoices.results.total_entries == 0
|
91
|
+
end
|
92
|
+
|
93
|
+
it "gets the client's invoices with filters" do
|
94
|
+
filter = Invoicexpress::Models::Filter.new({
|
95
|
+
:status => [:draft, :final],
|
96
|
+
:by_type => ["Receipt"],
|
97
|
+
:archived => [:non_archived]
|
98
|
+
})
|
99
|
+
|
100
|
+
stub_post("/clients/1/invoices.xml").
|
101
|
+
to_return(xml_response("clients.invoices.xml"))
|
102
|
+
|
103
|
+
invoices = @client.client_invoices(1, filter)
|
104
|
+
invoices.results.entries.should == 0
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Invoicexpress::Client::CreditNotes do
|
4
|
+
before do
|
5
|
+
@client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".credit_notes" do
|
9
|
+
it "Returns all the credit notes" do
|
10
|
+
stub_get("/credit_notes.xml?page=1").
|
11
|
+
to_return(xml_response("credit_notes.list.xml"))
|
12
|
+
|
13
|
+
credit_notes = @client.credit_notes
|
14
|
+
credit_notes.count.should == 2
|
15
|
+
credit_notes.first.id == 1415679
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".create_credit_note" do
|
20
|
+
it "creates a new credit note" do
|
21
|
+
stub_post("/credit_notes.xml").
|
22
|
+
to_return(xml_response("credit_notes.create.xml"))
|
23
|
+
|
24
|
+
|
25
|
+
cnote = Invoicexpress::Models::CreditNote.new(
|
26
|
+
:date => Date.new(2013, 5, 1),
|
27
|
+
:due_date => Date.new(2013, 6, 1),
|
28
|
+
:tax_exemption => "M01",
|
29
|
+
:client => Invoicexpress::Models::Client.new(
|
30
|
+
:name => "Pedro Sousa"
|
31
|
+
),
|
32
|
+
:items => [
|
33
|
+
Invoicexpress::Models::Item.new(
|
34
|
+
:name => "Item 1",
|
35
|
+
:unit_price => 60,
|
36
|
+
:quantity => 2,
|
37
|
+
:unit => "unit",
|
38
|
+
),
|
39
|
+
Invoicexpress::Models::Item.new(
|
40
|
+
:name => "Item 2",
|
41
|
+
:unit_price => 50,
|
42
|
+
:quantity => 1,
|
43
|
+
:unit => "unit",
|
44
|
+
)
|
45
|
+
]
|
46
|
+
)
|
47
|
+
|
48
|
+
cnote = @client.create_credit_note(cnote)
|
49
|
+
cnote.id.should == 1423940
|
50
|
+
cnote.status == "draft"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".update_credit_note" do
|
55
|
+
it "updates the credit note" do
|
56
|
+
stub_put("/credit_notes/1423940.xml").
|
57
|
+
to_return(xml_response("ok.xml"))
|
58
|
+
|
59
|
+
model = Invoicexpress::Models::CreditNote.new(:id => 1423940)
|
60
|
+
expect { @client.update_credit_note(model) }.to_not raise_error
|
61
|
+
end
|
62
|
+
it "raises if no credit note is passed" do
|
63
|
+
expect {
|
64
|
+
@client.update_credit_note(nil)
|
65
|
+
}.to raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
it "raises if the credit_note to update has no id" do
|
68
|
+
stub_put("/credit_notes/.xml").
|
69
|
+
to_return(xml_response("ok.xml"))
|
70
|
+
expect {
|
71
|
+
@client.update_credit_note(Invoicexpress::Models::CreditNote.new)
|
72
|
+
}.to raise_error(ArgumentError)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ".update_credit_note_state" do
|
77
|
+
it "updates the state" do
|
78
|
+
stub_put("/credit_notes/1423940/change-state.xml").
|
79
|
+
to_return(xml_response("credit_notes.update_state.xml"))
|
80
|
+
|
81
|
+
state = Invoicexpress::Models::InvoiceState.new(
|
82
|
+
:state => "finalized"
|
83
|
+
)
|
84
|
+
expect { cnote = @client.update_credit_note_state(1423940, state) }.to_not raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe ".credit_note_mail" do
|
89
|
+
it "sends the credit note through email" do
|
90
|
+
stub_put("/credit_notes/1423940/email-document.xml").
|
91
|
+
to_return(xml_response("credit_notes.email_document.xml"))
|
92
|
+
|
93
|
+
message = Invoicexpress::Models::Message.new(
|
94
|
+
:subject => "Hello world",
|
95
|
+
:body => "Here is the invoice.",
|
96
|
+
:client => Invoicexpress::Models::Client.new(
|
97
|
+
:name => "Pedro Sousa",
|
98
|
+
:email=> 'psousa@thinkorange.pt'
|
99
|
+
)
|
100
|
+
)
|
101
|
+
expect { cnote = @client.credit_note_mail(1423940, message) }.to_not raise_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|