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.
- data/app/models/booking.rb +1 -1
- data/app/models/booking.rb~ +22 -1
- metadata +2 -2
data/app/models/booking.rb
CHANGED
@@ -64,7 +64,7 @@ class Booking < ActiveRecord::Base
|
|
64
64
|
rescue ArgumentError
|
65
65
|
end
|
66
66
|
|
67
|
-
where("title LIKE :text OR
|
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
|
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
|
|