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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +44 -0
  3. data/.travis.yml +9 -9
  4. data/Gemfile +2 -0
  5. data/LICENSE.txt +1 -1
  6. data/README.md +3 -3
  7. data/Rakefile +2 -0
  8. data/ci/Gemfile-rails-4-2 +3 -2
  9. data/ci/Gemfile-rails-5-0 +3 -2
  10. data/ci/Gemfile-rails-5-1 +3 -2
  11. data/ci/Gemfile-rails-5-2 +3 -2
  12. data/ci/{Gemfile-rails-4-1 → Gemfile-rails-6-0} +3 -2
  13. data/keepr.gemspec +14 -12
  14. data/lib/generators/keepr/migration/migration_generator.rb +5 -3
  15. data/lib/generators/keepr/migration/templates/migration.rb +2 -0
  16. data/lib/keepr.rb +6 -4
  17. data/lib/keepr/account.rb +37 -37
  18. data/lib/keepr/account_export.rb +10 -14
  19. data/lib/keepr/active_record_extension.rb +4 -2
  20. data/lib/keepr/contact_export.rb +6 -7
  21. data/lib/keepr/cost_center.rb +2 -0
  22. data/lib/keepr/group.rb +21 -20
  23. data/lib/keepr/groups_creator.rb +7 -7
  24. data/lib/keepr/journal.rb +14 -11
  25. data/lib/keepr/journal_export.rb +9 -6
  26. data/lib/keepr/posting.rb +21 -16
  27. data/lib/keepr/tax.rb +2 -0
  28. data/lib/keepr/version.rb +3 -1
  29. data/spec/factories/account.rb +5 -3
  30. data/spec/factories/cost_center.rb +4 -2
  31. data/spec/factories/group.rb +4 -2
  32. data/spec/factories/tax.rb +5 -3
  33. data/spec/keepr/account_export_spec.rb +22 -19
  34. data/spec/keepr/account_spec.rb +47 -42
  35. data/spec/keepr/active_record_extension_spec.rb +20 -18
  36. data/spec/keepr/contact_export_spec.rb +17 -14
  37. data/spec/keepr/cost_center_spec.rb +2 -0
  38. data/spec/keepr/group_spec.rb +39 -35
  39. data/spec/keepr/groups_creator_spec.rb +7 -4
  40. data/spec/keepr/journal_export_spec.rb +26 -25
  41. data/spec/keepr/journal_spec.rb +33 -31
  42. data/spec/keepr/posting_spec.rb +8 -6
  43. data/spec/keepr/tax_spec.rb +21 -14
  44. data/spec/spec_helper.rb +6 -5
  45. data/spec/support/contact.rb +2 -0
  46. data/spec/support/document.rb +2 -0
  47. data/spec/support/ledger.rb +2 -0
  48. data/spec/support/spec_migration.rb +2 -0
  49. metadata +28 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c077965d94021d6d19a624c4c93a3d6ac23f3f90f1c4f74b6518c56da54ac625
4
- data.tar.gz: 22afd3248d4a5e3476c09c383323a402847c73d997b14216066432083c968236
3
+ metadata.gz: b05feec2870ab3c67b501c7f485f7c2a0a05e44357c416f2f83b5749b4c5a860
4
+ data.tar.gz: c706bf22151ff63fff5be0921ae4f49c1f72ef79907bc719dea5b7485298469e
5
5
  SHA512:
6
- metadata.gz: 278fc8320da492345c89a0e957e65d933b479c1a48fa286454353f5a1814f8d8ee6ae95e894ec1ee9f3083193629f537f361f54be7a66cd14da45937ec528b0f
7
- data.tar.gz: 6456e4cad08500ba0d8c80891588b2c3e8c65ec26cc014908c9a7e15b9398cdcc63506483d0499ffb05677930445be0bf029193215752f38b8164bbe00c07cdc
6
+ metadata.gz: 15ac6a10623a8441a17ac7c7eea8ec97094c7d5e7a8498028f21d993b05c5d27ae245bbf9e804a8dfdcf67f5770dec664d34810d48d19d10850461fcb3b29026
7
+ data.tar.gz: '08cfa52e53f1aa28a588be6e2646f38f99b65b2ac21eadcff0069d8622d1b8323ac7937dc368e4498ae5b5872208a9b617a3307f3dd29567ff08f02512ade605'
@@ -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
@@ -1,21 +1,21 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.10
4
- - 2.3.7
5
- - 2.4.4
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.4
16
- gemfile: ci/Gemfile-rails-4-1
17
- - rvm: 2.5.1
18
- gemfile: ci/Gemfile-rails-4-1
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in keepr.gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2018 Georg Ledermann
1
+ Copyright (c) 2013-2019 Georg Ledermann
2
2
 
3
3
  MIT License
4
4
 
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.2+
23
- * Rails 4.1+ (including Rails 5.2)
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-2018 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
67
+ Copyright (c) 2013-2019 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.2.8'
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'
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 5.0.2'
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'
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 5.1.0'
3
+ gem 'activerecord', '~> 5.1.7'
4
4
  gem 'ancestry'
5
- gem 'sqlite3'
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', '~> 5.2.0'
3
+ gem 'activerecord', '~> 5.2.3'
4
4
  gem 'ancestry'
5
- gem 'sqlite3'
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', '~> 4.1.16'
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'
@@ -1,34 +1,36 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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 = "keepr"
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 = %q{Double entry bookkeeping with Rails}
12
- spec.summary = %q{Some basic ActiveRecord models to build a double entry bookkeeping application}
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.2.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.1'
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 'rake'
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 'coveralls'
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('../templates', __FILE__)
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("%Y%m%d%H%M%S")
19
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
18
20
  else
19
- "%.3d" % (current_migration_number(dirname) + 1)
21
+ format('%.3d', (current_migration_number(dirname) + 1))
20
22
  end
21
23
  end
22
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class KeeprMigration < Keepr::MIGRATION_BASE_CLASS
2
4
  def self.up
3
5
  create_table Keepr::Group, force: true do |t|
@@ -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
- ActiveRecord::Migration[5.0]
23
- else
24
- ActiveRecord::Migration
25
- end
24
+ ActiveRecord::Migration[5.0]
25
+ else
26
+ ActiveRecord::Migration
27
+ end
@@ -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: [ :asset, :liability, :revenue, :expense, :forward, :debtor, :creditor ]
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
- select('SUM(keepr_postings.amount)').
27
- joins(:keepr_journal).
28
- where('keepr_postings.keepr_account_id = keepr_accounts.id')
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] do
55
+ while (account = accounts[position])
56
56
  if account.parent_id && account.sum_amount
57
- if parent_account = accounts.find { |a| a.id == account.parent_id }
58
- parent_account.sum_amount ||= 0
59
- parent_account.sum_amount += account.sum_amount
60
- accounts.delete_at(position)
61
- else
62
- raise RuntimeError
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
- when nil
85
- keepr_postings
86
- when Date
87
- keepr_postings.
88
- joins(:keepr_journal).
89
- where('keepr_journals.date <= ?', date)
90
- when Range
91
- keepr_postings.
92
- joins(:keepr_journal).
93
- where(keepr_journals: { date: date.first..date.last })
94
- else
95
- raise ArgumentError
96
- end
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
- "%04d" % number
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
 
@@ -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
- def to_s
9
- export.to_s
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
- { 'Konto' => account.number,
32
- 'Kontenbeschriftung' => account.name.slice(0,40)
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