effective_memberships 0.9.15 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e299db8cf3241529169d0f61a9524263dce1b1752fb04cbec395951ae7d1d029
4
- data.tar.gz: e04637274efa4c3bffae73bbd27b62588ec3f6c74379050f51c58609f513bbc0
3
+ metadata.gz: 978c99bc1bc8f0106fac7867dc8a07acea70bd94456d248e20cbb2e57c633b76
4
+ data.tar.gz: af1183a241f5b564c7b3ca4aa1ded0768dfde262d3b75da1933ddd177e430ede
5
5
  SHA512:
6
- metadata.gz: 9d01059e8b8e98c6c5ed0838a15a4b126a6d031cbaea7f76adb19146985f687514f5d518ca05bebbf6b9b3735739efd26c63a5d3a970097572d836cadb478c01
7
- data.tar.gz: 00da75ee33edb063d76280cfb6bd1c771903ff24bdab9db0bf5c0ca06cc76e0998bd72313705ae0bf2ef90acf0c37dc4703b9fc5b3d15b34808f13606ccf38bc
6
+ metadata.gz: caa13055dda3360d3d1426710a39923cc79fcf99cf0af710acead650e3f56089d068e4d30fde0072ba2708cc144515a948a4a265624f0726e6afee4e1457861d
7
+ data.tar.gz: 5f8241aba4c6d6ca7757346ae74520993d48d4d04af8c5bdf486337ec2e939da8f2d7641fe746319d8c284190c07594b0be1b675240e996beee98815bb124c74
@@ -42,6 +42,9 @@ module Admin
42
42
 
43
43
  col :checkout_type, search: Effective::Fee::CHECKOUT_TYPES, visible: false
44
44
 
45
+ col :late_on, visible: false
46
+ col :not_in_good_standing_on, visible: false
47
+
45
48
  unless attributes[:total] == false
46
49
  aggregate :total
47
50
  end
@@ -99,6 +99,10 @@ module EffectiveMembershipsOwner
99
99
  fees.select { |fee| fee.fee_payment_fee? && !fee.purchased? }
100
100
  end
101
101
 
102
+ def outstanding_renewal_fees
103
+ fees.select { |fee| fee.fee_type == 'Renewal' && !fee.purchased? }
104
+ end
105
+
102
106
  def outstanding_fee_payments
103
107
  fee_payments = EffectiveMemberships.FeePayment.all
104
108
 
@@ -333,6 +337,25 @@ module EffectiveMembershipsOwner
333
337
  save!
334
338
  end
335
339
 
340
+ # Delete the last membership history
341
+ def rollback_membership_history!
342
+ raise('expected membership to be present') unless membership.present?
343
+
344
+ (history, last) = membership_histories.last(2)
345
+ raise('expected 2 or more membership histories') unless history.present? && last.present?
346
+
347
+ last.mark_for_destruction
348
+ history.assign_attributes(end_on: nil)
349
+
350
+ membership.assign_attributes(
351
+ number: history.number,
352
+ categories: history.membership_categories,
353
+ statuses: history.membership_statuses
354
+ )
355
+
356
+ save!
357
+ end
358
+
336
359
  def build_membership_history(start_on: nil, notes: nil)
337
360
  raise('expected membership to be present') unless membership.present?
338
361
 
@@ -76,27 +76,8 @@ module EffectiveMembershipsRegistrar
76
76
  membership.number ||= number
77
77
  membership.number_as_integer ||= (Integer(number) rescue nil)
78
78
 
79
- # Delete any removed statuses
80
- membership.membership_statuses.each do |membership_status|
81
- next if statuses.include?(membership_status.status)
82
- membership_status.mark_for_destruction
83
- end
84
-
85
- # Build any additional statuses
86
- statuses.each do |status|
87
- membership.build_membership_status(status: status)
88
- end
89
-
90
- # Delete any removed categories
91
- membership.membership_categories.each do |membership_category|
92
- next if categories.include?(membership_category.category)
93
- membership_category.mark_for_destruction
94
- end
95
-
96
- # Build any additional categories
97
- categories.each do |category|
98
- membership.build_membership_category(category: category)
99
- end
79
+ # Builds the membership_categories and membership_statuses. Marks for destruction ones that don't exist.
80
+ membership.assign_attributes(statuses: statuses, categories: categories)
100
81
 
