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
@@ -1,35 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::AccountExport
2
- def initialize(accounts, header_options={}, &block)
4
+ def initialize(accounts, header_options = {}, &block)
3
5
  @accounts = accounts
4
6
  @header_options = header_options
5
7
  @block = block
6
8
  end
7
9
 
8
- def to_s
9
- export.to_s
10
- end
11
-
12
- def to_file(filename)
13
- export.to_file(filename)
14
- end
10
+ delegate :to_s, :to_file,
11
+ to: :export
15
12
 
16
- private
13
+ private
17
14
 
18
15
  def export
19
16
  export = Datev::AccountExport.new(@header_options)
20
17
 
21
18
  @accounts.reorder(:number).each do |account|
22
- unless account.debtor? || account.creditor?
23
- export << to_datev(account)
24
- end
19
+ export << to_datev(account) unless account.debtor? || account.creditor?
25
20
  end
26
21
 
27
22
  export
28
23
  end
29
24
 
30
25
  def to_datev(account)
31
- { 'Konto' => account.number,
32
- 'Kontenbeschriftung' => account.name.slice(0,40)
26
+ {
27
+ 'Konto' => account.number,
28
+ 'Kontenbeschriftung' => account.name.slice(0, 40)
33
29
  }.merge(@block ? @block.call(account) : {})
34
30
  end
35
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Keepr::ActiveRecordExtension
2
4
  def self.included(base)
3
5
  base.extend ClassMethods
@@ -5,19 +7,19 @@ module Keepr::ActiveRecordExtension
5
7
 
6
8
  module ClassMethods
7
9
  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
10
+ has_one :keepr_account, class_name: 'Keepr::Account', as: :accountable, dependent: :restrict_with_error
11
+ has_many :keepr_postings, class_name: 'Keepr::Posting', through: :keepr_account, dependent: :restrict_with_error
10
12
  end
11
13
 
12
14
  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
15
+ has_many :keepr_accounts, class_name: 'Keepr::Account', as: :accountable, dependent: :restrict_with_error
16
+ has_many :keepr_postings, class_name: 'Keepr::Posting', through: :keepr_accounts, dependent: :restrict_with_error
15
17
  end
16
18
 
17
19
  def has_keepr_journals
18
- has_many :keepr_journals, :class_name => 'Keepr::Journal', :as => :accountable, :dependent => :restrict_with_error
20
+ has_many :keepr_journals, class_name: 'Keepr::Journal', as: :accountable, dependent: :restrict_with_error
19
21
 
20
- class_eval <<-EOT
22
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
21
23
  def keepr_booked?
22
24
  keepr_journals.exists?
23
25
  end
@@ -27,11 +29,11 @@ module Keepr::ActiveRecordExtension
27
29
  where('keepr_journals.id' => nil)
28
30
  }
29
31
  scope :keepr_booked, -> { joins(:keepr_journals) }
30
- EOT
32
+ CODE
31
33
  end
32
34
 
33
35
  def has_keepr_postings
34
- has_many :keepr_postings, :class_name => 'Keepr::Posting', :as => :accountable, :dependent => :restrict_with_error
36
+ has_many :keepr_postings, class_name: 'Keepr::Posting', as: :accountable, dependent: :restrict_with_error
35
37
  end
36
38
  end
37
39
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::ContactExport
2
- def initialize(accounts, header_options={}, &block)
4
+ def initialize(accounts, header_options = {}, &block)
3
5
  raise ArgumentError unless block_given?
4
6
 
5
7
  @accounts = accounts
@@ -15,22 +17,19 @@ class Keepr::ContactExport
15
17
  export.to_file(filename)
16
18
  end
17
19
 
18
- private
20
+ private
19
21
 
20
22
  def export
21
23
  export = Datev::ContactExport.new(@header_options)
22
24
 
23
25
  @accounts.reorder(:number).each do |account|
24
- if account.debtor? || account.creditor?
25
- export << to_datev(account)
26
- end
26
+ export << to_datev(account) if account.debtor? || account.creditor?
27
27
  end
28
28
 
29
29
  export
30
30
  end
31
31
 
32
32
  def to_datev(account)
33
- { 'Konto' => account.number
34
- }.merge(@block.call(account))
33
+ { 'Konto' => account.number }.merge(@block.call(account))
35
34
  end
36
35
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::CostCenter < ActiveRecord::Base
2
4
  self.table_name = 'keepr_cost_centers'
