keepr 0.3.2 → 0.4.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 +11 -15
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/ci/Gemfile-rails-4-1 +1 -1
- data/ci/Gemfile-rails-4-2 +1 -1
- data/ci/Gemfile-rails-5-0 +1 -1
- data/ci/Gemfile-rails-5-1 +1 -1
- data/ci/Gemfile-rails-5-2 +12 -0
- data/keepr.gemspec +2 -2
- data/lib/generators/keepr/migration/templates/migration.rb +24 -24
- data/lib/keepr/account.rb +42 -37
- data/lib/keepr/active_record_extension.rb +6 -6
- data/lib/keepr/cost_center.rb +1 -1
- data/lib/keepr/group.rb +13 -7
- data/lib/keepr/groups_creator.rb +4 -4
- data/lib/keepr/journal.rb +6 -6
- data/lib/keepr/journal_export.rb +1 -1
- data/lib/keepr/posting.rb +8 -8
- data/lib/keepr/tax.rb +2 -2
- data/lib/keepr/version.rb +1 -1
- data/spec/factories/account.rb +1 -1
- data/spec/factories/cost_center.rb +1 -1
- data/spec/factories/group.rb +1 -1
- data/spec/factories/tax.rb +2 -2
- data/spec/keepr/account_export_spec.rb +7 -7
- data/spec/keepr/account_spec.rb +55 -55
- data/spec/keepr/active_record_extension_spec.rb +30 -30
- data/spec/keepr/contact_export_spec.rb +3 -3
- data/spec/keepr/cost_center_spec.rb +7 -7
- data/spec/keepr/group_spec.rb +25 -25
- data/spec/keepr/journal_export_spec.rb +34 -34
- data/spec/keepr/journal_spec.rb +29 -29
- data/spec/keepr/posting_spec.rb +17 -17
- data/spec/keepr/tax_spec.rb +11 -11
- data/spec/spec_helper.rb +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c077965d94021d6d19a624c4c93a3d6ac23f3f90f1c4f74b6518c56da54ac625
|
4
|
+
data.tar.gz: 22afd3248d4a5e3476c09c383323a402847c73d997b14216066432083c968236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278fc8320da492345c89a0e957e65d933b479c1a48fa286454353f5a1814f8d8ee6ae95e894ec1ee9f3083193629f537f361f54be7a66cd14da45937ec528b0f
|
7
|
+
data.tar.gz: 6456e4cad08500ba0d8c80891588b2c3e8c65ec26cc014908c9a7e15b9398cdcc63506483d0499ffb05677930445be0bf029193215752f38b8164bbe00c07cdc
|
data/.travis.yml
CHANGED
@@ -1,26 +1,22 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.4.1
|
3
|
+
- 2.2.10
|
4
|
+
- 2.3.7
|
5
|
+
- 2.4.4
|
6
|
+
- 2.5.1
|
8
7
|
gemfile:
|
9
8
|
- ci/Gemfile-rails-4-1
|
10
9
|
- ci/Gemfile-rails-4-2
|
11
10
|
- ci/Gemfile-rails-5-0
|
12
11
|
- ci/Gemfile-rails-5-1
|
12
|
+
- ci/Gemfile-rails-5-2
|
13
13
|
matrix:
|
14
14
|
exclude:
|
15
|
-
- rvm: 2.
|
16
|
-
gemfile: ci/Gemfile-rails-5-1
|
17
|
-
- rvm: 2.1.10
|
18
|
-
gemfile: ci/Gemfile-rails-5-1
|
19
|
-
- rvm: 2.0.0
|
20
|
-
gemfile: ci/Gemfile-rails-5-0
|
21
|
-
- rvm: 2.1.10
|
22
|
-
gemfile: ci/Gemfile-rails-5-0
|
23
|
-
- rvm: 2.4.1
|
15
|
+
- rvm: 2.4.4
|
24
16
|
gemfile: ci/Gemfile-rails-4-1
|
25
|
-
|
17
|
+
- rvm: 2.5.1
|
18
|
+
gemfile: ci/Gemfile-rails-4-1
|
19
|
+
before_install:
|
20
|
+
- gem update --system
|
21
|
+
- gem update bundler
|
26
22
|
sudo: false
|
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.1
|
22
|
+
* Ruby 2.2+
|
23
|
+
* Rails 4.1+ (including Rails 5.2)
|
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-2018 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
|
data/Rakefile
CHANGED
data/ci/Gemfile-rails-4-1
CHANGED
data/ci/Gemfile-rails-4-2
CHANGED
data/ci/Gemfile-rails-5-0
CHANGED
data/ci/Gemfile-rails-5-1
CHANGED
data/keepr.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = %q{Some basic ActiveRecord models to build a double entry bookkeeping application}
|
13
13
|
spec.homepage = 'https://github.com/ledermann/keepr'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 2.
|
15
|
+
spec.required_ruby_version = '>= 2.2.2'
|
16
16
|
|
17
17
|
spec.files = `git ls-files`.split($/)
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'sqlite3'
|
29
29
|
spec.add_development_dependency 'rspec'
|
30
30
|
spec.add_development_dependency 'database_cleaner'
|
31
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'factory_bot'
|
32
32
|
spec.add_development_dependency 'coveralls'
|
33
33
|
spec.add_development_dependency 'simplecov'
|
34
34
|
end
|
@@ -1,55 +1,55 @@
|
|
1
1
|
class KeeprMigration < Keepr::MIGRATION_BASE_CLASS
|
2
2
|
def self.up
|
3
3
|
create_table Keepr::Group, force: true do |t|
|
4
|
-
t.integer :target, :
|
4
|
+
t.integer :target, null: false
|
5
5
|
t.string :number
|
6
|
-
t.string :name, :
|
7
|
-
t.boolean :is_result, :
|
8
|
-
t.string :ancestry, :
|
6
|
+
t.string :name, null: false
|
7
|
+
t.boolean :is_result, null: false, default: false
|
8
|
+
t.string :ancestry, index: true
|
9
9
|
end
|
10
10
|
|
11
11
|
create_table Keepr::Tax, force: true do |t|
|
12
|
-
t.string :name, :
|
12
|
+
t.string :name, null: false
|
13
13
|
t.string :description
|
14
|
-
t.decimal :value, :
|
15
|
-
t.references :keepr_account, :
|
14
|
+
t.decimal :value, precision: 8, scale: 2, null: false
|
15
|
+
t.references :keepr_account, null: false, index: true
|
16
16
|
end
|
17
17
|
|
18
18
|
create_table Keepr::CostCenter, force: true do |t|
|
19
|
-
t.string :number, :
|
20
|
-
t.string :name, :
|
19
|
+
t.string :number, null: false
|
20
|
+
t.string :name, null: false
|
21
21
|
t.text :note
|
22
22
|
end
|
23
23
|
|
24
24
|
create_table Keepr::Account, force: true do |t|
|
25
|
-
t.integer :number, :
|
26
|
-
t.string :ancestry, :
|
27
|
-
t.string :name, :
|
28
|
-
t.integer :kind, :
|
29
|
-
t.references :keepr_group, :
|
30
|
-
t.references :accountable, :
|
31
|
-
t.references :keepr_tax, :
|
25
|
+
t.integer :number, null: false, index: true
|
26
|
+
t.string :ancestry, index: true
|
27
|
+
t.string :name, null: false
|
28
|
+
t.integer :kind, null: false
|
29
|
+
t.references :keepr_group, index: true
|
30
|
+
t.references :accountable, polymorphic: true, index: true
|
31
|
+
t.references :keepr_tax, index: true
|
32
32
|
t.datetime :created_at
|
33
33
|
t.datetime :updated_at
|
34
34
|
end
|
35
35
|
|
36
36
|
create_table Keepr::Journal, force: true do |t|
|
37
37
|
t.string :number
|
38
|
-
t.date :date, :
|
38
|
+
t.date :date, null: false, index: true
|
39
39
|
t.string :subject
|
40
|
-
t.references :accountable, :
|
40
|
+
t.references :accountable, polymorphic: true, index: true
|
41
41
|
t.text :note
|
42
|
-
t.boolean :permanent, :
|
42
|
+
t.boolean :permanent, null: false, default: false
|
43
43
|
t.datetime :created_at
|
44
44
|
t.datetime :updated_at
|
45
45
|
end
|
46
46
|
|
47
47
|
create_table Keepr::Posting, force: true do |t|
|
48
|
-
t.references :keepr_account, :
|
49
|
-
t.references :keepr_journal, :
|
50
|
-
t.decimal :amount, :
|
51
|
-
t.references :keepr_cost_center, :
|
52
|
-
t.references :accountable, :
|
48
|
+
t.references :keepr_account, null: false, index: true
|
49
|
+
t.references :keepr_journal, null: false, index: true
|
50
|
+
t.decimal :amount, precision: 8, scale: 2, null: false
|
51
|
+
t.references :keepr_cost_center, index: true
|
52
|
+
t.references :accountable, polymorphic: true, index: true
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
data/lib/keepr/account.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
class Keepr::Account < ActiveRecord::Base
|
2
2
|
self.table_name = 'keepr_accounts'
|
3
3
|
|
4
|
-
has_ancestry :
|
4
|
+
has_ancestry orphan_strategy: :restrict
|
5
5
|
|
6
|
-
enum :
|
6
|
+
enum kind: [ :asset, :liability, :revenue, :expense, :forward, :debtor, :creditor ]
|
7
7
|
|
8
8
|
validates_presence_of :number, :name
|
9
9
|
validates_uniqueness_of :number
|
10
10
|
validate :group_validation
|
11
11
|
validate :tax_validation
|
12
12
|
|
13
|
-
has_many :keepr_postings, :
|
14
|
-
has_many :keepr_taxes, :
|
13
|
+
has_many :keepr_postings, class_name: 'Keepr::Posting', foreign_key: 'keepr_account_id', dependent: :restrict_with_error
|
14
|
+
has_many :keepr_taxes, class_name: 'Keepr::Tax', foreign_key: 'keepr_account_id', dependent: :restrict_with_error
|
15
15
|
|
16
|
-
belongs_to :keepr_tax, :
|
17
|
-
belongs_to :keepr_group, :
|
18
|
-
belongs_to :accountable, :
|
16
|
+
belongs_to :keepr_tax, class_name: 'Keepr::Tax'
|
17
|
+
belongs_to :keepr_group, class_name: 'Keepr::Group'
|
18
|
+
belongs_to :accountable, polymorphic: true
|
19
19
|
|
20
20
|
default_scope { order(:number) }
|
21
21
|
|
@@ -30,18 +30,18 @@ class Keepr::Account < ActiveRecord::Base
|
|
30
30
|
date = options[:date]
|
31
31
|
permanent_only = options[:permanent_only]
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
case date
|
34
|
+
when nil
|
35
|
+
when Date
|
36
|
+
subquery = subquery.where('keepr_journals.date <= ?', date)
|
37
|
+
when Range
|
38
|
+
subquery = subquery.where(keepr_journals: { date: date.first..date.last })
|
39
|
+
else
|
40
|
+
raise ArgumentError
|
41
41
|
end
|
42
42
|
|
43
43
|
if permanent_only
|
44
|
-
subquery = subquery.where
|
44
|
+
subquery = subquery.where(keepr_journals: { permanent: true })
|
45
45
|
end
|
46
46
|
|
47
47
|
select "keepr_accounts.*, (#{subquery.to_sql}) AS sum_amount"
|
@@ -80,17 +80,22 @@ class Keepr::Account < ActiveRecord::Base
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def balance(date=nil)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
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 })
|
91
94
|
else
|
92
|
-
|
95
|
+
raise ArgumentError
|
93
96
|
end
|
97
|
+
|
98
|
+
scope.sum(:amount)
|
94
99
|
end
|
95
100
|
|
96
101
|
def number_as_string
|
@@ -107,19 +112,19 @@ class Keepr::Account < ActiveRecord::Base
|
|
107
112
|
|
108
113
|
private
|
109
114
|
def group_validation
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
errors.add(:keepr_group_id, :no_group_allowed_for_result) if keepr_group.is_result
|
115
|
+
return unless keepr_group.present?
|
116
|
+
|
117
|
+
if asset?
|
118
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.asset?
|
119
|
+
elsif liability?
|
120
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.liability?
|
121
|
+
elsif profit_and_loss?
|
122
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.profit_and_loss?
|
123
|
+
else
|
124
|
+
errors.add(:kind, :group_conflict)
|
122
125
|
end
|
126
|
+
|
127
|
+
errors.add(:keepr_group_id, :no_group_allowed_for_result) if keepr_group.is_result
|
123
128
|
end
|
124
129
|
|
125
130
|
def tax_validation
|
@@ -5,17 +5,17 @@ module Keepr::ActiveRecordExtension
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def has_one_keepr_account
|
8
|
-
has_one :keepr_account, :
|
9
|
-
has_many :keepr_postings, :
|
8
|
+
has_one :keepr_account, class_name: 'Keepr::Account', as: :accountable, dependent: :restrict_with_error
|
9
|
+
has_many :keepr_postings, class_name: 'Keepr::Posting', through: :keepr_account, dependent: :restrict_with_error
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_many_keepr_accounts
|
13
|
-
has_many :keepr_accounts, :
|
14
|
-
has_many :keepr_postings, :
|
13
|
+
has_many :keepr_accounts, class_name: 'Keepr::Account', as: :accountable, dependent: :restrict_with_error
|
14
|
+
has_many :keepr_postings, class_name: 'Keepr::Posting', through: :keepr_accounts, dependent: :restrict_with_error
|
15
15
|
end
|
16
16
|
|
17
17
|
def has_keepr_journals
|
18
|
-
has_many :keepr_journals, :
|
18
|
+
has_many :keepr_journals, class_name: 'Keepr::Journal', as: :accountable, dependent: :restrict_with_error
|
19
19
|
|
20
20
|
class_eval <<-EOT
|
21
21
|
def keepr_booked?
|
@@ -31,7 +31,7 @@ module Keepr::ActiveRecordExtension
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def has_keepr_postings
|
34
|
-
has_many :keepr_postings, :
|
34
|
+
has_many :keepr_postings, class_name: 'Keepr::Posting', as: :accountable, dependent: :restrict_with_error
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/keepr/cost_center.rb
CHANGED
@@ -4,5 +4,5 @@ class Keepr::CostCenter < ActiveRecord::Base
|
|
4
4
|
validates_presence_of :number, :name
|
5
5
|
validates_uniqueness_of :number
|
6
6
|
|
7
|
-
has_many :keepr_postings, :
|
7
|
+
has_many :keepr_postings, class_name: 'Keepr::Posting', foreign_key: 'keepr_cost_center_id', dependent: :restrict_with_error
|
8
8
|
end
|
data/lib/keepr/group.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
class Keepr::Group < ActiveRecord::Base
|
2
2
|
self.table_name = 'keepr_groups'
|
3
3
|
|
4
|
-
has_ancestry :
|
4
|
+
has_ancestry orphan_strategy: :restrict
|
5
5
|
|
6
|
-
enum :
|
6
|
+
enum target: [ :asset, :liability, :profit_and_loss ]
|
7
7
|
|
8
8
|
validates_presence_of :name
|
9
9
|
|
10
|
-
has_many :keepr_accounts, :
|
10
|
+
has_many :keepr_accounts, class_name: 'Keepr::Account', foreign_key: 'keepr_group_id', dependent: :restrict_with_error
|
11
11
|
|
12
12
|
before_validation :get_from_parent
|
13
13
|
|
14
14
|
validate :check_result_and_target
|
15
15
|
|
16
16
|
def self.result
|
17
|
-
where(:
|
17
|
+
where(is_result: true).first
|
18
18
|
end
|
19
19
|
|
20
20
|
def keepr_postings
|
21
21
|
if is_result
|
22
|
-
Keepr::Posting.
|
23
|
-
|
22
|
+
Keepr::Posting.
|
23
|
+
joins(:keepr_account).
|
24
|
+
where(keepr_accounts: { kind: [
|
25
|
+
Keepr::Account.kinds[:revenue],
|
26
|
+
Keepr::Account.kinds[:expense]
|
27
|
+
]})
|
24
28
|
else
|
25
|
-
Keepr::Posting.
|
29
|
+
Keepr::Posting.
|
30
|
+
joins(keepr_account: :keepr_group).
|
31
|
+
merge(self.subtree)
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
data/lib/keepr/groups_creator.rb
CHANGED
@@ -9,10 +9,10 @@ class Keepr::GroupsCreator
|
|
9
9
|
def run
|
10
10
|
case @target
|
11
11
|
when :balance then
|
12
|
-
load 'asset.txt', :
|
13
|
-
load 'liability.txt', :
|
12
|
+
load 'asset.txt', target: :asset
|
13
|
+
load 'liability.txt', target: :liability
|
14
14
|
when :profit_and_loss
|
15
|
-
load 'profit_and_loss.txt', :
|
15
|
+
load 'profit_and_loss.txt', target: :profit_and_loss
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -30,7 +30,7 @@ private
|
|
30
30
|
# Remove leading spaces and separate number and name
|
31
31
|
number, name = line.lstrip.match(/^(.*?)\s(.+)$/).to_a[1..-1]
|
32
32
|
|
33
|
-
attributes = options.merge(:
|
33
|
+
attributes = options.merge(name: name, number: number)
|
34
34
|
if @target == :balance && name == 'Jahresüberschuss/Jahresfehlbetrag'
|
35
35
|
attributes[:is_result] = true
|
36
36
|
end
|