101
82
  changed = membership.membership_categories.any? { |mc| mc.new_record? || mc.marked_for_destruction? }
102
83
  changed ||= membership.membership_statuses.any? { |ms| ms.new_record? || ms.marked_for_destruction? }
@@ -175,6 +156,7 @@ module EffectiveMembershipsRegistrar
175
156
  raise('expected to and from to be different') if from == to
176
157
 
177
158
  date ||= Time.zone.now
159
+ period = period(date: date)
178
160
 
179
161
  # Existing Membership
180
162
  membership = owner.membership
@@ -190,11 +172,18 @@ module EffectiveMembershipsRegistrar
190
172
  membership.build_membership_status(status: status) if status.present?
191
173
 
192
174
  unless skip_fees
193
- fee = owner.build_prorated_fee(date: date)
194
- raise('already has purchased prorated fee') if fee.purchased?
175
+ existing = owner.membership_period_fee(category: from, period: period)
176
+
177
+ if existing
178
+ fee = owner.build_prorated_fee(date: date)
179
+ raise('already has purchased prorated fee') if fee.purchased?
195
180
 
196
- fee = owner.build_discount_fee(date: date, from: from)
197
- raise('already has purchased discount fee') if fee.purchased?
181
+ fee = owner.build_discount_fee(date: date, from: from)
182
+ raise('already has purchased discount fee') if fee.purchased?
183
+ else
184
+ fee = owner.build_renewal_fee(category: to, period: period)
185
+ raise('already has purchased renewal fee') if fee.purchased?
186
+ end
198
187
  end
199
188
 
200
189
  save!(owner, date: date)
@@ -156,6 +156,21 @@ module Effective
156
156
  membership_categories.reject(&:marked_for_destruction?).map(&:category_id)
157
157
  end
158
158
 
159
+ def categories=(categories)
160
+ categories = Array(categories)
161
+ raise('expecting a membership category') if categories.any? { |cat| !cat.class.respond_to?(:effective_memberships_category?) }
162
+
163
+ # Delete any removed categories
164
+ membership_categories.each do |membership_category|
165
+ membership_category.mark_for_destruction unless categories.include?(membership_category.category)
166
+ end
167
+
168
+ # Build any additional categories
169
+ categories.each { |category| build_membership_category(category: category) }
170
+
171
+ nil
172
+ end
173
+
159
174
  # We might want to use singular memberships.
160
175
  def category
161
176
  raise('expected singular usage but there are more than one membership category') if categories.length > 1
@@ -192,6 +207,21 @@ module Effective
192
207
  membership_statuses.reject(&:marked_for_destruction?).map(&:status_id)
193
208
  end
194
209
 
210
+ def statuses=(statuses)
211
+ statuses = Array(statuses)
212
+ raise('expecting a membership category') if statuses.any? { |status| !status.class.respond_to?(:effective_memberships_status?) }
213
+
214
+ # Delete any removed statuses
215
+ membership_statuses.each do |membership_status|
216
+ membership_status.mark_for_destruction unless statuses.include?(membership_status.status)
217
+ end
218
+
219
+ # Build any additional statuses
220
+ statuses.each { |status| build_membership_status(status: status) }
221
+
222
+ nil
223
+ end
224
+
195
225
  def statuses_sentence
196
226
  statuses.map(&:to_s).to_sentence.presence || 'None'
197
227
  end
@@ -31,8 +31,11 @@
31
31
  %li A #{month} prorated fee
32
32
 
33
33
  - if applicant.reclassification?
34
- %li A #{month} prorated fee to the new category
35
- %li A #{month} discount fee from their old category
34
+ - if applicant.owner.outstanding_renewal_fees.present?
35
+ %li A renewal fee in their new category
36
+ - else
37
+ %li A #{month} prorated fee to the new category
38
+ %li A #{month} discount fee from their old category
36
39
 
37
40
  - if applicant.reinstatement?
38
41
  %li A #{month} prorated fee to their reinstatement category
@@ -1,3 +1,3 @@
1
1
  module EffectiveMemberships
2
- VERSION = '0.9.15'
2
+ VERSION = '0.10.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_memberships
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-13 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails