keepr 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +14 -10
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +3 -3
  6. data/Rakefile +3 -1
  7. data/ci/Gemfile-rails-4-2 +4 -4
  8. data/ci/Gemfile-rails-5-0 +4 -4
  9. data/ci/Gemfile-rails-5-1 +12 -0
  10. data/ci/Gemfile-rails-5-2 +12 -0
  11. data/ci/{Gemfile-rails-4-1 → Gemfile-rails-6-0} +4 -4
  12. data/keepr.gemspec +15 -14
  13. data/lib/generators/keepr/migration/migration_generator.rb +5 -3
  14. data/lib/generators/keepr/migration/templates/migration.rb +27 -25
  15. data/lib/keepr.rb +8 -0
  16. data/lib/keepr/account.rb +66 -61
  17. data/lib/keepr/account_export.rb +10 -14
  18. data/lib/keepr/active_record_extension.rb +10 -8
  19. data/lib/keepr/contact_export.rb +6 -7
  20. data/lib/keepr/cost_center.rb +3 -1
  21. data/lib/keepr/group.rb +25 -16
  22. data/lib/keepr/groups_creator.rb +11 -11
  23. data/lib/keepr/journal.rb +19 -16
  24. data/lib/keepr/journal_export.rb +10 -7
  25. data/lib/keepr/posting.rb +26 -21
  26. data/lib/keepr/tax.rb +4 -2
  27. data/lib/keepr/version.rb +3 -1
  28. data/spec/factories/account.rb +6 -4
  29. data/spec/factories/cost_center.rb +5 -3
  30. data/spec/factories/group.rb +5 -3
  31. data/spec/factories/tax.rb +7 -5
  32. data/spec/keepr/account_export_spec.rb +30 -27
  33. data/spec/keepr/account_spec.rb +92 -87
  34. data/spec/keepr/active_record_extension_spec.rb +38 -36
  35. data/spec/keepr/contact_export_spec.rb +20 -17
  36. data/spec/keepr/cost_center_spec.rb +9 -7
  37. data/spec/keepr/group_spec.rb +53 -49
  38. data/spec/keepr/groups_creator_spec.rb +7 -4
  39. data/spec/keepr/journal_export_spec.rb +76 -75
  40. data/spec/keepr/journal_spec.rb +48 -46
  41. data/spec/keepr/posting_spec.rb +25 -23
  42. data/spec/keepr/tax_spec.rb +21 -14
  43. data/spec/spec_helper.rb +13 -11
  44. data/spec/support/contact.rb +2 -0
  45. data/spec/support/document.rb +2 -0
  46. data/spec/support/ledger.rb +2 -0
  47. data/spec/support/spec_migration.rb +3 -1
  48. metadata +23 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c36525234e1c745fd201672cbaa4148c8b024399
4
- data.tar.gz: faaf32245ff13cad1025be66f1a6414c56d1cdaf
2
+ SHA256:
3
+ metadata.gz: a7dfe416636ebe5a292bb6a49c43e8d1ffcec6be4711d14b3baaa7099f6efe48
4
+ data.tar.gz: 78691b1440c14e91497710e486b7fb3504f16ac6449900d930af39dbf427b872
5
5
  SHA512:
6
- metadata.gz: ac0e9adcd2ca80ad6e37d95886a06f23385f3dbc99d8a3d008178f0f1ff3cf3a1734016fe7cf033e5b992a0ccb860085c4f89f6bdc8c7beafcf5239ce65b66d1
7
- data.tar.gz: 40f93e86f9fb4a259aee40a28d93876a9f6c7e7bc0285164ccf6474fcbdce8fb1337189a57beacb30ed669b81fb5c41e9391b7ef7328be3b96c8ff9e8cf43406
6
+ metadata.gz: c5995815889beabb1bd25798c906fad998641775276d047089a1028485a72effe2fb9e5dca8a96de249d8dcd3a035073d10a0518259199b71b350c34c9d30d52
7
+ data.tar.gz: 2c6d8b7498e8d6abc21547a5f979da6d96c87328966de102aebcb8afdf139954cf1721ee45d46c3e9b582da4b541fba55b710fd8239ce2ee0fe57c7915a94dda
@@ -1,17 +1,21 @@
1
+ os: linux
2
+ dist: xenial
1
3
  language: ruby