3
5
 
4
6
  validates_presence_of :number, :name
5
7
  validates_uniqueness_of :number
6
8
 
7
- has_many :keepr_postings, :class_name => 'Keepr::Posting', :foreign_key => 'keepr_cost_center_id', :dependent => :restrict_with_error
9
+ has_many :keepr_postings, class_name: 'Keepr::Posting', foreign_key: 'keepr_cost_center_id', dependent: :restrict_with_error
8
10
  end
@@ -1,42 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Keepr::Group < ActiveRecord::Base
2
4
  self.table_name = 'keepr_groups'
3
5
 
4
- has_ancestry :orphan_strategy => :restrict
6
+ has_ancestry orphan_strategy: :restrict
5
7
 
6
- enum :target => [ :asset, :liability, :profit_and_loss ]
8
+ enum target: %i[asset liability profit_and_loss]
7
9
 
8
10
  validates_presence_of :name
9
11
 
10
- has_many :keepr_accounts, :class_name => 'Keepr::Account', :foreign_key => 'keepr_group_id', :dependent => :restrict_with_error
12
+ has_many :keepr_accounts, class_name: 'Keepr::Account', foreign_key: 'keepr_group_id', dependent: :restrict_with_error
11
13
 
12
- before_validation :get_from_parent
14
+ before_validation :set_target_from_parent
13
15
 
14
16
  validate :check_result_and_target
15
17
 
16
18
  def self.result
17
- where(:is_result => true).first
19
+ where(is_result: true).first
18
20
  end
19
21
 
20
22
  def keepr_postings
21
23
  if is_result
22
- Keepr::Posting.joins(:keepr_account).where(:keepr_accounts => { :kind => [ Keepr::Account.kinds[:revenue],
23
- Keepr::Account.kinds[:expense] ] })
24
+ Keepr::Posting
25
+ .joins(:keepr_account)
26
+ .where(keepr_accounts: { kind: [
27
+ Keepr::Account.kinds[:revenue],
28
+ Keepr::Account.kinds[:expense]
29
+ ] })
24
30
  else
25
- Keepr::Posting.joins(:keepr_account => :keepr_group).merge(self.subtree)
31
+ Keepr::Posting
32
+ .joins(keepr_account: :keepr_group)
33
+ .merge(subtree)
26
34
  end
27
35
  end
28
36
 
29
- private
30
- def get_from_parent
31
- if self.parent
32
- self.target = self.parent.target
37
+ private
38
+
39
+ def set_target_from_parent
40
+ self.class.unscoped do
41
+ self.target = parent.target if parent
33
42
  end
34
43
  end
35
44
 
36
45
  def check_result_and_target
37
- if is_result
38
- # Attribute `is_result` allowed for liability target only
39
- errors.add :base, :liability_needed_for_result unless liability?
40
- end
46
+ return unless is_result
47
+
48
+ # Attribute `is_result` allowed for liability target only
49
+ errors.add :base, :liability_needed_for_result unless liability?
41
50
  end
42
51
  end
@@ -1,24 +1,28 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  class Keepr::GroupsCreator
3
- def initialize(target)
4
- raise ArgumentError unless [ :balance, :profit_and_loss ].include?(target)
4
+ def initialize(target, language = :de)
5
+ raise ArgumentError unless %i[balance profit_and_loss].include?(target)
6
+ raise ArgumentError unless %i[de es en].include?(language)
5
7
 
6
- @target = target
8
+ @target = target
9
+ @language = language
7
10
  end
8
11
 
9
12
  def run
10
13
  case @target
11
14
  when :balance then
12
- load 'asset.txt', :target => :asset
13
- load 'liability.txt', :target => :liability
15
+ load 'asset.txt', target: :asset
16
+ load 'liability.txt', target: :liability
14
17
  when :profit_and_loss
15
- load 'profit_and_loss.txt', :target => :profit_and_loss
18
+ load 'profit_and_loss.txt', target: :profit_and_loss
16
19
  end
17
20
  end
18
21
 
19
- private
22
+ private
23
+
20
24
  def load(filename, options)
21
- full_filename = File.join(File.dirname(__FILE__), "groups_creator/#{filename}".downcase)
25
+ full_filename = File.join(File.dirname(__FILE__), "groups_creator/#{@language.to_s}/#{filename}".downcase)
22
26
  lines = File.readlines(full_filename)
23
27
  last_depth = 0
