keepr 0.3.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) 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 +4 -4
  6. data/Rakefile +3 -1
  7. data/ci/Gemfile-rails-4-2 +5 -5
  8. data/ci/Gemfile-rails-5-0 +5 -5
  9. data/ci/Gemfile-rails-5-1 +12 -0
  10. data/ci/Gemfile-rails-5-2 +12 -0
  11. data/ci/Gemfile-rails-6-0 +12 -0
  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 +27 -14
  23. data/lib/keepr/groups_creator/{asset.txt → de/asset.txt} +0 -0
  24. data/lib/keepr/groups_creator/{liability.txt → de/liability.txt} +0 -0
  25. data/lib/keepr/groups_creator/{profit_and_loss.txt → de/profit_and_loss.txt} +0 -0
  26. data/lib/keepr/groups_creator/en/asset.txt +36 -0
  27. data/lib/keepr/groups_creator/en/liability.txt +28 -0
  28. data/lib/keepr/groups_creator/en/profit_and_loss.txt +31 -0
  29. data/lib/keepr/groups_creator/es/asset.txt +36 -0
  30. data/lib/keepr/groups_creator/es/liability.txt +28 -0
  31. data/lib/keepr/groups_creator/es/profit_and_loss.txt +31 -0
  32. data/lib/keepr/journal.rb +19 -16
  33. data/lib/keepr/journal_export.rb +10 -7
  34. data/lib/keepr/posting.rb +26 -21
  35. data/lib/keepr/tax.rb +4 -2
  36. data/lib/keepr/version.rb +3 -1
  37. data/spec/factories/account.rb +6 -4
  38. data/spec/factories/cost_center.rb +5 -3
  39. data/spec/factories/group.rb +5 -3
  40. data/spec/factories/tax.rb +7 -5
  41. data/spec/keepr/account_export_spec.rb +22 -19
  42. data/spec/keepr/account_spec.rb +92 -87
  43. data/spec/keepr/active_record_extension_spec.rb +38 -36
  44. data/spec/keepr/contact_export_spec.rb +17 -14
  45. data/spec/keepr/cost_center_spec.rb +9 -7
  46. data/spec/keepr/group_spec.rb +53 -49
  47. data/spec/keepr/groups_creator_spec.rb +13 -10
  48. data/spec/keepr/journal_export_spec.rb +54 -53
  49. data/spec/keepr/journal_spec.rb +48 -46
  50. data/spec/keepr/posting_spec.rb +25 -23
  51. data/spec/keepr/tax_spec.rb +21 -14
  52. data/spec/spec_helper.rb +13 -11
  53. data/spec/support/contact.rb +2 -0
  54. data/spec/support/document.rb +2 -0
  55. data/spec/support/ledger.rb +2 -0
  56. data/spec/support/spec_migration.rb +3 -1
  57. metadata +35 -28
  58. data/ci/Gemfile-rails-4-1 +0 -12
@@ -0,0 +1,31 @@
1
+ 01. Ventas
2
+ 02. Aumento o disminución de existencias de productos terminados y sin terminar
3
+ 03. otro trabajo propio capitalizado
4
+ 04. otros ingresos operativos
5
+ 05. Costo de materiales
6
+ a) Gastos por materias primas, consumibles y suministros y por bienes adquiridos
7
+ b) Gastos por servicios adquiridos
8
+ 06. Gastos de personal
9
+ a) Sueldos y salarios
10
+ b) Seguridad social y gastos de pensión y manutención.
11
+ de eso para pensiones
12
+ 07. Depreciación
13
+ a) sobre activos intangibles y propiedades, planta y equipo
14
+ b) de los activos corrientes, en la medida en que estos excedan la depreciación habitual en la corporación
15
+ 08. otros gastos operativos
16
+ 09. Ingresos de inversiones
17
+ a) de los cuales de empresas afiliadas
18
+ 10. Ingresos de otros valores y préstamos de activos financieros
19
+ a) de los cuales de empresas afiliadas
20
+ 11. otros intereses e ingresos similares
21
+ a) de los cuales de empresas afiliadas
22
+ 12. Depreciación de activos financieros y valores mantenidos como activo corriente
23
+ 13. Intereses y gastos similares
24
+ de los cuales a empresas afiliadas
25
+ 14. Resultados de las actividades comerciales ordinarias
26
+ 15. Ingresos extraordinarios
27
+ 16. Gastos extraordinarios
28
+ 17. Resultado extraordinario
29
+ 18. Impuestos sobre la renta y las ganancias
30
+ 19. Otros impuestos
31
+ 20. Superávit anual / déficit anual
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::Journal < ActiveRecord::Base
2
4
  self.table_name = 'keepr_journals'
