has_accounts 0.3.0 → 0.4.0

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.
@@ -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
 
@@ -43,7 +43,7 @@ class Booking < ActiveRecord::Base
43
43
  rescue ArgumentError
44
44
  end
45
45
 
46
- where("title LIKE :text OR amount = :amount OR value_date = :value_date", :text => text, :amount => amount, :value_date => date)
46
+ where("title LIKE :text OR remarks = :text OR amount = :amount OR value_date = :value_date", :text => text, :amount => amount, :value_date => date)
47
47
  }
48
48
 
49
49
  # Returns array of all years we have bookings for
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Simon H\xC3\xBCrlimann (CyT)"