keepr 0.3.1 → 0.7.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 +5 -5
- data/.travis.yml +14 -10
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/Rakefile +3 -1
- data/ci/Gemfile-rails-4-2 +5 -5
- data/ci/Gemfile-rails-5-0 +5 -5
- data/ci/Gemfile-rails-5-1 +12 -0
- data/ci/Gemfile-rails-5-2 +12 -0
- data/ci/Gemfile-rails-6-0 +12 -0
- data/keepr.gemspec +15 -14
- data/lib/generators/keepr/migration/migration_generator.rb +5 -3
- data/lib/generators/keepr/migration/templates/migration.rb +27 -25
- data/lib/keepr.rb +8 -0
- data/lib/keepr/account.rb +66 -61
- data/lib/keepr/account_export.rb +10 -14
- data/lib/keepr/active_record_extension.rb +10 -8
- data/lib/keepr/contact_export.rb +6 -7
- data/lib/keepr/cost_center.rb +3 -1
- data/lib/keepr/group.rb +25 -16
- data/lib/keepr/groups_creator.rb +27 -14
- data/lib/keepr/groups_creator/{asset.txt → de/asset.txt} +0 -0
- data/lib/keepr/groups_creator/{liability.txt → de/liability.txt} +0 -0
- data/lib/keepr/groups_creator/{profit_and_loss.txt → de/profit_and_loss.txt} +0 -0
- data/lib/keepr/groups_creator/en/asset.txt +36 -0
- data/lib/keepr/groups_creator/en/liability.txt +28 -0
- data/lib/keepr/groups_creator/en/profit_and_loss.txt +31 -0
- data/lib/keepr/groups_creator/es/asset.txt +36 -0
- data/lib/keepr/groups_creator/es/liability.txt +28 -0
- data/lib/keepr/groups_creator/es/profit_and_loss.txt +31 -0
- data/lib/keepr/journal.rb +19 -16
- data/lib/keepr/journal_export.rb +10 -7
- data/lib/keepr/posting.rb +26 -21
- data/lib/keepr/tax.rb +4 -2
- data/lib/keepr/version.rb +3 -1
- data/spec/factories/account.rb +6 -4
- data/spec/factories/cost_center.rb +5 -3
- data/spec/factories/group.rb +5 -3
- data/spec/factories/tax.rb +7 -5
- data/spec/keepr/account_export_spec.rb +22 -19
- data/spec/keepr/account_spec.rb +92 -87
- data/spec/keepr/active_record_extension_spec.rb +38 -36
- data/spec/keepr/contact_export_spec.rb +17 -14
- data/spec/keepr/cost_center_spec.rb +9 -7
- data/spec/keepr/group_spec.rb +53 -49
- data/spec/keepr/groups_creator_spec.rb +13 -10
- data/spec/keepr/journal_export_spec.rb +54 -53
- data/spec/keepr/journal_spec.rb +48 -46
- data/spec/keepr/posting_spec.rb +25 -23
- data/spec/keepr/tax_spec.rb +21 -14
- data/spec/spec_helper.rb +13 -11
- data/spec/support/contact.rb +2 -0
- data/spec/support/document.rb +2 -0
- data/spec/support/ledger.rb +2 -0
- data/spec/support/spec_migration.rb +3 -1
- metadata +35 -28
- data/ci/Gemfile-rails-4-1 +0 -12
@@ -1,26 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::ActiveRecordExtension do
|
4
|
-
let(:account_1000) {
|
5
|
-
let(:account_1200) {
|
6
|
+
let(:account_1000) { FactoryBot.create(:account, number: 1000, kind: :asset) }
|
7
|
+
let(:account_1200) { FactoryBot.create(:account, number: 1200, kind: :asset) }
|
6
8
|
|
7
9
|
describe 'ledger with associated account' do
|
8
|
-
let(:ledger) { Ledger.create! :
|
9
|
-
let!(:account) { ledger.create_keepr_account! :
|
10
|
+
let(:ledger) { Ledger.create! bank_name: 'Sparkasse' }
|
11
|
+
let!(:account) { ledger.create_keepr_account! number: '1250', kind: :asset, name: 'Girokonto' }
|
10
12
|
|
11
13
|
it 'has keepr_account' do
|
12
14
|
expect(ledger.keepr_account).to eq(account)
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'has keepr_postings' do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
19
|
+
{ keepr_account: account, amount: 30, side: 'debit' },
|
20
|
+
{ keepr_account: account_1200, amount: 30, side: 'credit' }
|
21
|
+
]
|
22
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
23
|
+
{ keepr_account: account_1000, amount: 20, side: 'debit' },
|
24
|
+
{ keepr_account: account_1200, amount: 20, side: 'credit' }
|
25
|
+
]
|
24
26
|
|
25
27
|
expect(ledger.keepr_postings.count).to eq(1)
|
26
28
|
expect(ledger.keepr_postings.first.amount).to eq(30)
|
@@ -28,23 +30,23 @@ describe Keepr::ActiveRecordExtension do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
describe 'contact with multiple associated accounts' do
|
31
|
-
let(:contact) { Contact.create! :
|
32
|
-
let(:account1) { contact.keepr_accounts.create! :
|
33
|
-
let(:account2) { contact.keepr_accounts.create! :
|
33
|
+
let(:contact) { Contact.create! name: 'John Doe' }
|
34
|
+
let(:account1) { contact.keepr_accounts.create! number: '70001', kind: :debtor, name: "Doe's main account" }
|
35
|
+
let(:account2) { contact.keepr_accounts.create! number: '70002', kind: :debtor, name: "Doe's second account" }
|
34
36
|
|
35
37
|
it 'has multiple keepr_accounts' do
|
36
38
|
expect(contact.keepr_accounts).to eq([account1, account2])
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'has keepr_postings' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
43
|
+
{ keepr_account: account1, amount: 30, side: 'debit' },
|
44
|
+
{ keepr_account: account_1200, amount: 30, side: 'credit' }
|
45
|
+
]
|
46
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
47
|
+
{ keepr_account: account_1000, amount: 20, side: 'debit' },
|
48
|
+
{ keepr_account: account_1200, amount: 20, side: 'credit' }
|
49
|
+
]
|
48
50
|
|
49
51
|
expect(contact.keepr_postings.count).to eq(1)
|
50
52
|
expect(contact.keepr_postings.first.amount).to eq(30)
|
@@ -53,11 +55,11 @@ describe Keepr::ActiveRecordExtension do
|
|
53
55
|
|
54
56
|
describe 'Document with associated journal' do
|
55
57
|
subject do
|
56
|
-
document = Document.create! :
|
57
|
-
Keepr::Journal.create! :
|
58
|
-
:
|
59
|
-
{ :
|
60
|
-
{ :
|
58
|
+
document = Document.create! number: 'RE-2013-10-12345'
|
59
|
+
Keepr::Journal.create! accountable: document,
|
60
|
+
keepr_postings_attributes: [
|
61
|
+
{ keepr_account: account_1000, amount: 100.99, side: 'debit' },
|
62
|
+
{ keepr_account: account_1200, amount: 100.99, side: 'credit' }
|
61
63
|
]
|
62
64
|
document
|
63
65
|
end
|
@@ -69,16 +71,16 @@ describe Keepr::ActiveRecordExtension do
|
|
69
71
|
end
|
70
72
|
|
71
73
|
describe 'scopes' do
|
72
|
-
let!(:unbooked_document) { Document.create! :
|
73
|
-
let!(:booked_document)
|
74
|
-
document = Document.create! :
|
75
|
-
Keepr::Journal.create! :
|
76
|
-
:
|
77
|
-
{ :
|
78
|
-
{ :
|
74
|
+
let!(:unbooked_document) { Document.create! number: 'Unbooked' }
|
75
|
+
let!(:booked_document) do
|
76
|
+
document = Document.create! number: 'Booked'
|
77
|
+
Keepr::Journal.create! accountable: document,
|
78
|
+
keepr_postings_attributes: [
|
79
|
+
{ keepr_account: account_1000, amount: 100.99, side: 'debit' },
|
80
|
+
{ keepr_account: account_1200, amount: 100.99, side: 'credit' }
|
79
81
|
]
|
80
82
|
document
|
81
|
-
|
83
|
+
end
|
82
84
|
|
83
85
|
describe :keepr_booked do
|
84
86
|
subject { Document.keepr_booked }
|
@@ -1,22 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::ContactExport do
|
4
|
-
let!(:account_1000) {
|
5
|
-
let!(:account_10000) {
|
6
|
-
let!(:account_70000) {
|
6
|
+
let!(:account_1000) { FactoryBot.create :account, kind: :asset, number: 1000, name: 'Kasse' }
|
7
|
+
let!(:account_10000) { FactoryBot.create :account, kind: :creditor, number: 10_000, name: 'Meyer GmbH' }
|
8
|
+
let!(:account_70000) { FactoryBot.create :account, kind: :debtor, number: 70_000, name: 'Schulze AG' }
|
7
9
|
|
8
10
|
let(:scope) { Keepr::Account.all }
|
9
11
|
|
10
|
-
let(:export)
|
11
|
-
Keepr::ContactExport.new(
|
12
|
-
|
13
|
-
'
|
14
|
-
'
|
12
|
+
let(:export) do
|
13
|
+
Keepr::ContactExport.new(
|
14
|
+
scope,
|
15
|
+
'Berater' => 1_234_567,
|
16
|
+
'Mandant' => 78_901,
|
17
|
+
'WJ-Beginn' => Date.new(2016, 1, 1),
|
15
18
|
'Bezeichnung' => 'Keepr-Kontakte'
|
16
19
|
) do |account|
|
17
20
|
{ 'Kurzbezeichnung' => account.name }
|
18
21
|
end
|
19
|
-
|
22
|
+
end
|
20
23
|
|
21
24
|
describe :to_s do
|
22
25
|
subject { export.to_s }
|
@@ -25,31 +28,31 @@ describe Keepr::ContactExport do
|
|
25
28
|
subject.lines[2..-1]
|
26
29
|
end
|
27
30
|
|
28
|
-
it
|
31
|
+
it 'should return CSV lines' do
|
29
32
|
subject.lines.each { |line| expect(line).to include(';') }
|
30
33
|
end
|
31
34
|
|
32
|
-
it
|
35
|
+
it 'should include header data' do
|
33
36
|
expect(subject.lines[0]).to include('1234567;')
|
34
37
|
expect(subject.lines[0]).to include('78901;')
|
35
38
|
expect(subject.lines[0]).to include('"Keepr-Kontakte";')
|
36
39
|
end
|
37
40
|
|
38
|
-
it
|
41
|
+
it 'should include debtor/creditor accounts only' do
|
39
42
|
expect(account_lines.count).to eq(2)
|
40
43
|
|
41
44
|
expect(account_lines[0]).to include('10000;')
|
42
45
|
expect(account_lines[1]).to include('70000;')
|
43
46
|
end
|
44
47
|
|
45
|
-
it
|
48
|
+
it 'should include data from block' do
|
46
49
|
expect(account_lines[0]).to include('"Meyer GmbH";')
|
47
50
|
expect(account_lines[1]).to include('"Schulze AG";')
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
describe :to_file do
|
52
|
-
it
|
55
|
+
it 'should create CSV file' do
|
53
56
|
Dir.mktmpdir do |dir|
|
54
57
|
filename = "#{dir}/EXTF_Stammdaten.csv"
|
55
58
|
export.to_file(filename)
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::CostCenter do
|
4
|
-
let(:cost_center) {
|
5
|
-
let(:account) {
|
6
|
+
let(:cost_center) { FactoryBot.create(:cost_center) }
|
7
|
+
let(:account) { FactoryBot.create(:account, number: 8400, kind: :revenue) }
|
6
8
|
|
7
9
|
it 'should have postings' do
|
8
|
-
posting = Keepr::Posting.create! :
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
10
|
+
posting = Keepr::Posting.create! amount: 10,
|
11
|
+
side: 'debit',
|
12
|
+
keepr_account: account,
|
13
|
+
keepr_cost_center: cost_center,
|
14
|
+
keepr_journal_id: 42
|
13
15
|
|
14
16
|
expect(cost_center.keepr_postings).to eq([posting])
|
15
17
|
end
|
data/spec/keepr/group_spec.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::Group do
|
4
6
|
describe 'validations' do
|
5
|
-
it
|
6
|
-
group = Keepr::Group.new(:
|
7
|
+
it 'should allow is_result for liability' do
|
8
|
+
group = Keepr::Group.new(is_result: true, target: :liability, name: 'foo')
|
7
9
|
expect(group).to be_valid
|
8
10
|
end
|
9
11
|
|
10
|
-
[
|
12
|
+
%i[asset profit_and_loss].each do |target|
|
11
13
|
it "should not allow is_result for #{target}" do
|
12
|
-
group = Keepr::Group.new(:
|
14
|
+
group = Keepr::Group.new(is_result: true, target: target, name: 'foo')
|
13
15
|
expect(group).not_to be_valid
|
14
|
-
expect(group.errors.added?
|
16
|
+
expect(group.errors.added?(:base, :liability_needed_for_result)).to eq(true)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
describe :get_from_parent do
|
20
22
|
it 'should preset parent' do
|
21
|
-
root =
|
22
|
-
child = root.children.create! :
|
23
|
+
root = FactoryBot.create :group, target: :asset
|
24
|
+
child = root.children.create! name: 'Bar'
|
23
25
|
|
24
26
|
expect(child.target).to eq('asset')
|
25
27
|
end
|
@@ -27,16 +29,16 @@ describe Keepr::Group do
|
|
27
29
|
|
28
30
|
describe :keepr_accounts do
|
29
31
|
it 'should not destroy if there are accounts' do
|
30
|
-
group =
|
31
|
-
|
32
|
+
group = FactoryBot.create :group
|
33
|
+
FactoryBot.create :account, number: 1000, keepr_group: group
|
32
34
|
|
33
|
-
expect { group.destroy }.to_not change
|
35
|
+
expect { group.destroy }.to_not change(Keepr::Group, :count)
|
34
36
|
expect(group.destroy).to eq(false)
|
35
37
|
expect(group.reload).to eq(group)
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'should destroy if there are no accounts' do
|
39
|
-
group =
|
41
|
+
group = FactoryBot.create :group
|
40
42
|
|
41
43
|
expect { group.destroy }.to change { Keepr::Group.count }.by(-1)
|
42
44
|
end
|
@@ -44,58 +46,60 @@ describe Keepr::Group do
|
|
44
46
|
|
45
47
|
describe :keepr_postings do
|
46
48
|
# Simple asset group hierarchy
|
47
|
-
let(:group_1) {
|
48
|
-
let(:group_1_1) {
|
49
|
-
let(:group_1_1_1) {
|
49
|
+
let(:group_1) { FactoryBot.create :group, target: :asset }
|
50
|
+
let(:group_1_1) { FactoryBot.create :group, target: :asset, parent: group_1 }
|
51
|
+
let(:group_1_1_1) { FactoryBot.create :group, target: :asset, parent: group_1_1 }
|
50
52
|
|
51
53
|
# Group for P&L accounts
|
52
|
-
let(:group_2) {
|
54
|
+
let(:group_2) { FactoryBot.create :group, target: :profit_and_loss }
|
53
55
|
|
54
56
|
# Group for balance result
|
55
|
-
let(:group_result){
|
57
|
+
let(:group_result) { FactoryBot.create :group, target: :liability, is_result: true }
|
56
58
|
|
57
59
|
# Accounts
|
58
|
-
let(:account_1a) {
|
59
|
-
let(:account_1b) {
|
60
|
-
let(:account_1c) {
|
60
|
+
let(:account_1a) { FactoryBot.create :account, number: '0001', keepr_group: group_1_1_1 }
|
61
|
+
let(:account_1b) { FactoryBot.create :account, number: '0011', keepr_group: group_1_1_1 }
|
62
|
+
let(:account_1c) { FactoryBot.create :account, number: '0111', keepr_group: group_1_1_1 }
|
61
63
|
|
62
|
-
let(:account_2) {
|
64
|
+
let(:account_2) { FactoryBot.create :account, number: '8400', keepr_group: group_2, kind: :revenue }
|
63
65
|
|
64
66
|
# Journals
|
65
|
-
let!(:journal1)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
67
|
+
let!(:journal1) do
|
68
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
69
|
+
{ keepr_account: account_1a, amount: 100.99, side: 'debit' },
|
70
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
71
|
+
]
|
72
|
+
end
|
73
|
+
let!(:journal2) do
|
74
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
75
|
+
{ keepr_account: account_1b, amount: 100.99, side: 'debit' },
|
76
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
77
|
+
]
|
78
|
+
end
|
79
|
+
let!(:journal3) do
|
80
|
+
Keepr::Journal.create! keepr_postings_attributes: [
|
81
|
+
{ keepr_account: account_1c, amount: 100.99, side: 'debit' },
|
82
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
83
|
+
]
|
84
|
+
end
|
80
85
|
|
81
86
|
context 'for normal groups' do
|
82
|
-
it
|
83
|
-
|
84
|
-
expect(group_1.keepr_postings).to eq(
|
85
|
-
expect(group_1_1.keepr_postings).to eq(
|
86
|
-
expect(group_1_1_1.keepr_postings).to eq(
|
87
|
-
|
88
|
-
|
89
|
-
expect(group_2.keepr_postings).to eq(
|
87
|
+
it 'should return postings of all accounts within the group' do
|
88
|
+
postings1 = [journal1.debit_postings.first, journal2.debit_postings.first, journal3.debit_postings.first]
|
89
|
+
expect(group_1.keepr_postings).to eq(postings1)
|
90
|
+
expect(group_1_1.keepr_postings).to eq(postings1)
|
91
|
+
expect(group_1_1_1.keepr_postings).to eq(postings1)
|
92
|
+
|
93
|
+
postings2 = [journal1.credit_postings.first, journal2.credit_postings.first, journal3.credit_postings.first]
|
94
|
+
expect(group_2.keepr_postings).to eq(postings2)
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
93
|
-
context
|
94
|
-
it
|
95
|
-
result_postings = [
|
96
|
-
|
97
|
-
|
98
|
-
]
|
98
|
+
context 'for result group' do
|
99
|
+
it 'should return postings for P&L accounts' do
|
100
|
+
result_postings = [journal1.credit_postings.first,
|
101
|
+
journal2.credit_postings.first,
|
102
|
+
journal3.credit_postings.first]
|
99
103
|
|
100
104
|
expect(group_result.keepr_postings).to eq(result_postings)
|
101
105
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::GroupsCreator do
|
4
|
-
context 'balance groups' do
|
6
|
+
context 'balance groups in german' do
|
5
7
|
before :each do
|
6
8
|
Keepr::GroupsCreator.new(:balance).run
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
11
|
+
it 'should create groups' do
|
10
12
|
expect(Keepr::Group.count).to eq(64)
|
11
13
|
expect(Keepr::Group.asset.count).to eq(36)
|
12
14
|
expect(Keepr::Group.liability.count).to eq(28)
|
13
15
|
|
14
|
-
compare_with_source(Keepr::Group.asset, 'asset.txt')
|
15
|
-
compare_with_source(Keepr::Group.liability, 'liability.txt')
|
16
|
+
compare_with_source(Keepr::Group.asset, 'de', 'asset.txt')
|
17
|
+
compare_with_source(Keepr::Group.liability, 'de', 'liability.txt')
|
16
18
|
end
|
17
19
|
|
18
|
-
it
|
20
|
+
it 'should create result group' do
|
19
21
|
expect(Keepr::Group.result).to be_a(Keepr::Group)
|
20
22
|
end
|
21
23
|
end
|
@@ -25,17 +27,18 @@ describe Keepr::GroupsCreator do
|
|
25
27
|
Keepr::GroupsCreator.new(:profit_and_loss).run
|
26
28
|
end
|
27
29
|
|
28
|
-
it
|
30
|
+
it 'should create profit & loss groups' do
|
29
31
|
expect(Keepr::Group.count).to eq(31)
|
30
32
|
expect(Keepr::Group.profit_and_loss.count).to eq(31)
|
31
33
|
|
32
|
-
compare_with_source(Keepr::Group.profit_and_loss, 'profit_and_loss.txt')
|
34
|
+
compare_with_source(Keepr::Group.profit_and_loss, 'de', 'profit_and_loss.txt')
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
private
|
37
|
-
|
38
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
def compare_with_source(scope, language, filename)
|
41
|
+
full_filename = File.join(File.dirname(__FILE__), "../../lib/keepr/groups_creator/#{language}/#{filename}")
|
39
42
|
source = File.read(full_filename)
|
40
43
|
|
41
44
|
lines = scope.find_each.map { |g| "#{' ' * g.depth * 2}#{g.number} #{g.name}\n" }.join
|
@@ -1,34 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Keepr::JournalExport do
|
4
|
-
let(:ust) { Keepr::Tax.create! :
|
5
|
-
let(:vst) { Keepr::Tax.create! :
|
6
|
+
let(:ust) { Keepr::Tax.create! name: 'USt19', value: 19.0, keepr_account: account_1776 }
|
7
|
+
let(:vst) { Keepr::Tax.create! name: 'VSt19', value: 19.0, keepr_account: account_1576 }
|
6
8
|
|
7
|
-
let(:account_1000) {
|
8
|
-
let(:account_1200) {
|
9
|
-
let(:account_1576) {
|
10
|
-
let(:account_1776) {
|
11
|
-
let(:account_1600) {
|
12
|
-
let(:account_1718) {
|
13
|
-
let(:account_4920) {
|
14
|
-
let(:account_8400) {
|
9
|
+
let(:account_1000) { FactoryBot.create :account, number: 1000, kind: :asset }
|
10
|
+
let(:account_1200) { FactoryBot.create :account, number: 1200, kind: :asset }
|
11
|
+
let(:account_1576) { FactoryBot.create :account, number: 1576, kind: :asset }
|
12
|
+
let(:account_1776) { FactoryBot.create :account, number: 1776, kind: :liability }
|
13
|
+
let(:account_1600) { FactoryBot.create :account, number: 1600, kind: :liability }
|
14
|
+
let(:account_1718) { FactoryBot.create :account, number: 1718, kind: :liability, keepr_tax: ust }
|
15
|
+
let(:account_4920) { FactoryBot.create :account, number: 4920, kind: :expense, keepr_tax: vst }
|
16
|
+
let(:account_8400) { FactoryBot.create :account, number: 8400, kind: :revenue, keepr_tax: ust }
|
15
17
|
|
16
|
-
let(:account_10000) {
|
18
|
+
let(:account_10000) { FactoryBot.create :account, number: 10_000, kind: :debtor }
|
17
19
|
|
18
20
|
let(:scope) { Keepr::Journal.reorder(:number) }
|
19
21
|
|
20
|
-
let(:export)
|
22
|
+
let(:export) do
|
21
23
|
Keepr::JournalExport.new(scope,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
) do |posting|
|
24
|
+
'Berater' => 1_234_567,
|
25
|
+
'Mandant' => 78_901,
|
26
|
+
'Datum vom' => Date.new(2016, 6, 1),
|
27
|
+
'Datum bis' => Date.new(2016, 6, 30),
|
28
|
+
'WJ-Beginn' => Date.new(2016, 1, 1),
|
29
|
+
'Bezeichnung' => 'Keepr-Buchungen') do |posting|
|
29
30
|
{ 'Identifikationsnummer' => "ID:#{posting.id}" }
|
30
31
|
end
|
31
|
-
|
32
|
+
end
|
32
33
|
|
33
34
|
describe :to_s do
|
34
35
|
subject { export.to_s }
|
@@ -37,30 +38,30 @@ describe Keepr::JournalExport do
|
|
37
38
|
subject.lines[2..-1]
|
38
39
|
end
|
39
40
|
|
40
|
-
it
|
41
|
+
it 'should return CSV lines' do
|
41
42
|
expect(subject.lines.count).to eq(2)
|
42
43
|
subject.lines.each { |line| expect(line).to include(';') }
|
43
44
|
end
|
44
45
|
|
45
|
-
it
|
46
|
+
it 'should include header data' do
|
46
47
|
expect(subject.lines[0]).to include('1234567;')
|
47
48
|
expect(subject.lines[0]).to include('78901;')
|
48
49
|
expect(subject.lines[0]).to include('20160601;20160630;')
|
49
50
|
expect(subject.lines[0]).to include('"Keepr-Buchungen";')
|
50
51
|
end
|
51
52
|
|
52
|
-
context
|
53
|
+
context 'Journal without tax' do
|
53
54
|
let!(:journal_without_tax) do
|
54
|
-
Keepr::Journal.create! :
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
{ :
|
59
|
-
{ :
|
55
|
+
Keepr::Journal.create! number: 'BELEG-1',
|
56
|
+
subject: 'Geldautomat',
|
57
|
+
date: Date.new(2016, 0o6, 23),
|
58
|
+
keepr_postings_attributes: [
|
59
|
+
{ keepr_account: account_1000, amount: 105, side: 'debit' },
|
60
|
+
{ keepr_account: account_1200, amount: 105, side: 'credit' }
|
60
61
|
]
|
61
62
|
end
|
62
63
|
|
63
|
-
it
|
64
|
+
it 'should include data' do
|
64
65
|
expect(booking_lines.count).to eq(1)
|
65
66
|
|
66
67
|
expect(booking_lines[0]).to include('"Geldautomat";')
|
@@ -73,19 +74,19 @@ describe Keepr::JournalExport do
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
|
-
context
|
77
|
+
context 'Journal with tax' do
|
77
78
|
let!(:journal_with_tax) do
|
78
|
-
Keepr::Journal.create! :
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
{ :
|
83
|
-
{ :
|
84
|
-
{ :
|
79
|
+
Keepr::Journal.create! number: 'BELEG-2',
|
80
|
+
subject: 'Telefonrechnung',
|
81
|
+
date: Date.new(2016, 0o6, 24),
|
82
|
+
keepr_postings_attributes: [
|
83
|
+
{ keepr_account: account_4920, amount: 8.40, side: 'debit' },
|
84
|
+
{ keepr_account: account_1576, amount: 1.60, side: 'debit' },
|
85
|
+
{ keepr_account: account_1600, amount: 10.00, side: 'credit' }
|
85
86
|
]
|
86
87
|
end
|
87
88
|
|
88
|
-
it
|
89
|
+
it 'should include data' do
|
89
90
|
expect(booking_lines.count).to eq(2)
|
90
91
|
|
91
92
|
expect(booking_lines[0]).to include('"Telefonrechnung";')
|
@@ -106,22 +107,22 @@ describe Keepr::JournalExport do
|
|
106
107
|
end
|
107
108
|
end
|
108
109
|
|
109
|
-
context
|
110
|
+
context 'Journal with debtor' do
|
110
111
|
let!(:journal_with_debtor) do
|
111
|
-
Keepr::Journal.create! :
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
{ :
|
116
|
-
{ :
|
117
|
-
{ :
|
118
|
-
|
119
|
-
{ :
|
120
|
-
{ :
|
112
|
+
Keepr::Journal.create! number: 'BELEG-3',
|
113
|
+
subject: 'Warenverkauf mit Anzahlung',
|
114
|
+
date: Date.new(2016, 0o6, 25),
|
115
|
+
keepr_postings_attributes: [
|
116
|
+
{ keepr_account: account_10000, amount: 4760.00, side: 'debit' },
|
117
|
+
{ keepr_account: account_1718, amount: 1000.00, side: 'debit' },
|
118
|
+
{ keepr_account: account_1776, amount: 190.00, side: 'debit' },
|
119
|
+
|
120
|
+
{ keepr_account: account_8400, amount: 5000.00, side: 'credit' },
|
121
|
+
{ keepr_account: account_1776, amount: 950.00, side: 'credit' }
|
121
122
|
]
|
122
123
|
end
|
123
124
|
|
124
|
-
it
|
125
|
+
it 'should include data' do
|
125
126
|
expect(booking_lines.count).to eq(4)
|
126
127
|
|
127
128
|
expect(booking_lines[0]).to include('"Warenverkauf mit Anzahlung";')
|
@@ -157,7 +158,7 @@ describe Keepr::JournalExport do
|
|
157
158
|
expect(booking_lines[3]).to include(';0;')
|
158
159
|
end
|
159
160
|
|
160
|
-
it
|
161
|
+
it 'should include data from block' do
|
161
162
|
expect(booking_lines[0]).to include('ID:')
|
162
163
|
expect(booking_lines[1]).to include('ID:')
|
163
164
|
end
|
@@ -165,7 +166,7 @@ describe Keepr::JournalExport do
|
|
165
166
|
end
|
166
167
|
|
167
168
|
describe :to_file do
|
168
|
-
it
|
169
|
+
it 'should create CSV file' do
|
169
170
|
Dir.mktmpdir do |dir|
|
170
171
|
filename = "#{dir}/EXTF_Buchungsstapel.csv"
|
171
172
|
export.to_file(filename)
|