3
5
 
4
6
  validates_presence_of :date
5
- validates_uniqueness_of :number, :allow_blank => true
7
+ validates_uniqueness_of :number, allow_blank: true
6
8
 
7
- has_many :keepr_postings, -> { order(:amount => :desc) },
8
- :class_name => 'Keepr::Posting', :foreign_key => 'keepr_journal_id', :dependent => :destroy
9
+ has_many :keepr_postings, -> { order(amount: :desc) },
10
+ class_name: 'Keepr::Posting', foreign_key: 'keepr_journal_id', dependent: :destroy
9
11
 
10
- belongs_to :accountable, :polymorphic => true
12
+ belongs_to :accountable, polymorphic: true
11
13
 
12
- accepts_nested_attributes_for :keepr_postings, :allow_destroy => true, :reject_if => :all_blank
14
+ accepts_nested_attributes_for :keepr_postings, allow_destroy: true, reject_if: :all_blank
13
15
 
14
- default_scope { order({:date => :desc}, {:id => :desc}) }
16
+ default_scope { order({ date: :desc }, id: :desc) }
15
17
 
16
18
  validate :validate_postings
17
19
 
@@ -31,7 +33,8 @@ class Keepr::Journal < ActiveRecord::Base
31
33
  before_update :check_permanent
32
34
  before_destroy :check_permanent
33
35
 
34
- private
36
+ private
37
+
35
38
  def existing_postings
36
39
  keepr_postings.to_a.delete_if(&:marked_for_destruction?)
37
40
  end
@@ -51,15 +54,15 @@ private
51
54
  end
52
55
 
53
56
  def check_permanent
54
- if self.permanent_was
55
- # If marked as permanent, no changes are allowed
56
- errors.add :base, :changes_not_allowed
57
-
58
- if ActiveRecord::VERSION::MAJOR < 5
59
- false
60
- else
61
- throw :abort
62
- end
57
+ return unless permanent_was
58
+
59
+ # If marked as permanent, no changes are allowed
60
+ errors.add :base, :changes_not_allowed
61
+
62
+ if ActiveRecord::VERSION::MAJOR < 5
63
+ false
64
+ else
65
+ throw :abort
63
66
  end
64
67
  end
65
68
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::JournalExport
2
- def initialize(journals, header_options={}, &block)
4
+ def initialize(journals, header_options = {}, &block)
3
5
  @journals = journals
4
6
  @header_options = header_options
5
7
  @block = block
@@ -13,12 +15,12 @@ class Keepr::JournalExport
13
15
  export.to_file(filename)
14
16
  end
15
17
 
16
- private
18
+ private
17
19
 
18
20
  def export
19
21
  export = Datev::BookingExport.new(@header_options)
20
22
 
21
- @journals.includes(:keepr_postings => :keepr_account).reorder(:date, :id).each do |journal|
23
+ @journals.includes(keepr_postings: :keepr_account).reorder(:date, :id).each do |journal|
22
24
  to_datev(journal).each do |hash|
23
25
  export << hash
24
26
  end
@@ -29,19 +31,20 @@ private
29
31
 
30
32
  def to_datev(journal)
31
33
  main_posting = journal.keepr_postings.find { |p| p.keepr_account.debtor? || p.keepr_account.creditor? }
32
- main_posting ||= journal.keepr_postings.sort_by(&:amount).last
34
+ main_posting ||= journal.keepr_postings.max_by(&:amount)
33
35
 
34
- journal.keepr_postings.sort_by { |p| [ p.side == main_posting.side ? 1 : 0, -p.amount ] }.map do |posting|
36
+ journal.keepr_postings.sort_by { |p| [p.side == main_posting.side ? 1 : 0, -p.amount] }.map do |posting|
35
37
  next if posting == main_posting
