has_accounts 0.5.0 → 0.6.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.
@@ -155,6 +155,23 @@ class Booking < ActiveRecord::Base
155
155
  def booking_template_id=(value)
156
156
  end
157
157
 
158
+ # Helpers
159
+ def split(amount, params = {})
160
+ # Clone
161
+ new_booking = self.clone
162
+
163
+ # Set amount
164
+ new_booking[:amount] = amount
165
+ self.amount -= amount
166
+
167
+ # Update attributes
168
+ params.each{|key, value|
169
+ new_booking[key] = value
170
+ }
171
+
172
+ [self, new_booking]
173
+ end
174
+
158
175
  # Reference
159
176
  belongs_to :reference, :polymorphic => true
160
177
  after_save :notify_references
@@ -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
@@ -155,6 +155,23 @@ class Booking < ActiveRecord::Base
155
155
  def booking_template_id=(value)
156
156
  end
157
157
 
158
+ # Helpers
159
+ def split(amount, params = {})
160
+ # Clone
161
+ new_booking = self.clone
162
+
163
+ # Set amount
164
+ new_booking[:amount] = amount
165
+ self.amount -= amount
166
+
167
+ # Update attributes
168
+ params.each{|key, value|
169
+ new_booking[key] = value
170
+ }
171
+
172
+ new_booking
173
+ end
174
+
158
175
  # Reference
159
176
  belongs_to :reference, :polymorphic => true
160
177
  after_save :notify_references
@@ -42,8 +42,7 @@ module HasAccounts
42
42
  # Prepare booking parameters
43
43
  booking_params = {
44
44
  :value_date => value_date,
45
- :reference_type => self.class.name,
46
- :reference_id => self.id
45
+ :reference => self
47
46
  }
48
47
  booking_params.merge!(params)
49
48
 
@@ -40,7 +40,11 @@ module HasAccounts
40
40
  booking_template = BookingTemplate.find_by_code(template_code)
41
41
 
42
42
  # Prepare booking parameters
43
- booking_params = {:value_date => value_date}
43
+ booking_params = {
44
+ :value_date => value_date,
45
+ :reference_type => self.class.name,
46
+ :reference_id => self.id
47
+ }
44
48
  booking_params.merge!(params)
45
49
 
46
50
  # Build and assign booking
@@ -50,8 +54,8 @@ module HasAccounts
50
54
  booking
51
55
  end
52
56
 
53
- def balance(value_date = nil)
54
- bookings.direct_balance(value_date)
57
+ def balance(value_date = nil, direct_account = nil)
58
+ bookings.direct_balance(value_date, direct_account)
55
59
  end
56
60
  end
57
61
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
7
+ - 6
8
8
  - 0
9
- version: 0.5.0
9
+ version: 0.6.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-15 00:00:00 +02:00
17
+ date: 2011-04-26 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20