keepr 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,16 +2,16 @@ class Keepr::Journal < ActiveRecord::Base
2
2
  self.table_name = 'keepr_journals'
3
3
 
4
4
  validates_presence_of :date
5
- validates_uniqueness_of :number, :allow_blank => true
5
+ validates_uniqueness_of :number, allow_blank: true
6
6
 
7
- has_many :keepr_postings, -> { order(:amount => :desc) },
8
- :class_name => 'Keepr::Posting', :foreign_key => 'keepr_journal_id', :dependent => :destroy
7
+ has_many :keepr_postings, -> { order(amount: :desc) },
8
+ class_name: 'Keepr::Posting', foreign_key: 'keepr_journal_id', dependent: :destroy
9
9
 
10
- belongs_to :accountable, :polymorphic => true
10
+ belongs_to :accountable, polymorphic: true
11
11
 
12
- accepts_nested_attributes_for :keepr_postings, :allow_destroy => true, :reject_if => :all_blank
12
+ accepts_nested_attributes_for :keepr_postings, allow_destroy: true, reject_if: :all_blank
13
13
 
14
- default_scope { order({:date => :desc}, {:id => :desc}) }
14
+ default_scope { order({date: :desc}, {id: :desc}) }
15
15
 
16
16
  validate :validate_postings
17
17
 
@@ -18,7 +18,7 @@ private
18
18
  def export
19
19
  export = Datev::BookingExport.new(@header_options)
20
20
 
21
- @journals.includes(:keepr_postings => :keepr_account).reorder(:date, :id).each do |journal|
21
+ @journals.includes(keepr_postings: :keepr_account).reorder(:date, :id).each do |journal|
22
22
  to_datev(journal).each do |hash|
23
23
  export << hash
24
24
  end
@@ -4,10 +4,10 @@ class Keepr::Posting < ActiveRecord::Base
4
4
  validates_presence_of :keepr_account_id, :amount
5
5
  validate :cost_center_validation
6
6
 
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
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
11
11
 
12
12
  SIDE_DEBIT = 'debit'
13
13
  SIDE_CREDIT = 'credit'
@@ -22,14 +22,14 @@ class Keepr::Posting < ActiveRecord::Base
22
22
  end
23
23
 
24
24
  def side=(value)
25
+ raise ArgumentError unless [ SIDE_DEBIT, SIDE_CREDIT ].include?(value)
25
26
  @side = value
27
+ return unless amount
26
28
 
27
29
  if credit?
28
- self.raw_amount = -amount if amount
30
+ self.raw_amount = -amount
29
31
  elsif debit?
30
- self.raw_amount = amount if amount
31
- else
32
- raise ArgumentError
32
+ self.raw_amount = amount
33
33
  end
34
34
  end
35
35
 
@@ -4,8 +4,8 @@ class Keepr::Tax < ActiveRecord::Base
4
4
  validates_presence_of :name, :value, :keepr_account_id
5
5
  validates_numericality_of :value
6
6
 
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
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
9
 
10
10
  validate do |tax|
11
11
  tax.errors.add(:keepr_account_id, :circular_reference) if tax.keepr_account.try(:keepr_tax) == tax
@@ -1,3 +1,3 @@
1
1
  module Keepr
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :account, class: Keepr::Account do
3
3
  number 12345
4
4
  kind :asset
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :cost_center, class: Keepr::CostCenter do
3
3
  number 'FZ1'
4
4
  name 'Kleintransporter'
@@ -1,4 +1,4 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :group, class: Keepr::Group do
3
3
  target :asset
4
4
  name 'Foo'
@@ -1,8 +1,8 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
  factory :tax, class: Keepr::Tax do
3
3
  name 'USt19'
4
4
  description 'Umsatzsteuer 19%'
5
5
  value 19.0
6
- keepr_account { FactoryGirl.create :account, :number => 1776 }
6
+ keepr_account { FactoryBot.create :account, number: 1776 }
7
7
  end
8
8
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  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' }
4
+ let!(:account_1000) { FactoryBot.create :account, kind: :asset, number: 1000, name: 'Kasse' }
5
+ let!(:account_1776) { FactoryBot.create :account, kind: :liability, number: 1776, name: 'Umsatzsteuer 19 %' }
6
+ let!(:account_4920) { FactoryBot.create :account, kind: :expense, number: 4920, name: 'Telefon' }
7
+ let!(:account_8400) { FactoryBot.create :account, kind: :revenue, number: 8400, name: 'Erlöse 19 %' }
8
+ let!(:account_9000) { FactoryBot.create :account, kind: :forward, number: 9000, name: 'Saldenvorträge Sachkonten' }
9
+ let!(:account_10000) { FactoryBot.create :account, kind: :creditor, number: 10000, name: 'Diverse Kreditoren' }
10
+ let!(:account_70000) { FactoryBot.create :account, kind: :debtor, number: 70000, name: 'Diverse Debitoren' }
11
11
 
12
12
  let(:scope) { Keepr::Account.all }
13
13
 
@@ -4,86 +4,86 @@ require 'spec_helper'
4
4
  describe Keepr::Account do
5
5
  describe :number_as_string do
6
6
  it "should return number with leading zeros for low values" do
7
- account = Keepr::Account.new(:number => 999)
7
+ account = Keepr::Account.new(number: 999)
8
8
  expect(account.number_as_string).to eq('0999')
9
9
  end
10
10
 
11
11
  it "should return number unchanged for high values" do
12
- account = Keepr::Account.new(:number => 70000)
12
+ account = Keepr::Account.new(number: 70000)
13
13
  expect(account.number_as_string).to eq('70000')
14
14
  end
15
15
  end
16
16
 
17
17
  describe :to_s do
18
18
  it "should format" do
19
- account = Keepr::Account.new(:number => 27, :name => 'Software')
19
+ account = Keepr::Account.new(number: 27, name: 'Software')
20
20
  expect(account.to_s).to eq('0027 (Software)')
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
25
  describe Keepr::Account do
26
- let!(:account_1000) { FactoryGirl.create(:account, :number => 1000) }
27
- let!(:account_1200) { FactoryGirl.create(:account, :number => 1200) }
26
+ let!(:account_1000) { FactoryBot.create(:account, number: 1000) }
27
+ let!(:account_1200) { FactoryBot.create(:account, number: 1200) }
28
28
 
29
29
  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' }
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
35
  ]
36
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' },
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
41
  ]
42
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' }
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
47
  ]
48
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' },
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
53
  ]
54
54
  end
55
55
 
56
56
  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) }
57
+ let!(:result_group) { FactoryBot.create(:group, target: :liability, is_result: true) }
58
+ let!(:liability_group) { FactoryBot.create(:group, target: :liability) }
59
+ let!(:asset_group) { FactoryBot.create(:group, target: :asset) }
60
60
 
61
61
  it "should not allow assigning to result group" do
62
- account = FactoryGirl.build(:account, :keepr_group => result_group)
62
+ account = FactoryBot.build(:account, keepr_group: result_group)
63
63
  expect(account).to_not be_valid
64
64
  expect(account.errors.added? :keepr_group_id, :no_group_allowed_for_result).to eq(true)
65
65
  end
66
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
+ account = FactoryBot.build(:account, kind: :asset, keepr_group: liability_group)
69
69
  expect(account).to_not be_valid
70
70
  expect(account.errors.added? :kind, :group_mismatch).to eq(true)
71
71
  end
72
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
+ account = FactoryBot.build(:account, kind: :liability, keepr_group: asset_group)
75
75
  expect(account).to_not be_valid
76
76
  expect(account.errors.added? :kind, :group_mismatch).to eq(true)
77
77
  end
78
78
 
79
- it "should not allow assigning neutral account to asset group" do
80
- account = FactoryGirl.build(:account, :kind => :neutral, :keepr_group => asset_group)
79
+ it "should not allow assigning forward account to asset group" do
80
+ account = FactoryBot.build(:account, kind: :forward, keepr_group: asset_group)
81
81
  expect(account).to_not be_valid
82
82
  expect(account.errors.added? :kind, :group_conflict).to eq(true)
83
83
  end
84
84
 
85
85
  it "should allow target match" do
86
- account = FactoryGirl.build(:account, :kind => :asset, :keepr_group => asset_group)
86
+ account = FactoryBot.build(:account, kind: :asset, keepr_group: asset_group)
87
87
  expect(account).to be_valid
88
88
  end
89
89
  end
@@ -131,7 +131,7 @@ describe Keepr::Account do
131
131
 
132
132
  context 'with date option' do
133
133
  it 'should work with Date' do
134
- account1, account2 = Keepr::Account.with_sums(:date => Date.yesterday)
134
+ account1, account2 = Keepr::Account.with_sums(date: Date.yesterday)
135
135
 
136
136
  expect(account1.number).to eq(1000)
137
137
  expect(account1.sum_amount).to eq(10)
@@ -140,7 +140,7 @@ describe Keepr::Account do
140
140
  end
141
141
 
