sie 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/sie/document/financial_years.rb +5 -12
- data/lib/sie/document.rb +6 -5
- data/lib/sie/version.rb +1 -1
- data/spec/unit/document/financial_years_spec.rb +12 -22
- data/spec/unit/document_spec.rb +27 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTJmMTM2NDcyNGI2ODIzZmZhZjdiMmUzMTNmOWM5ZjU5NDNjNWUyYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDI2MDliNGM4NWZlMjYyMWU1ODliOGQ5YTA4NzMyMGFmMzVmMTgyNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA1OTJjYzcyNTA3YWMxYmY5MTE0ZjY5ODk5ZDJkMjA2NDJiZGJhYTcyMGY5
|
10
|
+
ODEwYzQ3ZDY4NjdkYjI5YzdlOTJmYzE0ZDJjZDkxNDIwODdiNDdkNzY0Yjcy
|
11
|
+
MWYwODVmNjk4OWFjNGIxNzQ4MmExNGMyMTAyMTQ3ODFlZjcyNWI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGY2NTM1ZjgyZjU2ODMwYTc4YmNhOTFiZjNlMDJjYjhmMTgwMmQ3ZWFmZWQ4
|
14
|
+
MGM3ZDI5MjgzN2Q5MDFiYjVkNmIzZGIyYmQwOTRjNzRlZTgyZDRhNGE4MTc4
|
15
|
+
OWRhNTU1MGNiMTBlYzljZWZjNWNmNmM0M2QwNzM4ZjVkNjk0NTY=
|
@@ -7,21 +7,14 @@ class Sie::Document
|
|
7
7
|
|
8
8
|
def between
|
9
9
|
from_date.year.upto(to_date.year).map { |year|
|
10
|
-
|
11
|
-
|
12
|
-
financial_year_date_range unless out_of_year_range(financial_year_date_range)
|
13
|
-
}.compact
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def out_of_year_range(range)
|
19
|
-
range.last.year > to_date.year
|
10
|
+
FinancialYear.date_range(year, start_month)
|
11
|
+
}
|
20
12
|
end
|
21
13
|
end
|
22
14
|
|
23
15
|
class FinancialYear
|
24
|
-
|
16
|
+
method_object :date_range,
|
17
|
+
:year, :start_month
|
25
18
|
|
26
19
|
def date_range
|
27
20
|
(start_of_year.beginning_of_month..end_of_year.end_of_month)
|
@@ -30,7 +23,7 @@ class Sie::Document
|
|
30
23
|
private
|
31
24
|
|
32
25
|
def start_of_year
|
33
|
-
|
26
|
+
Date.new(year, start_month, 1)
|
34
27
|
end
|
35
28
|
|
36
29
|
def end_of_year
|
data/lib/sie/document.rb
CHANGED
@@ -6,7 +6,8 @@ require "active_support/core_ext/module/delegation"
|
|
6
6
|
|
7
7
|
class Sie::Document
|
8
8
|
pattr_initialize :data_source
|
9
|
-
|
9
|
+
# Because fortnox imposes these limits
|
10
|
+
DESCRIPTION_LENGTH_MAX = 30
|
10
11
|
|
11
12
|
def render
|
12
13
|
add_header
|
@@ -43,7 +44,7 @@ class Sie::Document
|
|
43
44
|
def add_accounts
|
44
45
|
accounts.each do |account|
|
45
46
|
number = account.fetch(:number)
|
46
|
-
description = account.fetch(:description).slice(0,
|
47
|
+
description = account.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
47
48
|
|
48
49
|
add_line("KONTO", number, description)
|
49
50
|
end
|
@@ -76,7 +77,7 @@ class Sie::Document
|
|
76
77
|
type = opts.fetch(:type)
|
77
78
|
number = opts.fetch(:number)
|
78
79
|
booked_on = opts.fetch(:booked_on)
|
79
|
-
description = opts.fetch(:description).slice(0,
|
80
|
+
description = opts.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
80
81
|
voucher_lines = opts.fetch(:voucher_lines)
|
81
82
|
|
82
83
|
add_line("VER", voucher_series(creditor, type), number, booked_on, description)
|
@@ -88,14 +89,14 @@ class Sie::Document
|
|
88
89
|
booked_on = line.fetch(:booked_on)
|
89
90
|
# Some SIE-importers (fortnox) cannot handle descriptions longer than 30 characters,
|
90
91
|
# but the specification has no limit.
|
91
|
-
description = line.fetch(:description).slice(0,
|
92
|
+
description = line.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
92
93
|
|
93
94
|
add_line("TRANS", account_number, Renderer::EMPTY_ARRAY, amount, booked_on, description)
|
94
95
|
|
95
96
|
# Some consumers of SIE cannot handle single voucher lines (fortnox), so add another empty one to make
|
96
97
|
# it balance. The spec just requires the sum of lines to be 0, so single lines with zero amount would conform,
|
97
98
|
# but break for these implementations.
|
98
|
-
if voucher_lines.size < 2 && amount
|
99
|
+
if voucher_lines.size < 2 && amount.zero?
|
99
100
|
add_line("TRANS", account_number, Renderer::EMPTY_ARRAY, amount, booked_on, description)
|
100
101
|
end
|
101
102
|
end
|
data/lib/sie/version.rb
CHANGED
@@ -4,15 +4,14 @@ describe Sie::Document::FinancialYears, ".between" do
|
|
4
4
|
it "gives us the financial years between from_date and to_date" do
|
5
5
|
Sie::Document::FinancialYears.between(
|
6
6
|
1,
|
7
|
-
Date.new(2011,
|
8
|
-
Date.new(
|
7
|
+
Date.new(2011, 1, 1),
|
8
|
+
Date.new(2011, 12, 31)
|
9
9
|
).should == [
|
10
|
-
Date.new(2011, 1, 1)..Date.new(2011, 12, 31)
|
11
|
-
Date.new(2012, 1, 1)..Date.new(2012, 12, 31),
|
10
|
+
Date.new(2011, 1, 1)..Date.new(2011, 12, 31)
|
12
11
|
]
|
13
12
|
end
|
14
13
|
|
15
|
-
it "gives us the financial years
|
14
|
+
it "gives us the financial years over multiple years" do
|
16
15
|
Sie::Document::FinancialYears.between(
|
17
16
|
1,
|
18
17
|
Date.new(2011, 9, 1),
|
@@ -24,18 +23,6 @@ describe Sie::Document::FinancialYears, ".between" do
|
|
24
23
|
]
|
25
24
|
end
|
26
25
|
|
27
|
-
it "gives us the financial years between from_date and to_date with a different financial year start month" do
|
28
|
-
Sie::Document::FinancialYears.between(
|
29
|
-
5,
|
30
|
-
Date.new(2011, 9, 1),
|
31
|
-
Date.new(2014, 1, 31)
|
32
|
-
).should == [
|
33
|
-
Date.new(2011, 5, 1)..Date.new(2012, 4, 30),
|
34
|
-
Date.new(2012, 5, 1)..Date.new(2013, 4, 30),
|
35
|
-
Date.new(2013, 5, 1)..Date.new(2014, 4, 30),
|
36
|
-
]
|
37
|
-
end
|
38
|
-
|
39
26
|
it "normalizes start and end date for compatibility with other systems" do
|
40
27
|
Sie::Document::FinancialYears.between(
|
41
28
|
1,
|
@@ -46,13 +33,16 @@ describe Sie::Document::FinancialYears, ".between" do
|
|
46
33
|
]
|
47
34
|
end
|
48
35
|
|
49
|
-
it "
|
36
|
+
it "uses the start month" do
|
50
37
|
Sie::Document::FinancialYears.between(
|
51
|
-
|
52
|
-
Date.new(2011,
|
53
|
-
Date.new(
|
38
|
+
5,
|
39
|
+
Date.new(2011, 9, 1),
|
40
|
+
Date.new(2014, 1, 31)
|
54
41
|
).should == [
|
55
|
-
Date.new(2011,
|
42
|
+
Date.new(2011, 5, 1)..Date.new(2012, 4, 30),
|
43
|
+
Date.new(2012, 5, 1)..Date.new(2013, 4, 30),
|
44
|
+
Date.new(2013, 5, 1)..Date.new(2014, 4, 30),
|
45
|
+
Date.new(2014, 5, 1)..Date.new(2015, 4, 30),
|
56
46
|
]
|
57
47
|
end
|
58
48
|
end
|
data/spec/unit/document_spec.rb
CHANGED
@@ -163,13 +163,13 @@ describe Sie::Document, "#render" do
|
|
163
163
|
}
|
164
164
|
let(:vouchers) {
|
165
165
|
[
|
166
|
-
|
167
|
-
|
166
|
+
build_voucher(
|
167
|
+
description: "Payout 1 with really really long description blablabla",
|
168
168
|
voucher_lines: [
|
169
|
-
|
170
|
-
|
169
|
+
build_voucher_line(description: "Payout line 1 with really really long description blablabla"),
|
170
|
+
build_voucher_line(description: "Payout line 2"),
|
171
171
|
]
|
172
|
-
|
172
|
+
)
|
173
173
|
]
|
174
174
|
}
|
175
175
|
|
@@ -183,22 +183,37 @@ describe Sie::Document, "#render" do
|
|
183
183
|
context "with a zeroed single voucher line" do
|
184
184
|
let(:vouchers) {
|
185
185
|
[
|
186
|
-
|
187
|
-
creditor: false, type: :invoice, number: 1, booked_on: from_date + 2, description: "Invoice 1",
|
188
|
-
voucher_lines: [
|
189
|
-
{ account_number: 1500, amount: 0, booked_on: from_date + 2, description: "Item 1" },
|
190
|
-
]
|
191
|
-
},
|
186
|
+
build_voucher(voucher_lines: [ build_voucher_line(amount: 0) ])
|
192
187
|
]
|
193
188
|
}
|
194
189
|
|
195
|
-
it "
|
190
|
+
it "ensures there are at least two lines" do
|
196
191
|
expect(indexed_voucher_entries(0).size).to eq(2)
|
197
192
|
end
|
198
193
|
end
|
199
194
|
|
200
195
|
private
|
201
196
|
|
197
|
+
def build_voucher(attributes)
|
198
|
+
defaults = {
|
199
|
+
creditor: true,
|
200
|
+
type: :payment,
|
201
|
+
number: 1,
|
202
|
+
booked_on: Date.today,
|
203
|
+
description: "A voucher",
|
204
|
+
voucher_lines: [
|
205
|
+
build_voucher_line,
|
206
|
+
build_voucher_line,
|
207
|
+
],
|
208
|
+
}
|
209
|
+
defaults.merge(attributes)
|
210
|
+
end
|
211
|
+
|
212
|
+
def build_voucher_line(attributes = {})
|
213
|
+
defaults = { account_number: 1234, amount: 1, booked_on: Date.today, description: "A voucher line" }
|
214
|
+
defaults.merge(attributes)
|
215
|
+
end
|
216
|
+
|
202
217
|
def entry_attribute(label, attribute)
|
203
218
|
indexed_entry_attribute(label, 0, attribute)
|
204
219
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barsoom AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attr_extras
|