has_accounts 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,16 +1,20 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
1
9
  require 'rake'
2
- require 'rake/testtask'
3
10
  require 'rake/rdoctask'
4
11
 
5
- desc 'Default: run unit tests.'
6
- task :default => :test
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
7
14
 
8
- desc 'Test the has_accounts plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
14
18
 
15
19
  desc 'Generate documentation for the has_accounts plugin.'
16
20
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -31,8 +31,8 @@ class Booking < ActiveRecord::Base
31
31
  # Scoping
32
32
  default_scope order('value_date, id')
33
33
 
34
- scope :by_value_date, lambda {|value_date| where(:value_date => value_date) }
35
- scope :by_value_period, lambda {|from, to| where(:value_date => (from..to)) }
34
+ scope :by_value_date, lambda {|value_date| where("date(value_date) = ?", value_date) }
35
+ scope :by_value_period, lambda {|from, to| where("date(value_date) BETWEEN :from AND :to", :from => from, :to => to) }
36
36
 
37
37
  scope :by_account, lambda {|account_id|
38
38
  { :conditions => ["debit_account_id = :account_id OR credit_account_id = :account_id", {:account_id => account_id}] }
@@ -169,7 +169,7 @@ class Booking < ActiveRecord::Base
169
169
  new_booking[key] = value
170
170
  }
171
171
 
172
- new_booking
172
+ [self, new_booking]
173
173
  end
174
174
 
175
175
  # Reference
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/base'
2
+ require 'rails/generators/migration'
3
+
4
+ module HasAccounts
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/setup_has_accounts_engine.rb'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,59 @@
1
+ class SetupHasAccountsEngine < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "account_types" 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" 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" do |t|
32
+ t.integer "vcard_id"
33
+ t.datetime "created_at"
34
+ t.datetime "updated_at"
35
+ end
36
+
37
+ create_table "bookings" 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
+
@@ -14,7 +14,7 @@ module HasAccounts
14
14
  balance = BigDecimal.new('0')
15
15
 
16
16
  direct_bookings = scoped
17
- direct_bookings = direct_bookings.where("value_date <= ?", value_date) if value_date
17
+ direct_bookings = direct_bookings.where("date(value_date) <= ?", value_date) if value_date
18
18
 
19
19
  for booking in direct_bookings.all
20
20
  balance += booking.accounted_amount(direct_account)
@@ -40,10 +40,7 @@ module HasAccounts
40
40
  booking_template = BookingTemplate.find_by_code(template_code)
41
41
 
42
42
  # Prepare booking parameters
43
- booking_params = {
44
- :value_date => value_date,
45
- :reference => self
46
- }
43
+ booking_params = {:reference => self}
47
44
  booking_params.merge!(params)
48
45
 
49
46
  # Build and assign booking
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Simon H\xC3\xBCrlimann (CyT)"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-26 00:00:00 +02:00
17
+ date: 2011-04-29 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -36,6 +36,8 @@ files:
36
36
  - app/models/account_type.rb
37
37
  - app/models/bank_account.rb
38
38
  - app/models/booking.rb~
39
+ - lib/generators/has_accounts/templates/migration.rb
40
+ - lib/generators/has_accounts/migration_generator.rb
39
41
  - lib/has_accounts.rb
40
42
  - lib/has_accounts/model.rb~
41
43
  - lib/has_accounts/class_methods.rb