effective_resources 2.17.3 → 2.17.5

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: 6c70e7b28b1a29c7866bcf7dc30678e8d6209b55982ee2d0cbe304c634d5345e
4
- data.tar.gz: 805d91cd88201d62adf8ecdb9a9b2d4b620e735caf11a6ee4883fa774464543e
3
+ metadata.gz: c8d215c9f3f4da7bf1e7776c8a313f7e75c8e2cc611ec5bfa7aab447c9153b70
4
+ data.tar.gz: 6c6775a3ae086b767a3a2277afa1bbb874001a9c0ea4de7c5c13939791b1619c
5
5
  SHA512:
6
- metadata.gz: 3dff69131842340f24d978672a91503c34ce5aaca8043473d2cc2fff2a042fa142e816c0944f2132e909d1fd215f46e8440490fd42c7c20f2ed78fb1ebaa5959
7
- data.tar.gz: 99d503e6756ba059d700f9f1f1eab65258b3c81a65445847edf1cb562ba828ff9e3ba327e32451e04040e3ea3303c2d80142527e88364cbd84ddf1edd00d2803
6
+ metadata.gz: ebb84318ad63c0cd8cdedf95bab1f72784a10d9e0cd80cdf3dd667c9fbc51bbdb7325686a614c963940ca92bd1bc39f2fa498e1c4733833d8c3b63ed663fc9a0
7
+ data.tar.gz: b58c8776531032a60c827a5e78224ebaf23778de79dc0bf2fc86c94dbc949da231606dfc71628ea5abd11083594ba99dfa6ee1f06de7e4dd3ca9096cc20bfcbb
@@ -77,6 +77,9 @@ module ActsAsPurchasableWizard
77
77
  # This will update all order items to match the prices from their purchasable
78
78
  order.try(:update_purchasable_attributes)
79
79
 
80
+ # Handle effective_memberships coupon fees price reduction
81
+ reduce_order_item_coupon_fee_price(order)
82
+
80
83
  # Hook to extend for coupon fees
81
84
  order = before_submit_order_save(order)
82
85
  raise('before_submit_order_save must return an Effective::Order') unless order.kind_of?(Effective::Order)
@@ -91,6 +94,32 @@ module ActsAsPurchasableWizard
91
94
  order
92
95
  end
93
96
 
97
+ # This is used by effective_memberships and effective_events
98
+ # Which both add coupon_fees to their submit_fees
99
+ def reduce_order_item_coupon_fee_price(order)
100
+ # This only applies to orders with coupon fees
101
+ order_items = order.order_items.select { |oi| oi.purchasable.try(:coupon_fee?) }
102
+ return order unless order_items.present?
103
+ raise('multiple coupon fees not supported') if order_items.length > 1
104
+
105
+ # Get the coupon fee
106
+ order_item = order_items.first
107
+ coupon_fee = order_item.purchasable
108
+ raise('expected order item for coupon fee to be a negative price') unless coupon_fee.price.to_i < 0
109
+
110
+ # Calculate price
111
+ subtotal = order.order_items.reject { |oi| oi.purchasable.try(:coupon_fee?) }.sum(&:subtotal)
112
+
113
+ price = 0 if subtotal <= 0
114
+ price ||= [coupon_fee.price, (0 - subtotal)].max
115
+
116
+ # Assign the price to this order item. Underlying fee price stays the same.
117
+ order_item.assign_attributes(price: price)
118
+
119
+ # Return the order
120
+ order
121
+ end
122
+
94
123
  # Should be indempotent.
95
124
  def build_submit_fees_and_order
96
125
  return false if was_submitted?
@@ -134,6 +134,7 @@ module Effective
134
134
  belong_tos_names_attributes
135
135
  .merge(klass_attributes(sort: true))
136
136
  .merge(effective_addresses_attributes)
137
+ .merge(active_storage_attributes.transform_values { |thing| [:active_storage] })
137
138
  end
138
139
 
139
140
  private
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.17.3'.freeze
2
+ VERSION = '2.17.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.3
4
+ version: 2.17.5
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-11-21 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails