keepr 0.4.0 → 0.5.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 +4 -4
- data/.rubocop.yml +44 -0
- data/.travis.yml +9 -9
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/Rakefile +2 -0
- data/ci/Gemfile-rails-4-2 +3 -2
- data/ci/Gemfile-rails-5-0 +3 -2
- data/ci/Gemfile-rails-5-1 +3 -2
- data/ci/Gemfile-rails-5-2 +3 -2
- data/ci/{Gemfile-rails-4-1 → Gemfile-rails-6-0} +3 -2
- data/keepr.gemspec +14 -12
- data/lib/generators/keepr/migration/migration_generator.rb +5 -3
- data/lib/generators/keepr/migration/templates/migration.rb +2 -0
- data/lib/keepr.rb +6 -4
- data/lib/keepr/account.rb +37 -37
- data/lib/keepr/account_export.rb +10 -14
- data/lib/keepr/active_record_extension.rb +4 -2
- data/lib/keepr/contact_export.rb +6 -7
- data/lib/keepr/cost_center.rb +2 -0
- data/lib/keepr/group.rb +21 -20
- data/lib/keepr/groups_creator.rb +7 -7
- data/lib/keepr/journal.rb +14 -11
- data/lib/keepr/journal_export.rb +9 -6
- data/lib/keepr/posting.rb +21 -16
- data/lib/keepr/tax.rb +2 -0
- data/lib/keepr/version.rb +3 -1
- data/spec/factories/account.rb +5 -3
- data/spec/factories/cost_center.rb +4 -2
- data/spec/factories/group.rb +4 -2
- data/spec/factories/tax.rb +5 -3
- data/spec/keepr/account_export_spec.rb +22 -19
- data/spec/keepr/account_spec.rb +47 -42
- data/spec/keepr/active_record_extension_spec.rb +20 -18
- data/spec/keepr/contact_export_spec.rb +17 -14
- data/spec/keepr/cost_center_spec.rb +2 -0
- data/spec/keepr/group_spec.rb +39 -35
- data/spec/keepr/groups_creator_spec.rb +7 -4
- data/spec/keepr/journal_export_spec.rb +26 -25
- data/spec/keepr/journal_spec.rb +33 -31
- data/spec/keepr/posting_spec.rb +8 -6
- data/spec/keepr/tax_spec.rb +21 -14
- data/spec/spec_helper.rb +6 -5
- 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 +2 -0
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b05feec2870ab3c67b501c7f485f7c2a0a05e44357c416f2f83b5749b4c5a860
|
4
|
+
data.tar.gz: c706bf22151ff63fff5be0921ae4f49c1f72ef79907bc719dea5b7485298469e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ac6a10623a8441a17ac7c7eea8ec97094c7d5e7a8498028f21d993b05c5d27ae245bbf9e804a8dfdcf67f5770dec664d34810d48d19d10850461fcb3b29026
|
7
|
+
data.tar.gz: '08cfa52e53f1aa28a588be6e2646f38f99b65b2ac21eadcff0069d8622d1b8323ac7937dc368e4498ae5b5872208a9b617a3307f3dd29567ff08f02512ade605'
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
|
4
|
+
|
5
|
+
Metrics/LineLength:
|
6
|
+
Max: 150
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Max: 150
|
10
|
+
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 50
|
13
|
+
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/ClassAndModuleChildren:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
|
25
|
+
Layout/AlignHash:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
|
29
|
+
Naming/PredicateName:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
|
33
|
+
Lint/EmptyWhen:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
|
37
|
+
Metrics/AbcSize:
|
38
|
+
Max: 40
|
39
|
+
|
40
|
+
Metrics/CyclomaticComplexity:
|
41
|
+
Max: 10
|
42
|
+
|
43
|
+
Metrics/PerceivedComplexity:
|
44
|
+
Max: 10
|
data/.travis.yml
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.5.1
|
3
|
+
- 2.4.6
|
4
|
+
- 2.5.5
|
5
|
+
- 2.6.3
|
7
6
|
gemfile:
|
8
|
-
- ci/Gemfile-rails-4-1
|
9
7
|
- ci/Gemfile-rails-4-2
|
10
8
|
- ci/Gemfile-rails-5-0
|
11
9
|
- ci/Gemfile-rails-5-1
|
12
10
|
- ci/Gemfile-rails-5-2
|
11
|
+
- ci/Gemfile-rails-6-0
|
13
12
|
matrix:
|
14
13
|
exclude:
|
15
|
-
- rvm: 2.4.
|
16
|
-
gemfile: ci/Gemfile-rails-
|
17
|
-
|
18
|
-
|
14
|
+
- rvm: 2.4.6
|
15
|
+
gemfile: ci/Gemfile-rails-6-0
|
16
|
+
script:
|
17
|
+
- bundle exec rake
|
18
|
+
- bundle exec rubocop
|
19
19
|
before_install:
|
20
20
|
- gem update --system
|
21
21
|
- gem update bundler
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -19,8 +19,8 @@ This Ruby gem provides a double entry accounting system for use in any Rails app
|
|
19
19
|
|
20
20
|
## Dependencies
|
21
21
|
|
22
|
-
* Ruby 2.
|
23
|
-
* Rails 4.
|
22
|
+
* Ruby 2.4+
|
23
|
+
* Rails 4.2+ (including Rails 6.0)
|
24
24
|
|
25
25
|
|
26
26
|
## Installation
|
@@ -64,4 +64,4 @@ TODO: Write usage instructions here
|
|
64
64
|
* https://github.com/bigfleet/accountable
|
65
65
|
|
66
66
|
|
67
|
-
Copyright (c) 2013-
|
67
|
+
Copyright (c) 2013-2019 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
|
data/Rakefile
CHANGED
data/ci/Gemfile-rails-4-2
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 4.2.
|
3
|
+
gem 'activerecord', '~> 4.2.11'
|
4
4
|
gem 'ancestry'
|
5
|
-
gem 'sqlite3'
|
5
|
+
gem 'sqlite3', '~> 1.3.6'
|
6
6
|
gem 'rake'
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'simplecov'
|
@@ -10,3 +10,4 @@ gem 'coveralls'
|
|
10
10
|
gem 'database_cleaner'
|
11
11
|
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
13
|
+
gem 'rubocop'
|
data/ci/Gemfile-rails-5-0
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 5.0.
|
3
|
+
gem 'activerecord', '~> 5.0.7'
|
4
4
|
gem 'ancestry'
|
5
|
-
gem 'sqlite3'
|
5
|
+
gem 'sqlite3', '~> 1.3.6'
|
6
6
|
gem 'rake'
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'simplecov'
|
@@ -10,3 +10,4 @@ gem 'coveralls'
|
|
10
10
|
gem 'database_cleaner'
|
11
11
|
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
13
|
+
gem 'rubocop'
|
data/ci/Gemfile-rails-5-1
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 5.1.
|
3
|
+
gem 'activerecord', '~> 5.1.7'
|
4
4
|
gem 'ancestry'
|
5
|
-
gem
|
5
|
+
gem "sqlite3", "~> 1.3", ">= 1.3.6"
|
6
6
|
gem 'rake'
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'simplecov'
|
@@ -10,3 +10,4 @@ gem 'coveralls'
|
|
10
10
|
gem 'database_cleaner'
|
11
11
|
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
13
|
+
gem 'rubocop'
|
data/ci/Gemfile-rails-5-2
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 5.2.
|
3
|
+
gem 'activerecord', '~> 5.2.3'
|
4
4
|
gem 'ancestry'
|
5
|
-
gem
|
5
|
+
gem "sqlite3", "~> 1.3", ">= 1.3.6"
|
6
6
|
gem 'rake'
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'simplecov'
|
@@ -10,3 +10,4 @@ gem 'coveralls'
|
|
10
10
|
gem 'database_cleaner'
|
11
11
|
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
13
|
+
gem 'rubocop'
|
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~>
|
3
|
+
gem 'activerecord', '~> 6.0.0'
|
4
4
|
gem 'ancestry'
|
5
|
-
gem 'sqlite3'
|
5
|
+
gem 'sqlite3', "~> 1.4"
|
6
6
|
gem 'rake'
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'simplecov'
|
@@ -10,3 +10,4 @@ gem 'coveralls'
|
|
10
10
|
gem 'database_cleaner'
|
11
11
|
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
13
|
+
gem 'rubocop'
|
data/keepr.gemspec
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'keepr/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'keepr'
|
8
9
|
spec.version = Keepr::VERSION
|
9
10
|
spec.authors = 'Georg Ledermann'
|
10
11
|
spec.email = 'mail@georg-ledermann.de'
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
12
|
+
spec.description = 'Double entry bookkeeping with Rails'
|
13
|
+
spec.summary = 'Some basic ActiveRecord models to build a double entry bookkeeping application'
|
13
14
|
spec.homepage = 'https://github.com/ledermann/keepr'
|
14
15
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 2.
|
16
|
+
spec.required_ruby_version = '>= 2.4'
|
16
17
|
|
17
|
-
spec.files = `git ls-files`.split(
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
21
|
spec.require_paths = ['lib']
|
21
22
|
|
22
|
-
spec.add_dependency 'activerecord', '>= 4.
|
23
|
+
spec.add_dependency 'activerecord', '>= 4.2'
|
23
24
|
spec.add_dependency 'ancestry'
|
24
25
|
spec.add_dependency 'datev', '>= 0.5.0'
|
25
26
|
|
26
27
|
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency '
|
28
|
-
spec.add_development_dependency 'sqlite3'
|
29
|
-
spec.add_development_dependency 'rspec'
|
28
|
+
spec.add_development_dependency 'coveralls'
|
30
29
|
spec.add_development_dependency 'database_cleaner'
|
31
30
|
spec.add_development_dependency 'factory_bot'
|
32
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'rake'
|
32
|
+
spec.add_development_dependency 'rspec'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
33
34
|
spec.add_development_dependency 'simplecov'
|
35
|
+
spec.add_development_dependency 'sqlite3'
|
34
36
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/generators'
|
2
4
|
require 'rails/generators/migration'
|
3
5
|
|
@@ -6,7 +8,7 @@ module Keepr
|
|
6
8
|
include Rails::Generators::Migration
|
7
9
|
|
8
10
|
desc 'Generates migration for keepr'
|
9
|
-
source_root File.expand_path('
|
11
|
+
source_root File.expand_path('templates', __dir__)
|
10
12
|
|
11
13
|
def create_migration_file
|
12
14
|
migration_template 'migration.rb', 'db/migrate/keepr_migration.rb'
|
@@ -14,9 +16,9 @@ module Keepr
|
|
14
16
|
|
15
17
|
def self.next_migration_number(dirname)
|
16
18
|
if ActiveRecord::Base.timestamped_migrations
|
17
|
-
Time.now.utc.strftime(
|
19
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
18
20
|
else
|
19
|
-
|
21
|
+
format('%.3d', (current_migration_number(dirname) + 1))
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/keepr.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ancestry'
|
2
4
|
require 'datev'
|
3
5
|
|
@@ -19,7 +21,7 @@ class ActiveRecord::Base
|
|
19
21
|
end
|
20
22
|
|
21
23
|
Keepr::MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
|
22
|
-
|
23
|
-
else
|
24
|
-
|
25
|
-
end
|
24
|
+
ActiveRecord::Migration[5.0]
|
25
|
+
else
|
26
|
+
ActiveRecord::Migration
|
27
|
+
end
|
data/lib/keepr/account.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Keepr::Account < ActiveRecord::Base
|
2
4
|
self.table_name = 'keepr_accounts'
|
3
5
|
|
4
6
|
has_ancestry orphan_strategy: :restrict
|
5
7
|
|
6
|
-
enum kind: [
|
8
|
+
enum kind: %i[asset liability revenue expense forward debtor creditor]
|
7
9
|
|
8
10
|
validates_presence_of :number, :name
|
9
11
|
validates_uniqueness_of :number
|
@@ -19,13 +21,13 @@ class Keepr::Account < ActiveRecord::Base
|
|
19
21
|
|
20
22
|
default_scope { order(:number) }
|
21
23
|
|
22
|
-
def self.with_sums(options={})
|
24
|
+
def self.with_sums(options = {})
|
23
25
|
raise ArgumentError unless options.is_a?(Hash)
|
24
26
|
|
25
|
-
subquery = Keepr::Posting
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
subquery = Keepr::Posting
|
28
|
+
.select('SUM(keepr_postings.amount)')
|
29
|
+
.joins(:keepr_journal)
|
30
|
+
.where('keepr_postings.keepr_account_id = keepr_accounts.id')
|
29
31
|
|
30
32
|
date = options[:date]
|
31
33
|
permanent_only = options[:permanent_only]
|
@@ -40,27 +42,24 @@ class Keepr::Account < ActiveRecord::Base
|
|
40
42
|
raise ArgumentError
|
41
43
|
end
|
42
44
|
|
43
|
-
if permanent_only
|
44
|
-
subquery = subquery.where(keepr_journals: { permanent: true })
|
45
|
-
end
|
45
|
+
subquery = subquery.where(keepr_journals: { permanent: true }) if permanent_only
|
46
46
|
|
47
47
|
select "keepr_accounts.*, (#{subquery.to_sql}) AS sum_amount"
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.merged_with_sums(options={})
|
50
|
+
def self.merged_with_sums(options = {})
|
51
51
|
accounts = with_sums(options).to_a
|
52
52
|
|
53
53
|
# Sum up child accounts to parent
|
54
54
|
position = 0
|
55
|
-
while account = accounts[position]
|
55
|
+
while (account = accounts[position])
|
56
56
|
if account.parent_id && account.sum_amount
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
57
|
+
parent_account = accounts.find { |a| a.id == account.parent_id }
|
58
|
+
raise RuntimeError unless parent_account
|
59
|
+
|
60
|
+
parent_account.sum_amount ||= 0
|
61
|
+
parent_account.sum_amount += account.sum_amount
|
62
|
+
accounts.delete_at(position)
|
64
63
|
else
|
65
64
|
position += 1
|
66
65
|
end
|
@@ -74,33 +73,33 @@ class Keepr::Account < ActiveRecord::Base
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def keepr_postings
|
77
|
-
Keepr::Posting
|
78
|
-
joins(:keepr_account)
|
79
|
-
where(subtree_conditions)
|
76
|
+
Keepr::Posting
|
77
|
+
.joins(:keepr_account)
|
78
|
+
.where(subtree_conditions)
|
80
79
|
end
|
81
80
|
|
82
|
-
def balance(date=nil)
|
81
|
+
def balance(date = nil)
|
83
82
|
scope = case date
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
83
|
+
when nil
|
84
|
+
keepr_postings
|
85
|
+
when Date
|
86
|
+
keepr_postings
|
87
|
+
.joins(:keepr_journal)
|
88
|
+
.where('keepr_journals.date <= ?', date)
|
89
|
+
when Range
|
90
|
+
keepr_postings
|
91
|
+
.joins(:keepr_journal)
|
92
|
+
.where(keepr_journals: { date: date.first..date.last })
|
93
|
+
else
|
94
|
+
raise ArgumentError
|
95
|
+
end
|
97
96
|
|
98
97
|
scope.sum(:amount)
|
99
98
|
end
|
100
99
|
|
101
100
|
def number_as_string
|
102
101
|
if number < 1000
|
103
|
-
|
102
|
+
format('%04d', number)
|
104
103
|
else
|
105
104
|
number.to_s
|
106
105
|
end
|
@@ -110,7 +109,8 @@ class Keepr::Account < ActiveRecord::Base
|
|
110
109
|
"#{number_as_string} (#{name})"
|
111
110
|
end
|
112
111
|
|
113
|
-
private
|
112
|
+
private
|
113
|
+
|
114
114
|
def group_validation
|
115
115
|
return unless keepr_group.present?
|
116
116
|
|
data/lib/keepr/account_export.rb
CHANGED
@@ -1,35 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Keepr::AccountExport
|
2
|
-
def initialize(accounts, header_options={}, &block)
|
4
|
+
def initialize(accounts, header_options = {}, &block)
|
3
5
|
@accounts = accounts
|
4
6
|
@header_options = header_options
|
5
7
|
@block = block
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_file(filename)
|
13
|
-
export.to_file(filename)
|
14
|
-
end
|
10
|
+
delegate :to_s, :to_file,
|
11
|
+
to: :export
|
15
12
|
|
16
|
-
private
|
13
|
+
private
|
17
14
|
|
18
15
|
def export
|
19
16
|
export = Datev::AccountExport.new(@header_options)
|
20
17
|
|
21
18
|
@accounts.reorder(:number).each do |account|
|
22
|
-
unless account.debtor? || account.creditor?
|
23
|
-
export << to_datev(account)
|
24
|
-
end
|
19
|
+
export << to_datev(account) unless account.debtor? || account.creditor?
|
25
20
|
end
|
26
21
|
|
27
22
|
export
|
28
23
|
end
|
29
24
|
|
30
25
|
def to_datev(account)
|
31
|
-
{
|
32
|
-
'
|
26
|
+
{
|
27
|
+
'Konto' => account.number,
|
28
|
+
'Kontenbeschriftung' => account.name.slice(0, 40)
|
33
29
|
}.merge(@block ? @block.call(account) : {})
|
34
30
|
end
|
35
31
|
end
|