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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2680eedcb47403d6bcbae90de674d208f8a9ab06570b20e122c0c641c42e114
|
4
|
+
data.tar.gz: c33827bf895e0e15ea763a5217eb2efa3ff0f9fa5a48ae74ee4c07750a56ee28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c5e2703b9ce01a2aed1b29c096ffc879518a10528fb1f31092c6fb5602c7b566eade957974ec381904525c3d3ff455937fbb38f12fa700778b6d9b06d1256f
|
7
|
+
data.tar.gz: bb4d6e29f65dd0fac3d5b3f3ff764511387e543371df91318bf1117b1a8d4aba9bc9dc245ac94b6a07bdf063aa8f5a93ed70322899067306881b3162e1ac4091
|
data/.travis.yml
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
+
os: linux
|
2
|
+
dist: xenial
|
1
3
|
language: ruby
|
2
4
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.2
|
6
|
-
- 2.3.1
|
5
|
+
- 2.5.8
|
6
|
+
- 2.6.6
|
7
|
+
- 2.7.2
|
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.
|
14
|
-
gemfile: ci/Gemfile-rails-
|
15
|
-
|
16
|
-
|
17
|
-
before_install:
|
16
|
+
- rvm: 2.7.2
|
17
|
+
gemfile: ci/Gemfile-rails-4-2
|
18
|
+
script:
|
19
|
+
- bundle exec rake
|
20
|
+
before_install:
|
21
|
+
- gem update bundler
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This Ruby gem provides a double entry accounting system for use in any Rails app
|
|
4
4
|
|
5
5
|
[](https://travis-ci.org/ledermann/keepr)
|
6
6
|
[](https://codeclimate.com/github/ledermann/keepr)
|
7
|
-
[](https://coveralls.io/
|
7
|
+
[](https://coveralls.io/github/ledermann/keepr?branch=master)
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
@@ -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.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-
|
67
|
+
Copyright (c) 2013-2020 [Georg Ledermann](https://ledermann.dev), released under the MIT license
|
data/Rakefile
CHANGED
data/ci/Gemfile-rails-4-2
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 4.2.
|
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
|
-
gem 'coveralls'
|
9
|
+
gem 'coveralls', '~> 0.8'
|
10
10
|
gem 'database_cleaner'
|
11
|
-
gem '
|
11
|
+
gem 'factory_bot'
|
12
12
|
gem 'datev'
|
data/ci/Gemfile-rails-5-0
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '~> 5.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
|
-
gem 'coveralls'
|
9
|
+
gem 'coveralls', '~> 0.8'
|
10
10
|
gem 'database_cleaner'
|
11
|
-
gem '
|
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', '~> 0.8'
|
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', '~> 0.8'
|
10
|
+
gem 'database_cleaner'
|
11
|
+
gem 'factory_bot'
|
12
|
+
gem 'datev'
|
data/keepr.gemspec
CHANGED
@@ -1,34 +1,35 @@
|
|
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
|
-
spec.email = '
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.email = 'georg@ledermann.dev'
|
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.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.
|
23
|
-
spec.add_dependency 'ancestry'
|
23
|
+
spec.add_dependency 'activerecord', '>= 4.2'
|
24
|
+
spec.add_dependency 'ancestry', '>= 3.1.0'
|
24
25
|
spec.add_dependency 'datev', '>= 0.5.0'
|
25
26
|
|
26
27
|
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
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('
|
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
|
@@ -1,55 +1,57 @@
|
|
1
|
-
|
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, :
|
6
|
+
t.integer :target, null: false
|
5
7
|
t.string :number
|
6
|
-
t.string :name, :
|
7
|
-
t.boolean :is_result, :
|
8
|
-
t.string :ancestry, :
|
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, :
|
14
|
+
t.string :name, null: false
|
13
15
|
t.string :description
|
14
|
-
t.decimal :value, :
|
15
|
-
t.references :keepr_account, :
|
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, :
|
20
|
-
t.string :name, :
|
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, :
|
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, :
|
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, :
|
40
|
+
t.date :date, null: false, index: true
|
39
41
|
t.string :subject
|
40
|
-
t.references :accountable, :
|
42
|
+
t.references :accountable, polymorphic: true, index: true
|
41
43
|
t.text :note
|
42
|
-
t.boolean :permanent, :
|
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, :
|
49
|
-
t.references :keepr_journal, :
|
50
|
-
t.decimal :amount, :
|
51
|
-
t.references :keepr_cost_center, :
|
52
|
-
t.references :accountable, :
|
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
|
|
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
|
|
@@ -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
|
data/lib/keepr/account.rb
CHANGED
@@ -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 :
|
6
|
+
has_ancestry orphan_strategy: :restrict
|
5
7
|
|
6
|
-
enum :
|
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, :
|
14
|
-
has_many :keepr_taxes, :
|
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, :
|
17
|
-
belongs_to :keepr_group, :
|
18
|
-
belongs_to :accountable, :
|
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
|
-
|
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]
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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]
|
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,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
|
-
|
76
|
+
Keepr::Posting
|
77
|
+
.joins(:keepr_account)
|
78
|
+
.merge(subtree)
|
80
79
|
end
|
81
80
|
|
82
|
-
def balance(date=nil)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
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
|
-
|
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
|