has_accounts 3.0.0.beta1 → 3.0.0.beta2
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.
- checksums.yaml +4 -4
- data/app/models/account.rb +18 -0
- data/app/models/booking.rb +5 -2
- data/app/models/booking_template.rb +1 -1
- data/lib/has_accounts/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 579e264a5e2414301a5525c6b97dfe24cc8c5f64
|
4
|
+
data.tar.gz: 846d989c4b8192f05c4447c7a94ca2e334296870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b725ac935eb1fe671a12574ce1a92f97a712735b00683472381016b815249c4bd30ca012cf1fef17c7ec27cf752a5f4e1f8cd2fdc8e3cf28b640fd53203699
|
7
|
+
data.tar.gz: e02026c59e428421d0ed3675ee8d7dc04328b6402aeca15936da9bb9a8336d976462a9b2dcb0afab30294303132d61920e8f952844088dd0da3eb125c081737c
|
data/app/models/account.rb
CHANGED
@@ -51,6 +51,17 @@ class Account < ActiveRecord::Base
|
|
51
51
|
# Tagging
|
52
52
|
# =======
|
53
53
|
if defined?(ActsAsTaggableOn) && ActsAsTaggableOn::Tag.table_exists?
|
54
|
+
class Account::AmbiguousTag < StandardError
|
55
|
+
def initialize(tag, count)
|
56
|
+
@tag = tag
|
57
|
+
@count = count
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
"Given tag '#{@tag}' is ambiguous, found #{@count} records"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
54
65
|
acts_as_taggable
|
55
66
|
attr_accessible :tag_list
|
56
67
|
|
@@ -61,6 +72,13 @@ class Account < ActiveRecord::Base
|
|
61
72
|
def self.tag_collection
|
62
73
|
(default_tags + Account.tag_counts.pluck(:name)).uniq
|
63
74
|
end
|
75
|
+
|
76
|
+
def self.find_by_tag(tag)
|
77
|
+
accounts = tagged_with(tag)
|
78
|
+
count = accounts.count
|
79
|
+
raise Account::AmbiguousTag.new(tag, count) if count > 1
|
80
|
+
accounts.first
|
81
|
+
end
|
64
82
|
end
|
65
83
|
|
66
84
|
# Holder
|
data/app/models/booking.rb
CHANGED
@@ -77,6 +77,9 @@ class Booking < ActiveRecord::Base
|
|
77
77
|
end
|
78
78
|
}
|
79
79
|
|
80
|
+
# Scope for code filter
|
81
|
+
scope :by_code, -> (code) { where(code: code) }
|
82
|
+
|
80
83
|
# Scope for date filter
|
81
84
|
#
|
82
85
|
# @param from [Date]
|
@@ -160,7 +163,7 @@ class Booking < ActiveRecord::Base
|
|
160
163
|
|
161
164
|
# Accounted bookings
|
162
165
|
# ==================
|
163
|
-
SELECT_ACCOUNTED_AMOUNT =
|
166
|
+
SELECT_ACCOUNTED_AMOUNT = 'CASE WHEN credit_account_id = debit_account_id THEN 0.0 WHEN credit_account_id = %{account_id} THEN -bookings.amount WHEN debit_account_id = %{account_id} THEN bookings.amount ELSE 0 END'
|
164
167
|
|
165
168
|
private
|
166
169
|
|
@@ -170,7 +173,7 @@ class Booking < ActiveRecord::Base
|
|
170
173
|
elsif Account.exists?(account_or_id)
|
171
174
|
return account_or_id
|
172
175
|
else
|
173
|
-
|
176
|
+
raise ActiveRecord::RecordNotFound, 'argument needs to be a record of type Account or an id for an existing Account record.'
|
174
177
|
end
|
175
178
|
end
|
176
179
|
|
@@ -117,7 +117,7 @@ class BookingTemplate < ActiveRecord::Base
|
|
117
117
|
# @return [Booking] unsaved Booking
|
118
118
|
def self.build_booking(code, params = {})
|
119
119
|
template = find_by_code(code)
|
120
|
-
|
120
|
+
raise ActiveRecord::RecordNotFound, "BookingTemplate not found for '#{code}'" unless template
|
121
121
|
|
122
122
|
template.build_booking params
|
123
123
|
end
|
data/lib/has_accounts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_accounts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Hürlimann (CyT)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,3 +94,4 @@ signing_key:
|
|
94
94
|
specification_version: 4
|
95
95
|
summary: HasAccounts provides models for financial accounting.
|
96
96
|
test_files: []
|
97
|
+
has_rdoc:
|