keepr 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c91b1ad75caddcdc40fea241881c31b7f6c4da1d
4
- data.tar.gz: 11643a043c97b47c09d9623992fd70d2cbaa607a
2
+ SHA256:
3
+ metadata.gz: c077965d94021d6d19a624c4c93a3d6ac23f3f90f1c4f74b6518c56da54ac625
4
+ data.tar.gz: 22afd3248d4a5e3476c09c383323a402847c73d997b14216066432083c968236
5
5
  SHA512:
6
- metadata.gz: a207f1ebce4fe8bb4fa594ad73bda3035c9da0d82d05b7258e681b8c53478989c2b8155c3495bb7a9ccbf4345ac2a29b1a51762ab907cd248c1811f42ec74284
7
- data.tar.gz: dd41650bac870b4173f9cfe460ab187e42216bbd206bc36563032c3d75b9f550e3871bf842945c94781b0df73d3ccd697a4fd18b5df0bd8f41ad6378a7ef8d52
6
+ metadata.gz: 278fc8320da492345c89a0e957e65d933b479c1a48fa286454353f5a1814f8d8ee6ae95e894ec1ee9f3083193629f537f361f54be7a66cd14da45937ec528b0f
7
+ data.tar.gz: 6456e4cad08500ba0d8c80891588b2c3e8c65ec26cc014908c9a7e15b9398cdcc63506483d0499ffb05677930445be0bf029193215752f38b8164bbe00c07cdc
@@ -1,26 +1,22 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.7
6
- - 2.3.3
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.0.0
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
- before_install: gem update bundler
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2017 Georg Ledermann
1
+ Copyright (c) 2013-2018 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.x)
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-2017 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
67
+ Copyright (c) 2013-2018 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -8,5 +8,5 @@ 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'
@@ -8,5 +8,5 @@ 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'
@@ -8,5 +8,5 @@ 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'
@@ -8,5 +8,5 @@ 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.2.0'
4
+ gem 'ancestry'
5
+ gem 'sqlite3'
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'simplecov'
9
+ gem 'coveralls'
10
+ gem 'database_cleaner'
11
+ gem 'factory_bot'
12
+ gem 'datev'
@@ -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.0.0'
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 'factory_girl'
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, :null => false
4
+ t.integer :target, null: false
5
5
  t.string :number
6
- t.string :name, :null => false
7
- t.boolean :is_result, :null => false, :default => false
8
- t.string :ancestry, :index => true
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, :null => false
12
+ t.string :name, null: false
13
13
  t.string :description
14
- t.decimal :value, :precision => 8, :scale => 2, :null => false
15
- t.references :keepr_account, :null => false, :index => true
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, :null => false
20
- t.string :name, :null => false
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, :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
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, :null => false, :index => true
38
+ t.date :date, null: false, index: true
39
39
  t.string :subject
40
- t.references :accountable, :polymorphic => true, :index => true
40
+ t.references :accountable, polymorphic: true, index: true
41
41
  t.text :note
42
- t.boolean :permanent, :null => false, :default => false
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, :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
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
 
@@ -1,21 +1,21 @@
1
1
  class Keepr::Account < ActiveRecord::Base
2
2
  self.table_name = 'keepr_accounts'
3
3
 
4
- has_ancestry :orphan_strategy => :restrict
4
+ has_ancestry orphan_strategy: :restrict
5
5
 
6
- enum :kind => [ :asset, :liability, :revenue, :expense, :neutral, :debtor, :creditor ]
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, :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
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, :class_name => 'Keepr::Tax'
17
- belongs_to :keepr_group, :class_name => 'Keepr::Group'
18
- belongs_to :accountable, :polymorphic => true
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
- 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
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 "keepr_journals.permanent = #{connection.quoted_true}"
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
- 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
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
- keepr_postings.sum(:amount)
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
- 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
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, :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
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, :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
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, :class_name => 'Keepr::Journal', :as => :accountable, :dependent => :restrict_with_error
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, :class_name => 'Keepr::Posting', :as => :accountable, :dependent => :restrict_with_error
34
+ has_many :keepr_postings, class_name: 'Keepr::Posting', as: :accountable, dependent: :restrict_with_error
35
35
  end
36
36
  end
37
37
  end
@@ -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, :class_name => 'Keepr::Posting', :foreign_key => 'keepr_cost_center_id', :dependent => :restrict_with_error
7
+ has_many :keepr_postings, class_name: 'Keepr::Posting', foreign_key: 'keepr_cost_center_id', dependent: :restrict_with_error
8
8
  end
@@ -1,28 +1,34 @@
1
1
  class Keepr::Group < ActiveRecord::Base
2
2
  self.table_name = 'keepr_groups'
3
3
 
4
- has_ancestry :orphan_strategy => :restrict
4
+ has_ancestry orphan_strategy: :restrict
5
5
 
6
- enum :target => [ :asset, :liability, :profit_and_loss ]
6
+ enum target: [ :asset, :liability, :profit_and_loss ]
7
7
 
8
8
  validates_presence_of :name
9
9
 
10
- has_many :keepr_accounts, :class_name => 'Keepr::Account', :foreign_key => 'keepr_group_id', :dependent => :restrict_with_error
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(:is_result => true).first
17
+ where(is_result: true).first
18
18
  end
19
19
 
20
20
  def keepr_postings
21
21
  if is_result
22
- Keepr::Posting.joins(:keepr_account).where(:keepr_accounts => { :kind => [ Keepr::Account.kinds[:revenue],
23
- Keepr::Account.kinds[:expense] ] })
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.joins(:keepr_account => :keepr_group).merge(self.subtree)
29
+ Keepr::Posting.
30
+ joins(keepr_account: :keepr_group).
31
+ merge(self.subtree)
26
32
  end
27
33
  end
28
34
 
@@ -9,10 +9,10 @@ class Keepr::GroupsCreator
9
9
  def run
10
10
  case @target
11
11
  when :balance then
12
- load 'asset.txt', :target => :asset
13
- load 'liability.txt', :target => :liability
12
+ load 'asset.txt', target: :asset
13
+ load 'liability.txt', target: :liability
14
14
  when :profit_and_loss
15
- load 'profit_and_loss.txt', :target => :profit_and_loss
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(:name => name, :number => number)
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