sk-api 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/resources/credit_note.rb +1 -1
- data/lib/resources/invoice.rb +49 -0
- data/lib/sk_api.rb +1 -0
- data/spec/resources/invoice_spec.rb +121 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
@@ -31,7 +31,7 @@ module SKApi
|
|
31
31
|
"price_tax" => {"type" => "number", "optional" => true, "readonly" => true},
|
32
32
|
"created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true},
|
33
33
|
"updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true},
|
34
|
-
"address_field" => {"type" => "string", "optional" => true
|
34
|
+
"address_field" => {"type" => "string", "optional" => true},
|
35
35
|
"lock_version" => {"type" => "integer", "optional" => true, "readonly" => true},
|
36
36
|
"client_id" => {"type" => "string"},
|
37
37
|
"client" => {"type" => "object", "properties" => SKApi::Resources::Client.schema_props, "optional" => true, "readonly" => true},
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SKApi
|
2
|
+
module Resources
|
3
|
+
class Invoice < SKApi::Resources::Base
|
4
|
+
|
5
|
+
def save
|
6
|
+
save_with_validation
|
7
|
+
end
|
8
|
+
|
9
|
+
##########################################################################
|
10
|
+
# Class methods
|
11
|
+
##########################################################################
|
12
|
+
|
13
|
+
def self.schema
|
14
|
+
{ "type" => "object",
|
15
|
+
"properties" => SKApi::Resources::Invoice.schema_props}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.schema_props
|
19
|
+
{
|
20
|
+
"id" => {"type" => "string", "identity" => true, "optional" => true, "readonly" => true},
|
21
|
+
"number" => {"type" => "string", "optional" => true},
|
22
|
+
"date" => {"type" => "string", "format" =>"date", "optional" => true},
|
23
|
+
"due_days" => {"type" => "integer", "optional" => true},
|
24
|
+
"title" => {"type" => "string", "optional" => true},
|
25
|
+
"status" => {"type" => "string", "enum" => ["draft", "open", "closed"], "default" =>"draft", "optional" => true},
|
26
|
+
"payment_method" => {"type" => "string", "enum" => ["cash", "bank_transfer", "credit_card", "paypal", "direct_debit", "cheque"], "optional" => true},
|
27
|
+
"due_date" => {"type" => "string", "format" =>"date", "optional" => true},
|
28
|
+
"notes_before" => {"type" => "string", "optional" => true},
|
29
|
+
"notes_after" => {"type" => "string", "optional" => true},
|
30
|
+
"price_total" => {"type" => "number", "optional" => true, "readonly" => true},
|
31
|
+
"price_tax" => {"type" => "number", "optional" => true, "readonly" => true},
|
32
|
+
"created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true},
|
33
|
+
"updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true},
|
34
|
+
"address_field" => {"type" => "string", "optional" => true},
|
35
|
+
"lock_version" => {"type" => "integer", "optional" => true, "readonly" => true},
|
36
|
+
"client_id" => {"type" => "string"},
|
37
|
+
"client" => {"type" => "object", "properties" => SKApi::Resources::Client.schema_props, "optional" => true, "readonly" => true},
|
38
|
+
"line_items" => {"type" => "array","properties" => SKApi::Resources::LineItem.schema_props, "optional" => true,},
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.api_links
|
43
|
+
#internal links on fields=> id => salesking.eu/clients/4567.json
|
44
|
+
#external links to actions and related objects => invoeis => salesking.eu/clients/4567/invoices.json
|
45
|
+
[:edit, :destroy, :copy, :print, :show, :payments, :payment_new]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/sk_api.rb
CHANGED
@@ -27,5 +27,6 @@ require File.dirname(__FILE__) + '/resources/base'
|
|
27
27
|
require File.dirname(__FILE__) + '/resources/product'
|
28
28
|
require File.dirname(__FILE__) + '/resources/client'
|
29
29
|
require File.dirname(__FILE__) + '/resources/address'
|
30
|
+
require File.dirname(__FILE__) + '/resources/invoice'
|
30
31
|
require File.dirname(__FILE__) + '/resources/credit_note'
|
31
32
|
require File.dirname(__FILE__) + '/resources/line_item'
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
describe SKApi::Resources::Invoice, "in general" do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
#setup test doc to work with
|
7
|
+
# create client
|
8
|
+
@client = SKApi::Resources::Client.new(:organisation=>'Invoice API-Tester')
|
9
|
+
@client.save.should be_true
|
10
|
+
# @doc = SKApi::Resources::Invoice.new()
|
11
|
+
@doc = SKApi::Resources::Invoice.new(:client_id => @client.id,
|
12
|
+
:line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
|
13
|
+
@doc.save.should be_true
|
14
|
+
# @doc.title = 'A Document from the API'
|
15
|
+
# @doc.client_id = @client.id
|
16
|
+
# @doc.save
|
17
|
+
# @doc.errors.full_messages.should == 'adfd'
|
18
|
+
@doc.save.should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
after :all do
|
22
|
+
#delete test doc
|
23
|
+
@doc.destroy
|
24
|
+
@client.destroy
|
25
|
+
lambda {
|
26
|
+
doc = SKApi::Resources::Invoice.find(@doc.id)
|
27
|
+
}.should raise_error(ActiveResource::ResourceNotFound)
|
28
|
+
lambda {
|
29
|
+
client = SKApi::Resources::Client.find(@client.id)
|
30
|
+
}.should raise_error(ActiveResource::ResourceNotFound)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create a doc" do
|
34
|
+
@doc.errors.should be_empty
|
35
|
+
@doc.new?.should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fail create a doc" do
|
39
|
+
doc = SKApi::Resources::Invoice.new()
|
40
|
+
doc.save.should == false
|
41
|
+
doc.errors.count.should == 1
|
42
|
+
doc.errors.on(:client_id).should == "can't be blank"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find a doc" do
|
46
|
+
doc = SKApi::Resources::Invoice.find(@doc.id)
|
47
|
+
doc.title.should == @doc.title
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should validate raw json object with schema" do
|
51
|
+
doc = SKApi::Resources::Invoice.find(@doc.id)
|
52
|
+
# doc.number.should=='23'
|
53
|
+
# convert to json and read raw without activeresource assigning classes
|
54
|
+
json = doc.to_json
|
55
|
+
obj = Rufus::Json.decode(json)
|
56
|
+
lambda {
|
57
|
+
JSON::Schema.validate(obj, SKApi::Resources::Invoice.schema)
|
58
|
+
}.should_not raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should edit a doc" do
|
62
|
+
# @doc.lock_version.should == 0 # dont work cause doc is saved twice, for recalc of totals
|
63
|
+
old_lock_version = @doc.lock_version
|
64
|
+
@doc.notes_before = 'You will recieve the amout of:'
|
65
|
+
@doc.notes_before = 'Payment made to you bank Account'
|
66
|
+
@doc.title = 'Changed doc title'
|
67
|
+
|
68
|
+
@doc.save.should be_true
|
69
|
+
@doc.lock_version.should > old_lock_version # because save returns the data
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should fail edit a doc" do
|
73
|
+
@doc.client_id = ''
|
74
|
+
@doc.save.should == false
|
75
|
+
@doc.errors.count.should == 1
|
76
|
+
@doc.errors.on(:client_id).should == "can't be blank"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe SKApi::Resources::Invoice, "with line items" do
|
81
|
+
|
82
|
+
before :all do
|
83
|
+
@client = SKApi::Resources::Client.new(:organisation=>'Credit Note API-Tester')
|
84
|
+
@client.save.should be_true
|
85
|
+
#setup test doc to work with
|
86
|
+
@doc = SKApi::Resources::Invoice.new(:client_id => @client.id,
|
87
|
+
:line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
|
88
|
+
@doc.save.should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
after :all do
|
92
|
+
@client.destroy #also destroys all docs
|
93
|
+
# @doc.destroy
|
94
|
+
lambda {
|
95
|
+
doc = SKApi::Resources::Invoice.find(@doc.id)
|
96
|
+
}.should raise_error(ActiveResource::ResourceNotFound)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should create a line item" do
|
100
|
+
@doc.line_items.length.should == 1
|
101
|
+
@doc.line_items.first.description.should == 'Pork Chops'
|
102
|
+
@doc.price_total.should == 120.0
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should edit line item" do
|
106
|
+
@doc.line_items[0].description = 'Egg Sandwich'
|
107
|
+
@doc.save
|
108
|
+
@doc.line_items.length.should == 1
|
109
|
+
@doc.line_items.first.description.should == 'Egg Sandwich'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should add line item" do
|
113
|
+
item = SKApi::Resources::LineItem.new( { :position=>2, :description => 'Goat-Pie', :price_single => 10, :quantity=>10} )
|
114
|
+
@doc.line_items << item
|
115
|
+
@doc.save
|
116
|
+
@doc.line_items.length.should == 2
|
117
|
+
@doc.price_total.should == 220.0
|
118
|
+
# @doc.line_items[0].zip = '40001'
|
119
|
+
# @doc.line_items.[1].zip.should == '40001'
|
120
|
+
end
|
121
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Georg Leciejewski
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/resources/base.rb
|
53
53
|
- lib/resources/client.rb
|
54
54
|
- lib/resources/credit_note.rb
|
55
|
+
- lib/resources/invoice.rb
|
55
56
|
- lib/resources/line_item.rb
|
56
57
|
- lib/resources/product.rb
|
57
58
|
- lib/sk_api.rb
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- lib/utils/serializer.rb
|
60
61
|
- spec/resources/client_spec.rb
|
61
62
|
- spec/resources/credit_note_spec.rb
|
63
|
+
- spec/resources/invoice_spec.rb
|
62
64
|
- spec/resources/product_spec.rb
|
63
65
|
- spec/spec_helper.rb
|
64
66
|
- spec/utils/field_map_spec.rb
|
@@ -101,6 +103,7 @@ summary: Interact with SalesKing
|
|
101
103
|
test_files:
|
102
104
|
- spec/resources/client_spec.rb
|
103
105
|
- spec/resources/credit_note_spec.rb
|
106
|
+
- spec/resources/invoice_spec.rb
|
104
107
|
- spec/resources/product_spec.rb
|
105
108
|
- spec/spec_helper.rb
|
106
109
|
- spec/utils/field_map_spec.rb
|