142
142
  it 'should work with Range' do
143
- account1, account2 = Keepr::Account.with_sums(:date => Date.today..Date.tomorrow)
143
+ account1, account2 = Keepr::Account.with_sums(date: Date.today..Date.tomorrow)
144
144
 
145
145
  expect(account1.number).to eq(1000)
146
146
  expect(account1.sum_amount).to eq(100)
@@ -149,14 +149,14 @@ describe Keepr::Account do
149
149
  end
150
150
 
151
151
  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)
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)
154
154
  end
155
155
  end
156
156
 
157
157
  context 'with permanent_only option' do
158
158
  it 'should filter the permanent journals' do
159
- account1, account2 = Keepr::Account.with_sums(:permanent_only => true)
159
+ account1, account2 = Keepr::Account.with_sums(permanent_only: true)
160
160
 
161
161
  expect(account1.number).to eq(1000)
162
162
  expect(account1.sum_amount).to eq(20)
@@ -175,16 +175,16 @@ describe Keepr::Account do
175
175
  end
176
176
 
177
177
  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) }
178
+ let!(:account_1400) { FactoryBot.create(:account, number: 1400) }
179
+ let!(:account_10000) { FactoryBot.create(:account, number: 10000, parent: account_1400) }
180
+ let!(:account_10001) { FactoryBot.create(:account, number: 10001, parent: account_1400) }
181
+ let!(:account_8400) { FactoryBot.create(:account, number: 8400) }
182
182
 
183
183
  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' }
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
188
  ]
189
189
  end
190
190
 
@@ -227,20 +227,20 @@ describe Keepr::Account, 'with subaccounts' do
227
227
  end
228
228
 
229
229
  describe Keepr::Account, 'with tax' do
230
- let!(:tax_account) { Keepr::Account.create! :number => 1776,
231
- :name => 'Umsatzsteuer 19%',
232
- :kind => :asset }
230
+ let!(:tax_account) { Keepr::Account.create! number: 1776,
231
+ name: 'Umsatzsteuer 19%',
232
+ kind: :asset }
233
233
 
234
- let!(:tax) { Keepr::Tax.create! :name => 'USt19',
235
- :description => 'Umsatzsteuer 19%',
236
- :value => 19.0,
237
- :keepr_account => tax_account }
234
+ let!(:tax) { Keepr::Tax.create! name: 'USt19',
235
+ description: 'Umsatzsteuer 19%',
236
+ value: 19.0,
237
+ keepr_account: tax_account }
238
238
 
239
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
240
+ account = Keepr::Account.new number: 8400,
241
+ name: 'Erlöse 19% USt',
242
+ kind: :revenue,
243
+ keepr_tax: tax
244
244
  expect(account).to be_valid
245
245
  end
246
246
 
@@ -1,25 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Keepr::ActiveRecordExtension do
4
- let(:account_1000) { FactoryGirl.create(:account, :number => 1000, :kind => :asset) }
5
- let(:account_1200) { FactoryGirl.create(:account, :number => 1200, :kind => :asset) }
4
+ let(:account_1000) { FactoryBot.create(:account, number: 1000, kind: :asset) }
5
+ let(:account_1200) { FactoryBot.create(:account, number: 1200, kind: :asset) }
6
6
 
7
7
  describe 'ledger with associated account' do
8
- let(:ledger) { Ledger.create! :bank_name => 'Sparkasse' }
9
- let!(:account) { ledger.create_keepr_account! :number => '1250', :kind => :asset, :name => 'Girokonto' }
8
+ let(:ledger) { Ledger.create! bank_name: 'Sparkasse' }
9
+ let!(:account) { ledger.create_keepr_account! number: '1250', kind: :asset, name: 'Girokonto' }
10
10
 
11
11
  it 'has keepr_account' do
12
12
  expect(ledger.keepr_account).to eq(account)
13
13
  end
14
14
 
15
15
  it 'has keepr_postings' do
