has_accounts 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/booking.rb +22 -1
- data/app/models/booking.rb~ +1 -1
- metadata +2 -2
data/app/models/booking.rb
CHANGED
@@ -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
|
-
#
|
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
|
|
data/app/models/booking.rb~
CHANGED
@@ -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
|