has_accounts 0.4.0 → 0.4.1

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.
@@ -64,7 +64,7 @@ class Booking < ActiveRecord::Base
64
64
  rescue ArgumentError
65
65
  end
66
66
 
67
- where("title LIKE :text OR remarks = :text OR amount = :amount OR value_date = :value_date", :text => text, :amount => amount, :value_date => date)
67
+ where("title LIKE :text OR comments = :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
@@ -3,10 +3,31 @@ class Booking < ActiveRecord::Base
3
3
  validates_presence_of :debit_account, :credit_account, :title, :amount, :value_date
4
4
  validates_time :value_date
5
5
 
6
- # Associations
6
+ # Account
7
7
  belongs_to :debit_account, :foreign_key => 'debit_account_id', :class_name => "Account"
8
8
  belongs_to :credit_account, :foreign_key => 'credit_account_id', :class_name => "Account"
9
9
 
10
+ def direct_account
11
+ return nil unless reference
12
+
13
+ return reference.direct_account if reference.respond_to? :direct_account
14
+ end
15
+
16
+ def contra_account(account = nil)
17
+ # Derive from direct_account if available
18
+ account ||= direct_account
19
+
20
+ return unless account
21
+
22
+ if debit_account == account
23
+ return credit_account
24
+ elsif credit_account == account
25
+ return debit_account
26
+ else
27
+ return nil
28
+ end
29
+ end
30
+
10
31
  # Scoping
11
32
  default_scope order('value_date, id')
12
33
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Simon H\xC3\xBCrlimann (CyT)"