2
4
  rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.5
6
- - 2.3.1
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
7
8
  gemfile:
8
- - ci/Gemfile-rails-4-1
9
9
  - ci/Gemfile-rails-4-2
10
10
  - ci/Gemfile-rails-5-0
11
+ - ci/Gemfile-rails-5-1
12
+ - ci/Gemfile-rails-5-2
13
+ - ci/Gemfile-rails-6-0
11
14
  matrix:
12
15
  exclude:
13
- - rvm: 2.0.0
14
- gemfile: ci/Gemfile-rails-5-0
15
- - rvm: 2.1.10
16
- gemfile: ci/Gemfile-rails-5-0
17
- before_install: gem update bundler
16
+ - rvm: 2.7.1
17
+ gemfile: ci/Gemfile-rails-4-2
18
+ script:
19
+ - bundle exec rake
20
+ before_install:
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-2016 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.0.0 or later
23
- * Rails 4.1 or newer (including Rails 5)
22
+ * Ruby 2.5+
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-2016 [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,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,12 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.2.6'
4
- gem 'ancestry'
5
- gem 'sqlite3'
3
+ gem 'activerecord', '~> 4.2.11'
4
+ gem 'ancestry', '>= 3.1.0'
5
+ gem 'sqlite3', '~> 1.3.6'
6
6
  gem 'rake'
7
7
  gem 'rspec'
8
8
  gem 'simplecov'
9
9
  gem 'coveralls'
10
10
  gem 'database_cleaner'
11
- gem 'factory_girl'
11
+ gem 'factory_bot'
12
12
  gem 'datev'
@@ -1,12 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 5.0.0'
4
- gem 'ancestry'
5
- gem 'sqlite3'
3
+ gem 'activerecord', '~> 5.0.7'
4
+ gem 'ancestry', '>= 3.1.0'
5
+ gem 'sqlite3', '~> 1.3.6'
6
6
  gem 'rake'
7
7
  gem 'rspec'
8
8
  gem 'simplecov'
9
9
  gem 'coveralls'
10
10
  gem 'database_cleaner'
11
- gem 'factory_girl'
11
+ gem 'factory_bot'
12
12
  gem 'datev'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.1.7'
4
+ gem 'ancestry', '>= 3.1.0'
5
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'simplecov'
9
+ gem 'coveralls'
10
+ gem 'database_cleaner'
11
+ gem 'factory_bot'
12
+ gem 'datev'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.2.3'
4
+ gem 'ancestry', '>= 3.1.0'
5
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'simplecov'
9
+ gem 'coveralls'
10
+ gem 'database_cleaner'
11
+ gem 'factory_bot'
12
+ gem 'datev'
@@ -1,12 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.1.15'
4
- gem 'ancestry'
5
- gem 'sqlite3'
3
+ gem 'activerecord', '~> 6.0.0'
4
+ gem 'ancestry', '>= 3.1.0'
5
+ gem 'sqlite3', "~> 1.4"
6
6
  gem 'rake'
7
7
  gem 'rspec'
8
8
  gem 'simplecov'
9
9
  gem 'coveralls'
10
10
  gem 'database_cleaner'
11
- gem 'factory_girl'
11
+ gem 'factory_bot'
12
12
  gem 'datev'
@@ -1,34 +1,35 @@
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.0.0'
16
+ spec.required_ruby_version = '>= 2.5'
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 'ancestry'
24
- spec.add_dependency 'datev', '>= 0.4.0'
23
+ spec.add_dependency 'activerecord', '>= 4.2'
24
+ spec.add_dependency 'ancestry', '>= 3.1.0'
25
+ spec.add_dependency 'datev', '>= 0.5.0'
25
26
 
26
27
  spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'database_cleaner'
30
+ spec.add_development_dependency 'factory_bot'
27
31
  spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'sqlite3'
29
32
  spec.add_development_dependency 'rspec'
30
- spec.add_development_dependency 'database_cleaner'
31
- spec.add_development_dependency 'factory_girl'
32
- spec.add_development_dependency 'coveralls'
33
33
  spec.add_development_dependency 'simplecov'
34
+ spec.add_development_dependency 'sqlite3'
34
35
  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,55 +1,57 @@
1
- class KeeprMigration < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class KeeprMigration < Keepr::MIGRATION_BASE_CLASS
2
4
  def self.up
3
5
  create_table Keepr::Group, force: true do |t|
4
- t.integer :target, :null => false
6
+ t.integer :target, null: false
5
7
  t.string :number
6
- t.string :name, :null => false
7
- t.boolean :is_result, :null => false, :default => false
8
- t.string :ancestry, :index => true
8
+ t.string :name, null: false
9
+ t.boolean :is_result, null: false, default: false
10
+ t.string :ancestry, index: true
9
11
  end
10
12
 
11
13
  create_table Keepr::Tax, force: true do |t|
12
- t.string :name, :null => false
14
+ t.string :name, null: false
13
15
  t.string :description
14
- t.decimal :value, :precision => 8, :scale => 2, :null => false
15
- t.references :keepr_account, :null => false, :index => true
16
+ t.decimal :value, precision: 8, scale: 2, null: false
17
+ t.references :keepr_account, null: false, index: true
16
18
  end
17
19
 
18
20
  create_table Keepr::CostCenter, force: true do |t|
19
- t.string :number, :null => false
20
- t.string :name, :null => false
21
+ t.string :number, null: false
22
+ t.string :name, null: false
21
23
  t.text :note
22
24
  end
23
25
 
24
26
  create_table Keepr::Account, force: true do |t|
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
27
+ t.integer :number, null: false, index: true
28
+ t.string :ancestry, index: true
29
+ t.string :name, null: false
30
+ t.integer :kind, null: false
31
+ t.references :keepr_group, index: true
32
+ t.references :accountable, polymorphic: true, index: true
33
+ t.references :keepr_tax, index: true
32
34
  t.datetime :created_at
33
35
  t.datetime :updated_at
34
36
  end
35
37
 
36
38
  create_table Keepr::Journal, force: true do |t|
37
39
  t.string :number
38
- t.date :date, :null => false, :index => true
40
+ t.date :date, null: false, index: true
39
41
  t.string :subject
40
- t.references :accountable, :polymorphic => true, :index => true
42
+ t.references :accountable, polymorphic: true, index: true
41
43
  t.text :note
42
- t.boolean :permanent, :null => false, :default => false
44
+ t.boolean :permanent, null: false, default: false
43
45
  t.datetime :created_at
44
46
  t.datetime :updated_at
45
47
  end
46
48
 
47
49
  create_table Keepr::Posting, force: true do |t|
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
50
+ t.references :keepr_account, null: false, index: true
51
+ t.references :keepr_journal, null: false, index: true
52
+ t.decimal :amount, precision: 8, scale: 2, null: false
53
+ t.references :keepr_cost_center, index: true
54
+ t.references :accountable, polymorphic: true, index: true
53
55
  end
54
56
  end
55
57
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ancestry'
2
4
  require 'datev'
3
5
 
@@ -17,3 +19,9 @@ require 'keepr/active_record_extension'
17
19
  class ActiveRecord::Base
18
20
  include Keepr::ActiveRecordExtension
19
21
  end
22
+
23
+ Keepr::MIGRATION_BASE_CLASS = if ActiveRecord::VERSION::MAJOR >= 5
24
+ ActiveRecord::Migration[5.0]
25
+ else
26
+ ActiveRecord::Migration
27
+ end
@@ -1,66 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::Account < ActiveRecord::Base
2
4
  self.table_name = 'keepr_accounts'
3
5
 
4
- has_ancestry :orphan_strategy => :restrict
6
+ has_ancestry orphan_strategy: :restrict
5
7
 
6
- enum :kind => [ :asset, :liability, :revenue, :expense, :neutral, :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
10
12
  validate :group_validation
11
13
  validate :tax_validation
12
14
 
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
+ has_many :keepr_postings, class_name: 'Keepr::Posting', foreign_key: 'keepr_account_id', dependent: :restrict_with_error
16
+ has_many :keepr_taxes, class_name: 'Keepr::Tax', foreign_key: 'keepr_account_id', dependent: :restrict_with_error
15
17
 
16
- belongs_to :keepr_tax, :class_name => 'Keepr::Tax'
17
- belongs_to :keepr_group, :class_name => 'Keepr::Group'
18
- belongs_to :accountable, :polymorphic => true
18
+ belongs_to :keepr_tax, class_name: 'Keepr::Tax'
19
+ belongs_to :keepr_group, class_name: 'Keepr::Group'
20
+ belongs_to :accountable, polymorphic: true
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]
32
34
 
33
- if date
34
- if date.is_a?(Date)
35
- subquery = subquery.where "keepr_journals.date <= '#{date.to_s(:db)}'"
36
- elsif date.is_a?(Range)
37
- subquery = subquery.where "keepr_journals.date BETWEEN '#{date.first.to_s(:db)}' AND '#{date.last.to_s(:db)}'"
38
- else
39
- raise ArgumentError
40
- end
35
+ case date
36
+ when nil
37
+ when Date
38
+ subquery = subquery.where('keepr_journals.date <= ?', date)
39
+ when Range
40
+ subquery = subquery.where(keepr_journals: { date: date.first..date.last })
41
+ else
42
+ raise ArgumentError
41
43
  end
42
44
 
43
- if permanent_only
44
- subquery = subquery.where "keepr_journals.permanent = #{connection.quoted_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,28 +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
+ .merge(subtree)
80
79
  end
81
80
 
82
- def balance(date=nil)
83
- if date
84
- if date.is_a?(Date)
85
- keepr_postings.joins(:keepr_journal).where("keepr_journals.date <= '#{date.to_s(:db)}'").sum(:amount)
86
- elsif date.is_a?(Range)
87
- keepr_postings.joins(:keepr_journal).where("keepr_journals.date BETWEEN '#{date.first.to_s(:db)}' AND '#{date.last.to_s(:db)}'").sum(:amount)
88
- else
89
- raise ArgumentError
90
- end
91
- else
92
- keepr_postings.sum(:amount)
93
- end
81
+ def balance(date = nil)
82
+ scope = case date
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
96
+
97
+ scope.sum(:amount)
94
98
  end
95
99
 
96
100
  def number_as_string
97
101
  if number < 1000
98
- "%04d" % number
102
+ format('%04d', number)
99
103
  else
100
104
  number.to_s
101
105
  end
@@ -105,21 +109,22 @@ class Keepr::Account < ActiveRecord::Base
105
109
  "#{number_as_string} (#{name})"
106
110
  end
107
111
 
108
- private
109
- def group_validation
110
- if keepr_group.present?
111
- if asset?
112
- errors.add(:kind, :group_mismatch) unless keepr_group.asset?
113
- elsif liability?
114
- errors.add(:kind, :group_mismatch) unless keepr_group.liability?
115
- elsif profit_and_loss?
116
- errors.add(:kind, :group_mismatch) unless keepr_group.profit_and_loss?
117
- else
118
- errors.add(:kind, :group_conflict)
119
- end
112
+ private
120
113
 
121
- errors.add(:keepr_group_id, :no_group_allowed_for_result) if keepr_group.is_result
114
+ def group_validation
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