has_accounts 0.8.2 → 0.8.3

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.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  require 'rake'
10
- require 'rake/rdoctask'
10
+ require 'rdoc/task'
11
11
 
12
12
  require 'rspec/core'
13
13
  require 'rspec/core/rake_task'
@@ -51,9 +51,10 @@ class Account < ActiveRecord::Base
51
51
 
52
52
  # Calculations
53
53
  def turnover(selector = Date.today, inclusive = true)
54
+ equality = "=" if inclusive
55
+
54
56
  if selector.is_a? Range or selector.is_a? Array
55
57
  if selector.first.is_a? Booking
56
- equality = "=" if inclusive
57
58
  if selector.first.value_date == selector.last.value_date
58
59
  condition = ["date(value_date) = :value_date AND id >#{equality} :first_id AND id <#{equality} :last_id", {
59
60
  :value_date => selector.first.value_date,
@@ -82,11 +83,9 @@ class Account < ActiveRecord::Base
82
83
  end
83
84
  else
84
85
  if selector.is_a? Booking
85
- equality = "=" if inclusive
86
86
  # date(value_date) is needed on sqlite!
87
87
  condition = ["(value_date < :value_date) OR (date(value_date) = :value_date AND id <#{equality} :id)", {:value_date => selector.value_date, :id => selector.id}]
88
88
  else
89
- equality = "=" if inclusive
90
89
  condition = ["date(value_date) <#{equality} ?", selector]
91
90
  end
92
91
  end
@@ -16,6 +16,7 @@ class Account < ActiveRecord::Base
16
16
  # Account Type
17
17
  # ============
18
18
  belongs_to :account_type
19
+ validates_presence_of :account_type
19
20
 
20
21
  def is_asset_account?
21
22
  Account.by_type(['current_assets', 'capital_assets', 'costs']).exists?(self)
@@ -1,6 +1,7 @@
1
1
  class Booking < ActiveRecord::Base
2
2
  # Validation
3
- validates_presence_of :debit_account, :credit_account, :title, :amount, :value_date
3
+ validates_presence_of :debit_account, :credit_account, :title, :value_date
4
+ validates :amount, :presence => true, :numericality => true
4
5
  validates_time :value_date
5
6
 
6
7
  # Account
@@ -74,24 +75,6 @@ class Booking < ActiveRecord::Base
74
75
  end
75
76
  end
76
77
 
77
- def self.scope_by_value_date(value_date)
78
- scoping = self.default_scoping - [@by_value_scope]
79
-
80
- @by_value_scope = {:find => {:conditions => {:value_date => value_date}}}
81
- scoping << @by_value_scope
82
-
83
- Thread.current["#{self}_scoped_methods"] = nil
84
- self.default_scoping = scoping
85
- end
86
-
87
- def self.filter(controller, &block)
88
- if controller.value_date_scope
89
- with_scope(:find => {:conditions => {:value_date => controller.value_date_scope}}, &block)
90
- else
91
- block.call
92
- end
93
- end
94
-
95
78
  # Standard methods
96
79
  def to_s(format = :default)
97
80
  case format
@@ -64,7 +64,7 @@ class Booking < ActiveRecord::Base
64
64
  rescue ArgumentError
65
65
  end
66
66
 
67
- where("title LIKE :text OR comments = :text OR amount = :amount OR value_date = :value_date", :text => text, :amount => amount, :value_date => date)
67
+ where("title LIKE :text OR comments LIKE :text OR amount = :amount OR value_date = :value_date", :text => text, :amount => amount, :value_date => date)
68
68
  }
69
69
 
70
70
  # Returns array of all years we have bookings for
@@ -74,24 +74,6 @@ class Booking < ActiveRecord::Base
74
74
  end
75
75
  end
76
76
 
77
- def self.scope_by_value_date(value_date)
78
- scoping = self.default_scoping - [@by_value_scope]
79
-
80
- @by_value_scope = {:find => {:conditions => {:value_date => value_date}}}
81
- scoping << @by_value_scope
82
-
83
- Thread.current["#{self}_scoped_methods"] = nil
84
- self.default_scoping = scoping
85
- end
86
-
87
- def self.filter(controller, &block)
88
- if controller.value_date_scope
89
- with_scope(:find => {:conditions => {:value_date => controller.value_date_scope}}, &block)
90
- else
91
- block.call
92
- end
93
- end
94
-
95
77
  # Standard methods
96
78
  def to_s(format = :default)
97
79
  case format
@@ -0,0 +1,59 @@
1
+ class SetupHasAccountsEngine < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "account_types", :force => true do |t|
4
+ t.string "name", :limit => 100
5
+ t.string "title", :limit => 100
6
+ t.datetime "created_at"
7
+ t.datetime "updated_at"
8
+ end
9
+
10
+ create_table "accounts", :force => true do |t|
11
+ t.string "title", :limit => 100
12
+ t.integer "parent_id"
13
+ t.integer "account_type_id"
14
+ t.integer "number"
15
+ t.string "code"
16
+ t.integer "type"
17
+ t.integer "holder_id"
18
+ t.string "holder_type"
19
+ t.integer "bank_id"
20
+ t.integer "esr_id"
21
+ t.integer "pc_id"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ add_index "accounts", ["bank_id"], :name => "index_accounts_on_bank_id"
27
+ add_index "accounts", ["code"], :name => "index_accounts_on_code"
28
+ add_index "accounts", ["holder_id", "holder_type"], :name => "index_accounts_on_holder_id_and_holder_type"
29
+ add_index "accounts", ["type"], :name => "index_accounts_on_type"
30
+
31
+ create_table "banks", :force => true do |t|
32
+ t.integer "vcard_id"
33
+ t.datetime "created_at"
34
+ t.datetime "updated_at"
35
+ end
36
+
37
+ create_table "bookings", :force => true do |t|
38
+ t.string "title", :limit => 100
39
+ t.decimal "amount"
40
+ t.integer "credit_account_id"
41
+ t.integer "debit_account_id"
42
+ t.date "value_date"
43
+ t.text "comments", :limit => 1000, :default => ""
44
+ t.string "scan"
45
+ t.string "debit_currency", :default => "CHF"
46
+ t.string "credit_currency", :default => "CHF"
47
+ t.float "exchange_rate", :default => 1.0
48
+ t.datetime "created_at"
49
+ t.datetime "updated_at"
50
+ t.integer "reference_id"
51
+ t.string "reference_type"
52
+ end
53
+ end
54
+
55
+ def self.down
56
+ drop_table :account_types, :accounts, :banks, :bookings
57
+ end
58
+ end
59
+
@@ -0,0 +1,27 @@
1
+ require 'rails/generators/base'
2
+ require 'rails/generators/migration'
3
+
4
+ module HasVcards
5
+ class MigrationGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ def self.source_root
9
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
10
+ end
11
+
12
+ # Implement the required interface for Rails::Generators::Migration.
13
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
14
+ def self.next_migration_number(dirname)
15
+ if ActiveRecord::Base.timestamped_migrations
16
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
17
+ else
18
+ "%.3d" % (current_migration_number(dirname) + 1)
19
+ end
20
+ end
21
+
22
+ def create_migration_file
23
+ migration_template 'migration.rb', 'db/migrate/create_has_vcards.rb'
24
+ end
25
+
26
+ end
27
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_accounts
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Simon H\xC3\xBCrlimann (CyT)"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-17 00:00:00 +02:00
18
+ date: 2011-07-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,25 +29,23 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
 
31
31
  files:
32
- - app/models/account.rb~
33
32
  - app/models/account_scope_extension.rb
33
+ - app/models/booking.rb~
34
34
  - app/models/bank.rb
35
35
  - app/models/account.rb
36
- - app/models/booking.rb
37
- - app/models/account_type.rb~
38
- - app/models/account_type.rb
39
36
  - app/models/bank_account.rb
40
- - app/models/booking.rb~
41
- - lib/generators/has_accounts/templates/migration.rb
42
- - lib/generators/has_accounts/migration_generator.rb
43
- - lib/has_accounts.rb
44
- - lib/has_accounts/model.rb~
37
+ - app/models/account_type.rb
38
+ - app/models/booking.rb
39
+ - app/models/account.rb~
40
+ - lib/has_accounts/railtie.rb
45
41
  - lib/has_accounts/class_methods.rb
46
- - lib/has_accounts/railtie.rb~
47
- - lib/has_accounts/core_ext/rounding.rb~
48
42
  - lib/has_accounts/core_ext/rounding.rb
49
- - lib/has_accounts/railtie.rb
50
43
  - lib/has_accounts/model.rb
44
+ - lib/has_accounts.rb
45
+ - lib/generators/has_accounts/migration_generator.rb
46
+ - lib/generators/has_accounts/templates/migration.rb~
47
+ - lib/generators/has_accounts/templates/migration.rb
48
+ - lib/generators/migration_generator.rb~
51
49
  - MIT-LICENSE
52
50
  - Rakefile
53
51
  - README.md
@@ -81,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
79
  requirements: []
82
80
 
83
81
  rubyforge_project:
84
- rubygems_version: 1.6.0
82
+ rubygems_version: 1.5.2
85
83
  signing_key:
86
84
  specification_version: 3
87
85
  summary: HasAccounts provides models for financial accounting.
@@ -1,6 +0,0 @@
1
- class AccountType < ActiveRecord::Base
2
- # Helpers
3
- def to_s
4
- title
5
- end
6
- end
@@ -1,31 +0,0 @@
1
- module HasAccounts #:nodoc:
2
- module CoreExtensions #:nodoc:
3
- module Rounding
4
- # Rounds the float according to currency rules.
5
- # Currently targeted to Swiss Francs (CHF), usable
6
- # for all currencies having 0.05 as smallest unit.
7
- #
8
- # x = 1.337
9
- # x.round # => 1.35
10
- def currency_round
11
- if self.nil?
12
- return 0.0
13
- else
14
- return (self * 20).round / 20.0
15
- end
16
- end
17
- end
18
-
19
- module BigDecimal
20
- module Rounding
21
- def currency_round
22
- if self.nil?
23
- return BigDecimal.new("0")
24
- else
25
- return (self * 20).round / 20
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,58 +0,0 @@
1
- module HasAccounts
2
- module Model
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- class_inheritable_accessor :direct_account
7
-
8
- has_many :bookings, :as => :reference, :dependent => :destroy do
9
- # TODO: duplicated in Booking (without parameter)
10
- def direct_balance(value_date = nil, direct_account = nil)
11
- return BigDecimal.new('0') unless proxy_owner.direct_account
12
-
13
- direct_account ||= proxy_owner.direct_account
14
- balance = BigDecimal.new('0')
15
-
16
- direct_bookings = scoped
17
- direct_bookings = direct_bookings.where("date(value_date) <= ?", value_date) if value_date
18
-
19
- for booking in direct_bookings.all
20
- balance += booking.accounted_amount(direct_account)
21
- end
22
-
23
- balance
24
- end
25
- end
26
- end
27
-
28
- module ClassMethods
29
- end
30
-
31
- module InstanceMethods
32
- # Delegate to class
33
- def direct_account
34
- self.class.direct_account
35
- end
36
-
37
- # Build booking
38
- def build_booking(params = {}, template_code = nil)
39
- template_code ||= self.class.to_s.underscore + ':invoice'
40
- booking_template = BookingTemplate.find_by_code(template_code)
41
-
42
- # Prepare booking parameters
43
- booking_params = {:reference => self}
44
- booking_params.merge!(params)
45
-
46
- # Build and assign booking
47
- booking = booking_template.build_booking(booking_params)
48
- bookings << booking
49
-
50
- booking
51
- end
52
-
53
- def balance(value_date = nil, direct_account = nil)
54
- bookings.direct_balance(value_date, direct_account)
55
- end
56
- end
57
- end
58
- end
@@ -1,10 +0,0 @@
1
- require 'has_accounts'
2
- require 'rails'
3
-
4
- module HasAccounts
5
- class Railtie < Rails::Engine
6
- Float.send :include, HasAccounts::CoreExtensions::Rounding
7
- Fixnum.send :include, HasAccounts::CoreExtensions::Rounding
8
- BigDecimal.send :include, HasAccounts::CoreExtensions::Rounding
9
- end
10
- end