24
28
  parents = []
@@ -30,12 +34,10 @@ private
30
34
  # Remove leading spaces and separate number and name
31
35
  number, name = line.lstrip.match(/^(.*?)\s(.+)$/).to_a[1..-1]
32
36
 
33
- attributes = options.merge(:name => name, :number => number)
34
- if @target == :balance && name == 'Jahresüberschuss/Jahresfehlbetrag'
35
- attributes[:is_result] = true
36
- end
37
+ attributes = options.merge(name: name, number: number)
38
+ attributes[:is_result] = true if @target == :balance && name == annual_surplus
37
39
 
38
- if depth == 0
40
+ if depth.zero?
39
41
  parents = []
40
42
  group = Keepr::Group.create!(attributes)
41
43
  else
@@ -48,4 +50,15 @@ private
48
50
  last_depth = depth
49
51
  end
50
52
  end
53
+
54
+ def annual_surplus
55
+ case @language
56
+ when :en
57
+ return 'Annual surplus / annual deficit'
58
+ when :es
59
+ return 'Superávit anual / déficit anual'
60
+ when :de
61
+ return 'Jahresüberschuss/Jahresfehlbetrag'
62
+ end
63
+ end
51
64
  end
@@ -0,0 +1,36 @@
1
+ A. Fixed assets
2
+ I. Intangible assets
3
+ 1. Industrial property rights of own creation and similar rights and values
4
+ 2. Concessions acquired in exchange for a fee, industrial property rights and similar rights and values, as well as licenses for said rights and values
5
+ 3. Goodwill
6
+ 4. Advances made
7
+ II. Tangible assets
8
+ 1. Land, territorial rights and buildings, including buildings on third party land
9
+ 2. technical systems and machines
10
+ 3. other equipment, factory and office equipment
11
+ 4. Advances made and assets under construction
12
+ III. Financial assets
13
+ 1. Shares in affiliated companies
14
+ 2. Loans to affiliated companies
15
+ 3. Holdings
16
+ 4. Loans to companies with which there is a participation relationship
17
+ 5. Securities held as fixed assets
18
+ 6. other loans
19
+ B. Current assets
20
+ I. Inventories
21
+ 1. Raw materials and supplies
22
+ 2. unfinished products, unfinished services
23
+ 3. finished products and goods
24
+ 4. Advances made
25
+ II. Accounts receivable and other assets
26
+ 1. Accounts receivable for deliveries and services
27
+ 2. Accounts receivable from affiliated companies
28
+ 3. Claims against companies with which there is a participation relationship
29
+ 4. other assets
30
+ III. Values
31
+ 1. Shares in affiliated companies
32
+ 2. other values
33
+ IV. Cash on hand, Bundesbank balances, bank balances and checks
34
+ C. Prepaid Expenses
35
+ D. Deferred tax assets
36
+ E. Active asset offset difference
@@ -0,0 +1,28 @@
1
+ A. Equity
2
+ I. Drawn capital
3
+ II. Capital reserve
4
+ III. Retained earnings
5
+ 1. Legal reserve
6
+ 2. Reserve for shares of a controlling or majority-owned company
7
+ 3. Legal reserves
8
+ 4. other retained earnings
9
+ IV. Carry-over profit / carry-over loss
10
+ V. Annual surplus / deficit
11
+ B. Provisions
12
+ 1. Provisions for pensions and similar obligations
13
+ 2. Tax provisions
14
+ 3. other provisions
15
+ C. Liabilities
16
+ 1. Bonds
17
+ of which convertible
18
+ 2. Liabilities with banks
19
+ 3. Advances received on orders
20
+ 4. Trade accounts payable
21
+ 5. Liabilities for the acceptance of drafted bills of exchange and the issuance of own bills of exchange
22
+ 6. Liabilities with affiliated companies
23
+ 7. Liabilities to companies with which there is a participation relationship
24
+ 8. other liabilities
25
+ a) of which tax
26
+ b) of which in the context of social security
27
+ D. Prepaid expenses
28
+ E. Deferred tax liabilities
@@ -0,0 +1,31 @@
1
+ 01. Sales
2
+ 02. Increase or decrease in stocks of finished and unfinished products
3
+ 03. other capitalized own work
4
+ 04. other operating income
5
+ 05. Cost of materials
6
+ a) Expenses for raw materials, consumables and supplies and for purchased goods
7
+ b) Expenses for services acquired
8
+ 06. Personnel expenses
9
+ a) Wages and salaries
10
+ b) Social security and pension and living expenses.
11
+ of that for pensions
12
+ 07. Depreciation
13
+ a) on intangible assets and property, plant and equipment
14
+ b) of current assets, to the extent that these exceed the usual depreciation in the corporation
15
+ 08. other operating expenses
16
+ 09. Investment income
17
+ a) of which from affiliated companies
18
+ 10. Income from other securities and loans from financial assets
19
+ a) of which from affiliated companies
20
+ 11. other similar interest and income
21
+ a) of which from affiliated companies
22
+ 12. Depreciation of financial assets and securities held as current assets
23
+ 13. Interest and similar expenses
24
+ of which to affiliated companies
25
+ 14. Results of ordinary business activities
26
+ 15. Extraordinary income
27
+ 16. Extraordinary expenses
28
+ 17. Extraordinary result
29
+ 18. Income and income taxes
30
+ 19. Other taxes
31
+ 20. Annual surplus / annual deficit
@@ -0,0 +1,36 @@
1
+ A. Activos fijos
2
+ I. Activos intangibles
3
+ 1. Derechos de propiedad industrial de creación propia y derechos y valores similares
4
+ 2. Concesiones adquiridas a cambio de un canon, derechos de propiedad industrial y derechos y valores similares, así como licencias sobre dichos derechos y valores
5
+ 3. Fondo de comercio
6
+ 4. Anticipos efectuados
7
+ II. Activos materiales
8
+ 1. Terrenos, derechos territoriales y edificios, incluidos los edificios en terrenos de terceros
9
+ 2. sistemas técnicos y máquinas
10
+ 3. otros equipos, equipos de fábrica y de oficina
11
+ 4. Anticipos efectuados y activos en construcción
12
+ III. Activos financieros
13
+ 1. Acciones en empresas afiliadas
14
+ 2. Préstamos a empresas afiliadas
15
+ 3. Explotaciones
16
+ 4. Préstamos a empresas con las que existe relación de participación
17
+ 5. Valores mantenidos como activo fijo
18
+ 6. otros préstamos
19
+ B. Activo corriente
20
+ I. Inventarios
21
+ 1. Materias primas y suministros
22
+ 2. productos sin terminar, servicios sin terminar
23
+ 3. productos terminados y mercancías
24
+ 4. Anticipos efectuados
25
+ II. Cuentas por cobrar y otros activos
26
+ 1. Cuentas por cobrar por entregas y servicios
27
+ 2. Cuentas por cobrar de empresas afiliadas
28
+ 3. Reclamaciones frente a empresas con las que existe relación de participación
29
+ 4. otros activos
30
+ III. Valores
31
+ 1. Acciones en empresas afiliadas
32
+ 2. otros valores
33
+ IV. Efectivo en caja, saldos del Bundesbank, saldos bancarios y cheques
34
+ C. Gastos pagados por adelantado
35
+ D. Activos por impuestos diferidos
36
+ E. Diferencia activa de compensación de activos
@@ -0,0 +1,28 @@
1
+ A. Equidad
2
+ I. Capital dibujado
3
+ II. Reserva de capital
4
+ III. Ganancias retenidas
5
+ 1. Reserva legal
6
+ 2. Reserva para acciones de una empresa controladora o de propiedad mayoritaria
7
+ 3. Reservas legales
8
+ 4. otras ganancias retenidas
9
+ IV. Beneficios arrastrados / pérdidas arrastradas
10
+ V. Superávit / déficit anual
11
+ B. Provisiones
12
+ 1. Provisiones para pensiones y obligaciones similares
13
+ 2. Disposiciones fiscales
14
+ 3. otras disposiciones
15
+ C. Pasivos
16
+ 1. Bonos
17
+ de los cuales convertible
18
+ 2. Pasivos con los bancos
19
+ 3. Anticipos recibidos en pedidos
20
+ 4. Cuentas comerciales por pagar
21
+ 5. Pasivos por la aceptación de letras de cambio giradas y la emisión de letras de cambio propias
22
+ 6. Pasivos con empresas afiliadas
23
+ 7. Pasivos frente a empresas con las que existe relación de participación
24
+ 8. otros pasivos
25
+ a) de los cuales de impuestos
26
+ b) de los cuales en el contexto de la seguridad social
27
+ D. Gastos pagados por adelantado
28
+ E. Pasivos por impuestos diferidos