36
38
 
37
- { 'Umsatz (ohne Soll/Haben-Kz)' => posting.amount,
39
+ {
40
+ 'Umsatz (ohne Soll/Haben-Kz)' => posting.amount,
38
41
  'Soll/Haben-Kennzeichen' => 'S',
39
42
  'Konto' => posting.debit? ? posting.keepr_account.number : main_posting.keepr_account.number,
40
43
  'Gegenkonto (ohne BU-Schlüssel)' => posting.credit? ? posting.keepr_account.number : main_posting.keepr_account.number,
41
44
  'BU-Schlüssel' => '40', # Steuerautomatik deaktivieren
42
45
  'Belegdatum' => journal.date,
43
46
  'Belegfeld 1' => journal.number,
44
- 'Buchungstext' => journal.subject.slice(0,60),
47
+ 'Buchungstext' => journal.subject.slice(0, 60),
45
48
  'Festschreibung' => journal.permanent
46
49
  }.merge(@block ? @block.call(posting) : {})
47
50
  end.compact
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::Posting < ActiveRecord::Base
2
4
  self.table_name = 'keepr_postings'
3
5
 
4
6
  validates_presence_of :keepr_account_id, :amount
5
7
  validate :cost_center_validation
6
8
 
7
- belongs_to :keepr_account, :class_name => 'Keepr::Account'
8
- belongs_to :keepr_journal, :class_name => 'Keepr::Journal'
9
- belongs_to :keepr_cost_center, :class_name => 'Keepr::CostCenter'
10
- belongs_to :accountable, :polymorphic => true
9
+ belongs_to :keepr_account, class_name: 'Keepr::Account'
10
+ belongs_to :keepr_journal, class_name: 'Keepr::Journal'
11
+ belongs_to :keepr_cost_center, class_name: 'Keepr::CostCenter'
12
+ belongs_to :accountable, polymorphic: true
11
13
 
12
14
  SIDE_DEBIT = 'debit'
13
15
  SIDE_CREDIT = 'credit'
@@ -17,19 +19,20 @@ class Keepr::Posting < ActiveRecord::Base
17
19
 
18
20
  def side
19
21
  @side || begin
20
- (raw_amount < 0 ? SIDE_CREDIT : SIDE_DEBIT) if raw_amount
22
+ (raw_amount.negative? ? SIDE_CREDIT : SIDE_DEBIT) if raw_amount
21
23
  end
22
24
  end
23
25
 
24
26
  def side=(value)
27
+ raise ArgumentError unless [SIDE_DEBIT, SIDE_CREDIT].include?(value)
28
+
25
29
  @side = value
30
+ return unless amount
26
31
 
27
32
  if credit?
28
- self.raw_amount = -amount if amount
33
+ self.raw_amount = -amount.to_d
29
34
  elsif debit?
30
- self.raw_amount = amount if amount
31
- else
32
- raise ArgumentError
35
+ self.raw_amount = amount.to_d
33
36
  end
34
37
  end
35
38
 
@@ -54,23 +57,25 @@ class Keepr::Posting < ActiveRecord::Base
54
57
  end
55
58
 
56
59
  def amount=(value)
57
- raise ArgumentError.new('Negative amount not allowed!') if value.to_f < 0
58
60
  @side ||= SIDE_DEBIT
59
61
 
60
- if credit?
61
- self.raw_amount = -value
62
- else
63
- self.raw_amount = value
62
+ unless value
63
+ self.raw_amount = nil
64
+ return
64
65
  end
66
+
67
+ raise ArgumentError, 'Negative amount not allowed!' if value.to_d.negative?
68
+
69
+ self.raw_amount = credit? ? -value.to_d : value.to_d
65
70
  end
66
71
 
67
- private
72
+ private
73
+
68
74
  def cost_center_validation
69
- if keepr_cost_center
70
- unless keepr_account.profit_and_loss?
71
- # allowed for expense or revenue accounts only
72
- errors.add :keepr_cost_center_id, :allowed_for_expense_or_revenue_only
73
- end
74
- end
75
+ return unless keepr_cost_center
76
+ return if keepr_account.profit_and_loss?
77
+
78
+ # allowed for expense or revenue accounts only
79
+ errors.add :keepr_cost_center_id, :allowed_for_expense_or_revenue_only
75
80
  end
76
81
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::Tax < ActiveRecord::Base
2
4
  self.table_name = 'keepr_taxes'
3
5
 
4
6
  validates_presence_of :name, :value, :keepr_account_id
5
7
  validates_numericality_of :value
6
8
 
7
- belongs_to :keepr_account, :class_name => 'Keepr::Account'
8
- has_many :keepr_accounts, :class_name => 'Keepr::Account', :foreign_key => 'keepr_tax_id', :dependent => :restrict_with_error
9
+ belongs_to :keepr_account, class_name: 'Keepr::Account'
10
+ has_many :keepr_accounts, class_name: 'Keepr::Account', foreign_key: 'keepr_tax_id', dependent: :restrict_with_error
9
11
 
10
12
  validate do |tax|
11
13
  tax.errors.add(:keepr_account_id, :circular_reference) if tax.keepr_account.try(:keepr_tax) == tax
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Keepr
2
- VERSION = '0.3.1'
4
+ VERSION = '0.7.0'
3
5
  end
@@ -1,7 +1,9 @@
1
- FactoryGirl.define do
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
2
4
  factory :account, class: Keepr::Account do
3
- number 12345
4
- kind :asset
5
- name 'Foo'
5
+ number { 12_345 }
6
+ kind { :asset }
7
+ name { 'Foo' }
6
8
  end
7
9
  end
@@ -1,6 +1,8 @@
1
- FactoryGirl.define do
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
2
4
  factory :cost_center, class: Keepr::CostCenter do
3
- number 'FZ1'
4
- name 'Kleintransporter'
5
+ number { 'FZ1' }
6
+ name { 'Kleintransporter' }
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
- FactoryGirl.define do
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
2
4
  factory :group, class: Keepr::Group do
3
- target :asset
4
- name 'Foo'
5
+ target { :asset }
6
+ name { 'Foo' }
5
7
  end
6
8
  end
@@ -1,8 +1,10 @@
1
- FactoryGirl.define do
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
2
4
  factory :tax, class: Keepr::Tax do
3
- name 'USt19'
4
- description 'Umsatzsteuer 19%'
5
- value 19.0
6
- keepr_account { FactoryGirl.create :account, :number => 1776 }
5
+ name { 'USt19' }
6
+ description { 'Umsatzsteuer 19%' }
7
+ value { 19.0 }
8
+ keepr_account { FactoryBot.create :account, number: 1776 }
7
9
  end
8
10
  end
@@ -1,26 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::AccountExport do
4
- let!(:account_1000) { FactoryGirl.create :account, :kind => :asset, :number => 1000, :name => 'Kasse' }
5
- let!(:account_1776) { FactoryGirl.create :account, :kind => :liability, :number => 1776, :name => 'Umsatzsteuer 19 %' }
6
- let!(:account_4920) { FactoryGirl.create :account, :kind => :expense, :number => 4920, :name => 'Telefon' }
7
- let!(:account_8400) { FactoryGirl.create :account, :kind => :revenue, :number => 8400, :name => 'Erlöse 19 %' }
8
- let!(:account_9000) { FactoryGirl.create :account, :kind => :neutral, :number => 9000, :name => 'Saldenvorträge Sachkonten' }
9
- let!(:account_10000) { FactoryGirl.create :account, :kind => :creditor, :number => 10000, :name => 'Diverse Kreditoren' }
10
- let!(:account_70000) { FactoryGirl.create :account, :kind => :debtor, :number => 70000, :name => 'Diverse Debitoren' }
6
+ let!(:account_1000) { FactoryBot.create :account, kind: :asset, number: 1000, name: 'Kasse' }
7
+ let!(:account_1776) { FactoryBot.create :account, kind: :liability, number: 1776, name: 'Umsatzsteuer 19 %' }
8
+ let!(:account_4920) { FactoryBot.create :account, kind: :expense, number: 4920, name: 'Telefon' }
9
+ let!(:account_8400) { FactoryBot.create :account, kind: :revenue, number: 8400, name: 'Erlöse 19 %' }
10
+ let!(:account_9000) { FactoryBot.create :account, kind: :forward, number: 9000, name: 'Saldenvorträge Sachkonten' }
11
+ let!(:account_10000) { FactoryBot.create :account, kind: :creditor, number: 10_000, name: 'Diverse Kreditoren' }
12
+ let!(:account_70000) { FactoryBot.create :account, kind: :debtor, number: 70_000, name: 'Diverse Debitoren' }
11
13
 
12
14
  let(:scope) { Keepr::Account.all }
13
15
 
14
- let(:export) {
15
- Keepr::AccountExport.new(scope,
16
- 'Berater' => 1234567,
17
- 'Mandant' => 78901,
18
- 'WJ-Beginn' => Date.new(2016,1,1),
16
+ let(:export) do
17
+ Keepr::AccountExport.new(
18
+ scope,
19
+ 'Berater' => 1_234_567,
20
+ 'Mandant' => 78_901,
21
+ 'WJ-Beginn' => Date.new(2016, 1, 1),
19
22
  'Bezeichnung' => 'Keepr-Konten'
20
- ) do |account|
23
+ ) do
21
24
  { 'Sprach-ID' => 'de-DE' }
22
25
  end
23
- }
26
+ end
24
27
 
25
28
  describe :to_s do
26
29
  subject { export.to_s }
@@ -29,17 +32,17 @@ describe Keepr::AccountExport do
29
32
  subject.lines[2..-1].map { |line| line.encode(Encoding::UTF_8) }
30
33
  end
31
34
 
32
- it "should return CSV lines" do
35
+ it 'should return CSV lines' do
33
36
  subject.lines.each { |line| expect(line).to include(';') }
34
37
  end
35
38
 
36
- it "should include header data" do
39
+ it 'should include header data' do
37
40
  expect(subject.lines[0]).to include('1234567;')
38
41
  expect(subject.lines[0]).to include('78901;')
39
42
  expect(subject.lines[0]).to include('"Keepr-Konten";')
40
43
  end
41
44
 
42
- it "should include all accounts except debtor/creditor" do
45
+ it 'should include all accounts except debtor/creditor' do
43
46
  expect(account_lines.count).to eq(5)
44
47
 
45
48
  expect(account_lines[0]).to include('1000;')
@@ -58,14 +61,14 @@ describe Keepr::AccountExport do
58
61
  expect(account_lines[4]).to include('"Saldenvorträge Sachkonten";')
59
62
  end
60
63
 
61
- it "should include data from block" do
64
+ it 'should include data from block' do
62
65
  expect(account_lines[0]).to include(';"de-DE"')
63
66
  expect(account_lines[1]).to include(';"de-DE"')
64
67
  end
65
68
  end
66
69
 
67
70
  describe :to_file do
68
- it "should create CSV file" do
71
+ it 'should create CSV file' do
69
72
  Dir.mktmpdir do |dir|
70
73
  filename = "#{dir}/EXTF_Kontenbeschriftungen.csv"
71
74
  export.to_file(filename)
@@ -1,89 +1,90 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe Keepr::Account do
5
6
  describe :number_as_string do
6
- it "should return number with leading zeros for low values" do
7
- account = Keepr::Account.new(:number => 999)
7
+ it 'should return number with leading zeros for low values' do
8
+ account = Keepr::Account.new(number: 999)
8
9
  expect(account.number_as_string).to eq('0999')
9
10
  end
10
11
 
11
- it "should return number unchanged for high values" do
12
- account = Keepr::Account.new(:number => 70000)
12
+ it 'should return number unchanged for high values' do
13
+ account = Keepr::Account.new(number: 70_000)
13
14
  expect(account.number_as_string).to eq('70000')
14
15
  end
15
16
  end
16
17
 
17
18
  describe :to_s do
18
- it "should format" do
19
- account = Keepr::Account.new(:number => 27, :name => 'Software')
19
+ it 'should format' do
20
+ account = Keepr::Account.new(number: 27, name: 'Software')
20
21
  expect(account.to_s).to eq('0027 (Software)')
21
22
  end
22
23
  end
23
24
  end
24
25
 
25
26
  describe Keepr::Account do
26
- let!(:account_1000) { FactoryGirl.create(:account, :number => 1000) }
27
- let!(:account_1200) { FactoryGirl.create(:account, :number => 1200) }
27
+ let!(:account_1000) { FactoryBot.create(:account, number: 1000) }
28
+ let!(:account_1200) { FactoryBot.create(:account, number: 1200) }
28
29
 
29
30
  before :each do
30
- Keepr::Journal.create! :date => Date.yesterday,
31
- :permanent => true,
32
- :keepr_postings_attributes => [
33
- { :keepr_account => account_1000, :amount => 20, :side => 'debit' },
34
- { :keepr_account => account_1200, :amount => 20, :side => 'credit' }
35
- ]
36
-
37
- Keepr::Journal.create! :date => Date.yesterday,
38
- :keepr_postings_attributes => [
39
- { :keepr_account => account_1000, :amount => 10, :side => 'credit' },
40
- { :keepr_account => account_1200, :amount => 10, :side => 'debit' },
41
- ]
42
-
43
- Keepr::Journal.create! :date => Date.today,
44
- :keepr_postings_attributes => [
45
- { :keepr_account => account_1000, :amount => 200, :side => 'debit' },
46
- { :keepr_account => account_1200, :amount => 200, :side => 'credit' }
47
- ]
48
-
49
- Keepr::Journal.create! :date => Date.today,
50
- :keepr_postings_attributes => [
51
- { :keepr_account => account_1000, :amount => 100, :side => 'credit' },
52
- { :keepr_account => account_1200, :amount => 100, :side => 'debit' },
53
- ]
31
+ Keepr::Journal.create! date: Date.yesterday,
32
+ permanent: true,
33
+ keepr_postings_attributes: [
34
+ { keepr_account: account_1000, amount: 20, side: 'debit' },
35
+ { keepr_account: account_1200, amount: 20, side: 'credit' }
36
+ ]
37
+
38
+ Keepr::Journal.create! date: Date.yesterday,
39
+ keepr_postings_attributes: [
40
+ { keepr_account: account_1000, amount: 10, side: 'credit' },
41
+ { keepr_account: account_1200, amount: 10, side: 'debit' }
42
+ ]
43
+
44
+ Keepr::Journal.create! date: Date.current,
45
+ keepr_postings_attributes: [
46
+ { keepr_account: account_1000, amount: 200, side: 'debit' },
47
+ { keepr_account: account_1200, amount: 200, side: 'credit' }
48
+ ]
49
+
50
+ Keepr::Journal.create! date: Date.current,
51
+ keepr_postings_attributes: [
52
+ { keepr_account: account_1000, amount: 100, side: 'credit' },
53
+ { keepr_account: account_1200, amount: 100, side: 'debit' }
54
+ ]
54
55
  end
55
56
 
56
57
  describe 'validations' do
57
- let!(:result_group) { FactoryGirl.create(:group, :target => :liability, :is_result => true) }
58
- let!(:liability_group) { FactoryGirl.create(:group, :target => :liability) }
59
- let!(:asset_group) { FactoryGirl.create(:group, :target => :asset) }
58
+ let!(:result_group) { FactoryBot.create(:group, target: :liability, is_result: true) }
59
+ let!(:liability_group) { FactoryBot.create(:group, target: :liability) }
60
+ let!(:asset_group) { FactoryBot.create(:group, target: :asset) }
60
61
 
61
- it "should not allow assigning to result group" do
62
- account = FactoryGirl.build(:account, :keepr_group => result_group)
62
+ it 'should not allow assigning to result group' do
63
+ account = FactoryBot.build(:account, keepr_group: result_group)
63
64
  expect(account).to_not be_valid
64
- expect(account.errors.added? :keepr_group_id, :no_group_allowed_for_result).to eq(true)
65
+ expect(account.errors.added?(:keepr_group_id, :no_group_allowed_for_result)).to eq(true)
65
66
  end
66
67
 
67
- it "should not allow assigning asset account to liability group" do
68
- account = FactoryGirl.build(:account, :kind => :asset, :keepr_group => liability_group)
68
+ it 'should not allow assigning asset account to liability group' do
69
+ account = FactoryBot.build(:account, kind: :asset, keepr_group: liability_group)
69
70
  expect(account).to_not be_valid
70
- expect(account.errors.added? :kind, :group_mismatch).to eq(true)
71
+ expect(account.errors.added?(:kind, :group_mismatch)).to eq(true)
71
72
  end
72
73
 
73
- it "should not allow assigning liability account to asset group" do
74
- account = FactoryGirl.build(:account, :kind => :liability, :keepr_group => asset_group)
74
+ it 'should not allow assigning liability account to asset group' do
75
+ account = FactoryBot.build(:account, kind: :liability, keepr_group: asset_group)
75
76
  expect(account).to_not be_valid
76
- expect(account.errors.added? :kind, :group_mismatch).to eq(true)
77
+ expect(account.errors.added?(:kind, :group_mismatch)).to eq(true)
77
78
  end
78
79
 
79
- it "should not allow assigning neutral account to asset group" do
80
- account = FactoryGirl.build(:account, :kind => :neutral, :keepr_group => asset_group)
80
+ it 'should not allow assigning forward account to asset group' do
81
+ account = FactoryBot.build(:account, kind: :forward, keepr_group: asset_group)
81
82
  expect(account).to_not be_valid
82
- expect(account.errors.added? :kind, :group_conflict).to eq(true)
83
+ expect(account.errors.added?(:kind, :group_conflict)).to eq(true)
83
84
  end
84
85
 
85
- it "should allow target match" do
86
- account = FactoryGirl.build(:account, :kind => :asset, :keepr_group => asset_group)
86
+ it 'should allow target match' do
87
+ account = FactoryBot.build(:account, kind: :asset, keepr_group: asset_group)
87
88
  expect(account).to be_valid
88
89
  end
89
90
  end
@@ -131,7 +132,7 @@ describe Keepr::Account do
131
132
 
132
133
  context 'with date option' do
133
134
  it 'should work with Date' do
134
- account1, account2 = Keepr::Account.with_sums(:date => Date.yesterday)
135
+ account1, account2 = Keepr::Account.with_sums(date: Date.yesterday)
135
136
 
136
137
  expect(account1.number).to eq(1000)
137
138
  expect(account1.sum_amount).to eq(10)
@@ -140,7 +141,7 @@ describe Keepr::Account do
140
141
  end
141
142
 
142
143
  it 'should work with Range' do
143
- account1, account2 = Keepr::Account.with_sums(:date => Date.today..Date.tomorrow)
144
+ account1, account2 = Keepr::Account.with_sums(date: Date.today..Date.tomorrow)
144
145
 
145
146
  expect(account1.number).to eq(1000)
146
147
  expect(account1.sum_amount).to eq(100)
@@ -149,14 +150,14 @@ describe Keepr::Account do
149
150
  end
150
151
 
151
152
  it 'should raise for other class' do
152
- expect { Keepr::Account.with_sums(:date => Time.current) }.to raise_error(ArgumentError)
153
- expect { Keepr::Account.with_sums(:date => :foo) }.to raise_error(ArgumentError)
153
+ expect { Keepr::Account.with_sums(date: Time.current) }.to raise_error(ArgumentError)
154
+ expect { Keepr::Account.with_sums(date: :foo) }.to raise_error(ArgumentError)
154
155
  end
155
156
  end
156
157
 
157
158
  context 'with permanent_only option' do
158
159
  it 'should filter the permanent journals' do
159
- account1, account2 = Keepr::Account.with_sums(:permanent_only => true)
160
+ account1, account2 = Keepr::Account.with_sums(permanent_only: true)
160
161
 
161
162
  expect(account1.number).to eq(1000)
162
163
  expect(account1.sum_amount).to eq(20)
@@ -175,17 +176,17 @@ describe Keepr::Account do
175
176
  end
176
177
 
177
178
  describe Keepr::Account, 'with subaccounts' do
178
- let!(:account_1400) { FactoryGirl.create(:account, :number => 1400) }
179
- let!(:account_10000) { FactoryGirl.create(:account, :number => 10000, :parent => account_1400) }
180
- let!(:account_10001) { FactoryGirl.create(:account, :number => 10001, :parent => account_1400) }
181
- let!(:account_8400) { FactoryGirl.create(:account, :number => 8400) }
179
+ let!(:account_1400) { FactoryBot.create(:account, number: 1400) }
180
+ let!(:account_10000) { FactoryBot.create(:account, number: 10_000, parent: account_1400) }
181
+ let!(:account_10001) { FactoryBot.create(:account, number: 10_001, parent: account_1400) }
182
+ let!(:account_8400) { FactoryBot.create(:account, number: 8400) }
182
183
 
183
184
  before :each do
184
- Keepr::Journal.create! :date => Date.yesterday,
185
- :keepr_postings_attributes => [
186
- { :keepr_account => account_10000, :amount => 20, :side => 'debit' },
187
- { :keepr_account => account_8400, :amount => 20, :side => 'credit' }
188
- ]
185
+ Keepr::Journal.create! date: Date.yesterday,
186
+ keepr_postings_attributes: [
187
+ { keepr_account: account_10000, amount: 20, side: 'debit' },
188
+ { keepr_account: account_8400, amount: 20, side: 'credit' }
189
+ ]
189
190
  end
190
191
 
191
192
  describe :keepr_postings do
@@ -209,42 +210,46 @@ describe Keepr::Account, 'with subaccounts' do
209
210
 
210
211
  describe :with_sums do
211
212
  it 'should calc balance' do
212
- expect(Keepr::Account.with_sums.
213
- select(&:sum_amount).
214
- map { |a| [a.number, a.sum_amount] }).
215
- to eq([[8400, -20], [10000, 20]])
213
+ expect(Keepr::Account.with_sums
214
+ .select(&:sum_amount)
215
+ .map { |a| [a.number, a.sum_amount] })
216
+ .to eq([[8400, -20], [10_000, 20]])
216
217
  end
217
218
  end
218
219
 
219
220
  describe :merged_with_sums do
220
221
  it 'should calc merged balance' do
221
- expect(Keepr::Account.merged_with_sums.
222
- select(&:sum_amount).
223
- map { |a| [a.number, a.sum_amount] }).
224
- to eq([[1400, 20], [8400, -20]])
222
+ expect(Keepr::Account.merged_with_sums
223
+ .select(&:sum_amount)
224
+ .map { |a| [a.number, a.sum_amount] })
225
+ .to eq([[1400, 20], [8400, -20]])
225
226
  end
226
227
  end
227
228
  end
228
229
 
229
230
  describe Keepr::Account, 'with tax' do
230
- let!(:tax_account) { Keepr::Account.create! :number => 1776,
231
- :name => 'Umsatzsteuer 19%',
232
- :kind => :asset }
233
-
234
- let!(:tax) { Keepr::Tax.create! :name => 'USt19',
235
- :description => 'Umsatzsteuer 19%',
236
- :value => 19.0,
237
- :keepr_account => tax_account }
238
-
239
- it "should link to tax" do
240
- account = Keepr::Account.new :number => 8400,
241
- :name => 'Erlöse 19% USt',
242
- :kind => :revenue,
243
- :keepr_tax => tax
231
+ let!(:tax_account) do
232
+ Keepr::Account.create! number: 1776,
233
+ name: 'Umsatzsteuer 19%',
234
+ kind: :asset
235
+ end
236
+
237
+ let!(:tax) do
238
+ Keepr::Tax.create! name: 'USt19',
239
+ description: 'Umsatzsteuer 19%',
240
+ value: 19.0,
241
+ keepr_account: tax_account
242
+ end
243
+
244
+ it 'should link to tax' do
245
+ account = Keepr::Account.new number: 8400,
246
+ name: 'Erlöse 19% USt',
247
+ kind: :revenue,
248
+ keepr_tax: tax
244
249
  expect(account).to be_valid
245
250
  end
246
251
 
247
- it "should avoid circular reference" do
252
+ it 'should avoid circular reference' do
248
253
  tax_account.keepr_tax_id = tax.id
249
254
  expect(tax_account).to be_invalid
250
255
  end