16
- journal = Keepr::Journal.create! :keepr_postings_attributes => [
17
- { :keepr_account => account, :amount => 30, :side => 'debit' },
18
- { :keepr_account => account_1200, :amount => 30, :side => 'credit' }
16
+ journal = Keepr::Journal.create! keepr_postings_attributes: [
17
+ { keepr_account: account, amount: 30, side: 'debit' },
18
+ { keepr_account: account_1200, amount: 30, side: 'credit' }
19
19
  ]
20
- other_journal = Keepr::Journal.create! :keepr_postings_attributes => [
21
- { :keepr_account => account_1000, :amount => 20, :side => 'debit' },
22
- { :keepr_account => account_1200, :amount => 20, :side => 'credit' }
20
+ other_journal = Keepr::Journal.create! keepr_postings_attributes: [
21
+ { keepr_account: account_1000, amount: 20, side: 'debit' },
22
+ { keepr_account: account_1200, amount: 20, side: 'credit' }
23
23
  ]
24
24
 
25
25
  expect(ledger.keepr_postings.count).to eq(1)
@@ -28,22 +28,22 @@ describe Keepr::ActiveRecordExtension do
28
28
  end
29
29
 
30
30
  describe 'contact with multiple associated accounts' do
31
- let(:contact) { Contact.create! :name => 'John Doe' }
32
- let(:account1) { contact.keepr_accounts.create! :number => '70001', :kind => :debtor, :name => "Doe's main account" }
33
- let(:account2) { contact.keepr_accounts.create! :number => '70002', :kind => :debtor, :name => "Doe's second account" }
31
+ let(:contact) { Contact.create! name: 'John Doe' }
32
+ let(:account1) { contact.keepr_accounts.create! number: '70001', kind: :debtor, name: "Doe's main account" }
33
+ let(:account2) { contact.keepr_accounts.create! number: '70002', kind: :debtor, name: "Doe's second account" }
34
34
 
35
35
  it 'has multiple keepr_accounts' do
36
36
  expect(contact.keepr_accounts).to eq([account1, account2])
37
37
  end
38
38
 
39
39
  it 'has keepr_postings' do
40
- journal = Keepr::Journal.create! :keepr_postings_attributes => [
41
- { :keepr_account => account1, :amount => 30, :side => 'debit' },
42
- { :keepr_account => account_1200, :amount => 30, :side => 'credit' }
40
+ journal = Keepr::Journal.create! keepr_postings_attributes: [
41
+ { keepr_account: account1, amount: 30, side: 'debit' },
42
+ { keepr_account: account_1200, amount: 30, side: 'credit' }
43
43
  ]
44
- other_journal = Keepr::Journal.create! :keepr_postings_attributes => [
45
- { :keepr_account => account_1000, :amount => 20, :side => 'debit' },
46
- { :keepr_account => account_1200, :amount => 20, :side => 'credit' }
44
+ other_journal = Keepr::Journal.create! keepr_postings_attributes: [
45
+ { keepr_account: account_1000, amount: 20, side: 'debit' },
46
+ { keepr_account: account_1200, amount: 20, side: 'credit' }
47
47
  ]
48
48
 
49
49
  expect(contact.keepr_postings.count).to eq(1)
@@ -53,11 +53,11 @@ describe Keepr::ActiveRecordExtension do
53
53
 
54
54
  describe 'Document with associated journal' do
55
55
  subject do
56
- document = Document.create! :number => 'RE-2013-10-12345'
57
- Keepr::Journal.create! :accountable => document,
58
- :keepr_postings_attributes => [
59
- { :keepr_account => account_1000, :amount => 100.99, :side => 'debit' },
60
- { :keepr_account => account_1200, :amount => 100.99, :side => 'credit' }
56
+ document = Document.create! number: 'RE-2013-10-12345'
57
+ Keepr::Journal.create! accountable: document,
58
+ keepr_postings_attributes: [
59
+ { keepr_account: account_1000, amount: 100.99, side: 'debit' },
60
+ { keepr_account: account_1200, amount: 100.99, side: 'credit' }
61
61
  ]
62
62
  document
63
63
  end
@@ -69,13 +69,13 @@ describe Keepr::ActiveRecordExtension do
69
69
  end
70
70
 
71
71
  describe 'scopes' do
72
- let!(:unbooked_document) { Document.create! :number => 'Unbooked' }
72
+ let!(:unbooked_document) { Document.create! number: 'Unbooked' }
73
73
  let!(:booked_document) {
74
- document = Document.create! :number => 'Booked'
75
- Keepr::Journal.create! :accountable => document,
76
- :keepr_postings_attributes => [
77
- { :keepr_account => account_1000, :amount => 100.99, :side => 'debit' },
78
- { :keepr_account => account_1200, :amount => 100.99, :side => 'credit' }
74
+ document = Document.create! number: 'Booked'
75
+ Keepr::Journal.create! accountable: document,
76
+ keepr_postings_attributes: [
77
+ { keepr_account: account_1000, amount: 100.99, side: 'debit' },
78
+ { keepr_account: account_1200, amount: 100.99, side: 'credit' }
79
79
  ]
80
80
  document
81
81
  }