solidus_core 2.10.0.beta1 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -4
  3. data/app/helpers/spree/products_helper.rb +2 -1
  4. data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
  5. data/app/models/concerns/spree/user_methods.rb +2 -2
  6. data/app/models/spree/address.rb +11 -15
  7. data/app/models/spree/adjustment.rb +11 -0
  8. data/app/models/spree/calculator/price_sack.rb +1 -1
  9. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  10. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  11. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  12. data/app/models/spree/carton.rb +1 -1
  13. data/app/models/spree/credit_card.rb +2 -2
  14. data/app/models/spree/inventory_unit.rb +1 -19
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/order.rb +3 -2
  17. data/app/models/spree/order/checkout.rb +1 -1
  18. data/app/models/spree/order/payments.rb +2 -2
  19. data/app/models/spree/order_capturing.rb +2 -2
  20. data/app/models/spree/order_taxation.rb +2 -2
  21. data/app/models/spree/payment.rb +4 -41
  22. data/app/models/spree/payment/processing.rb +2 -2
  23. data/app/models/spree/payment_method.rb +2 -2
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product/scopes.rb +8 -7
  26. data/app/models/spree/promotion.rb +27 -12
  27. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  28. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  29. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  30. data/app/models/spree/promotion/rules/product.rb +3 -3
  31. data/app/models/spree/promotion_action.rb +1 -1
  32. data/app/models/spree/promotion_chooser.rb +2 -2
  33. data/app/models/spree/promotion_code.rb +9 -8
  34. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  35. data/app/models/spree/promotion_rule.rb +1 -1
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +3 -11
  38. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  39. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  40. data/app/models/spree/return_authorization.rb +1 -7
  41. data/app/models/spree/return_item.rb +3 -42
  42. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  43. data/app/models/spree/shipment.rb +4 -38
  44. data/app/models/spree/shipping_calculator.rb +0 -4
  45. data/app/models/spree/shipping_method.rb +1 -1
  46. data/app/models/spree/state.rb +1 -1
  47. data/app/models/spree/stock/differentiator.rb +1 -1
  48. data/app/models/spree/stock/package.rb +1 -1
  49. data/app/models/spree/stock_item.rb +1 -1
  50. data/app/models/spree/stock_quantities.rb +13 -12
  51. data/app/models/spree/tax_calculator/default.rb +0 -4
  52. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  53. data/app/models/spree/tax_rate.rb +4 -0
  54. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  55. data/app/models/spree/user_last_url_storer.rb +46 -0
  56. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  57. data/app/models/spree/variant.rb +9 -9
  58. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  59. data/app/models/spree/zone.rb +1 -1
  60. data/config/initializers/money.rb +2 -0
  61. data/config/locales/en.yml +12 -0
  62. data/lib/generators/spree/install/install_generator.rb +3 -0
  63. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  64. data/lib/spree/app_configuration.rb +18 -3
  65. data/lib/spree/core.rb +12 -0
  66. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  67. data/lib/spree/core/engine.rb +2 -2
  68. data/lib/spree/core/environment_extension.rb +9 -0
  69. data/lib/spree/core/importer/order.rb +26 -26
  70. data/lib/spree/core/product_filters.rb +15 -15
  71. data/lib/spree/core/role_configuration.rb +2 -2
  72. data/lib/spree/core/search/variant.rb +1 -1
  73. data/lib/spree/core/state_machines.rb +78 -0
  74. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  75. data/lib/spree/core/state_machines/payment.rb +61 -0
  76. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  77. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  78. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  79. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  80. data/lib/spree/core/state_machines/shipment.rb +58 -0
  81. data/lib/spree/core/stock_configuration.rb +1 -0
  82. data/lib/spree/core/validators/email.rb +1 -8
  83. data/lib/spree/core/version.rb +1 -1
  84. data/lib/spree/money.rb +2 -2
  85. data/lib/spree/permission_sets/user_management.rb +3 -0
  86. data/lib/spree/permitted_attributes.rb +3 -3
  87. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  88. data/lib/spree/testing_support/dummy_app.rb +4 -1
  89. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  90. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  91. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  92. data/solidus_core.gemspec +2 -2
  93. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  94. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  95. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  96. data/spec/models/spree/address_spec.rb +23 -0
  97. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  98. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  99. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  100. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  101. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  102. data/spec/models/spree/carton_spec.rb +8 -0
  103. data/spec/models/spree/classification_spec.rb +21 -9
  104. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  105. data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
  106. data/spec/models/spree/order_merger_spec.rb +3 -3
  107. data/spec/models/spree/order_spec.rb +8 -15
  108. data/spec/models/spree/order_updater_spec.rb +4 -3
  109. data/spec/models/spree/payment_create_spec.rb +4 -14
  110. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  111. data/spec/models/spree/preference_spec.rb +4 -4
  112. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  113. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  114. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  115. data/spec/models/spree/promotion_spec.rb +73 -52
  116. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
  117. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  118. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  119. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  120. data/spec/models/spree/shipping_method_spec.rb +32 -0
  121. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  122. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  123. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  124. data/spec/models/spree/stock/package_spec.rb +28 -28
  125. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  126. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  127. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  128. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  129. data/spec/models/spree/store_credit_spec.rb +1 -1
  130. data/spec/models/spree/tax_rate_spec.rb +1 -0
  131. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  132. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  133. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  134. metadata +17 -12
  135. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
  136. data/spec/models/spree/order/updating_spec.rb +0 -18
@@ -93,8 +93,8 @@ module Spree
93
93
  else
94
94
  active.available_to_users.available_to_admin
95
95
  end
96
- available_payment_methods.select do |p|
97
- store.nil? || store.payment_methods.empty? || store.payment_methods.include?(p)
96
+ available_payment_methods.select do |payment|
97
+ store.nil? || store.payment_methods.empty? || store.payment_methods.include?(payment)
98
98
  end
99
99
  end
100
100
 
@@ -25,7 +25,7 @@ module Spree
25
25
  variants_including_master.discard_all
26
26
  self.product_option_types = []
27
27
  self.product_properties = []
28
- self.classifications = []
28
+ self.classifications.destroy_all
29
29
  self.product_promotion_rules = []
30
30
  end
31
31
 
@@ -190,7 +190,7 @@ module Spree
190
190
  # @return [Hash] option_type as keys, array of variants as values.
191
191
  def categorise_variants_from_option(opt_type, pricing_options = Spree::Config.default_pricing_options)
192
192
  return {} unless option_types.include?(opt_type)
193
- variants.with_prices(pricing_options).group_by { |v| v.option_values.detect { |o| o.option_type == opt_type } }
193
+ variants.with_prices(pricing_options).group_by { |variant| variant.option_values.detect { |option| option.option_type == opt_type } }
194
194
  end
195
195
  deprecate :categorise_variants_from_option, deprecator: Spree::Deprecation
196
196
 
@@ -323,7 +323,7 @@ module Spree
323
323
 
324
324
  def any_variants_not_track_inventory?
325
325
  if variants_including_master.loaded?
326
- variants_including_master.any? { |v| !v.should_track_inventory? }
326
+ variants_including_master.any? { |variant| !variant.should_track_inventory? }
327
327
  else
328
328
  !Spree::Config.track_inventory_levels || variants_including_master.where(track_inventory: false).exists?
329
329
  end
@@ -241,19 +241,20 @@ module Spree
241
241
  # Always return array with at least an empty string to avoid SQL errors
242
242
  def prepare_words(words)
243
243
  return [''] if words.blank?
244
- a = words.split(/[,\s]/).map(&:strip)
245
- a.any? ? a : ['']
244
+
245
+ splitted = words.split(/[,\s]/).map(&:strip)
246
+ splitted.any? ? splitted : ['']
246
247
  end
247
248
 
248
249
  def get_taxons(*ids_or_records_or_names)
249
250
  taxons = Spree::Taxon.table_name
250
- ids_or_records_or_names.flatten.map { |t|
251
- case t
252
- when Integer then Spree::Taxon.find_by(id: t)
251
+ ids_or_records_or_names.flatten.map { |taxon|
252
+ case taxon
253
+ when Integer then Spree::Taxon.find_by(id: taxon)
253
254
  when ActiveRecord::Base then t
254
255
  when String
255
- Spree::Taxon.find_by(name: t) ||
256
- Spree::Taxon.where("#{taxons}.permalink LIKE ? OR #{taxons}.permalink = ?", "%/#{t}/", "#{t}/").first
256
+ Spree::Taxon.find_by(name: taxon) ||
257
+ Spree::Taxon.where("#{taxons}.permalink LIKE ? OR #{taxons}.permalink = ?", "%/#{taxon}/", "#{taxon}/").first
257
258
  end
258
259
  }.compact.flatten.uniq
259
260
  end
@@ -126,9 +126,12 @@ module Spree
126
126
  # called anytime order.recalculate happens
127
127
  def eligible?(promotable, promotion_code: nil)
128
128
  return false if inactive?
129
- return false if usage_limit_exceeded?
130
- return false if promotion_code && promotion_code.usage_limit_exceeded?
131
129
  return false if blacklisted?(promotable)
130
+
131
+ excluded_orders = eligibility_excluded_orders(promotable)
132
+ return false if usage_limit_exceeded?(excluded_orders: excluded_orders)
133
+ return false if promotion_code&.usage_limit_exceeded?(excluded_orders: excluded_orders)
134
+
132
135
  !!eligible_rules(promotable, {})
133
136
  end
134
137
 
@@ -138,7 +141,8 @@ module Spree
138
141
  def eligible_rules(promotable, options = {})
139
142
  # Promotions without rules are eligible by default.
140
143
  return [] if rules.none?
141
- eligible = lambda { |r| r.eligible?(promotable, options) }
144
+
145
+ eligible = lambda { |rule| rule.eligible?(promotable, options) }
142
146
  specific_rules = rules.for(promotable)
143
147
  return [] if specific_rules.none?
144
148
 
@@ -165,23 +169,23 @@ module Spree
165
169
 
166
170
  # Whether the promotion has exceeded it's usage restrictions.
167
171
  #
172
+ # @param excluded_orders [Array<Spree::Order>] Orders to exclude from usage limit
168
173
  # @return true or false
169
- def usage_limit_exceeded?
174
+ def usage_limit_exceeded?(excluded_orders: [])
170
175
  if usage_limit
171
- usage_count >= usage_limit
176
+ usage_count(excluded_orders: excluded_orders) >= usage_limit
172
177
  end
173
178
  end
174
179
 
175
180
  # Number of times the code has been used overall
176
181
  #
182
+ # @param excluded_orders [Array<Spree::Order>] Orders to exclude from usage count
177
183
  # @return [Integer] usage count
178
- def usage_count
179
- Spree::Adjustment.eligible.
180
- promotion.
181
- where(source_id: actions.map(&:id)).
182
- joins(:order).
183
- merge(Spree::Order.complete).
184
- distinct.
184
+ def usage_count(excluded_orders: [])
185
+ Spree::Adjustment.promotion.
186
+ eligible.
187
+ in_completed_orders(excluded_orders: excluded_orders).
188
+ where(source_id: actions).
185
189
  count(:order_id)
186
190
  end
187
191
 
@@ -255,8 +259,19 @@ module Spree
255
259
 
256
260
  def apply_automatically_disallowed_with_codes_or_paths
257
261
  return unless apply_automatically
262
+
258
263
  errors.add(:apply_automatically, :disallowed_with_code) if codes.any?
259
264
  errors.add(:apply_automatically, :disallowed_with_path) if path.present?
260
265
  end
266
+
267
+ def eligibility_excluded_orders(promotable)
268
+ if promotable.is_a?(Spree::Order)
269
+ [promotable]
270
+ elsif promotable.respond_to?(:order)
271
+ [promotable.order]
272
+ else
273
+ []
274
+ end
275
+ end
261
276
  end
262
277
  end
@@ -67,7 +67,7 @@ module Spree
67
67
  line_items = actionable_line_items(order)
68
68
 
69
69
  actioned_line_items = order.line_item_adjustments.reload.
70
- select { |a| a.source == self && a.amount < 0 }.
70
+ select { |adjustment| adjustment.source == self && adjustment.amount < 0 }.
71
71
  map(&:adjustable)
72
72
  other_line_items = actioned_line_items - [line_item]
73
73
 
@@ -21,7 +21,7 @@ module Spree
21
21
  end
22
22
  # Did we actually end up applying any adjustments?
23
23
  # If so, then this action should be classed as 'successful'
24
- results.any? { |r| r == true }
24
+ results.any? { |result| result == true }
25
25
  end
26
26
 
27
27
  def label
@@ -29,8 +29,8 @@ module Spree
29
29
  def preferred_eligible_values
30
30
  values = preferences[:eligible_values] || {}
31
31
  Hash[values.keys.map(&:to_i).zip(
32
- values.values.map do |v|
33
- (v.is_a?(Array) ? v : v.split(",")).map(&:to_i)
32
+ values.values.map do |value|
33
+ (value.is_a?(Array) ? value : value.split(",")).map(&:to_i)
34
34
  end
35
35
  )]
36
36
  end
@@ -32,15 +32,15 @@ module Spree
32
32
 
33
33
  case preferred_match_policy
34
34
  when 'all'
35
- unless eligible_products.all? { |p| order.products.include?(p) }
35
+ unless eligible_products.all? { |product| order.products.include?(product) }
36
36
  eligibility_errors.add(:base, eligibility_error_message(:missing_product), error_code: :missing_product)
37
37
  end
38
38
  when 'any'
39
- unless order.products.any? { |p| eligible_products.include?(p) }
39
+ unless order.products.any? { |product| eligible_products.include?(product) }
40
40
  eligibility_errors.add(:base, eligibility_error_message(:no_applicable_products), error_code: :no_applicable_products)
41
41
  end
42
42
  when 'none'
43
- unless order.products.none? { |p| eligible_products.include?(p) }
43
+ unless order.products.none? { |product| eligible_products.include?(product) }
44
44
  eligibility_errors.add(:base, eligibility_error_message(:has_excluded_product), error_code: :has_excluded_product)
45
45
  end
46
46
  else
@@ -16,7 +16,7 @@ module Spree
16
16
 
17
17
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions, optional: true
18
18
 
19
- scope :of_type, ->(t) { where(type: Array.wrap(t).map(&:to_s)) }
19
+ scope :of_type, ->(type) { where(type: Array.wrap(type).map(&:to_s)) }
20
20
  scope :shipping, -> { of_type(Spree::Config.environment.promotions.shipping_actions.to_a) }
21
21
 
22
22
  # Updates the state of the order or performs some other action depending on
@@ -26,8 +26,8 @@ module Spree
26
26
 
27
27
  # @return The best promotion from this set of adjustments.
28
28
  def best_promotion_adjustment
29
- @best_promotion_adjustment ||= @adjustments.select(&:eligible?).min_by do |a|
30
- [a.amount, -a.id]
29
+ @best_promotion_adjustment ||= @adjustments.select(&:eligible?).min_by do |adjustment|
30
+ [adjustment.amount, -adjustment.id]
31
31
  end
32
32
  end
33
33
  end
@@ -14,22 +14,23 @@ class Spree::PromotionCode < Spree::Base
14
14
 
15
15
  # Whether the promotion code has exceeded its usage restrictions
16
16
  #
17
+ # @param excluded_orders [Array<Spree::Order>] Orders to exclude from usage limit
17
18
  # @return true or false
18
- def usage_limit_exceeded?
19
+ def usage_limit_exceeded?(excluded_orders: [])
19
20
  if usage_limit
20
- usage_count >= usage_limit
21
+ usage_count(excluded_orders: excluded_orders) >= usage_limit
21
22
  end
22
23
  end
23
24
 
24
25
  # Number of times the code has been used overall
25
26
  #
27
+ # @param excluded_orders [Array<Spree::Order>] Orders to exclude from usage count
26
28
  # @return [Integer] usage count
27
- def usage_count
28
- adjustments.eligible.
29
- joins(:order).
30
- merge(Spree::Order.complete).
31
- distinct.
32
- count(:order_id)
29
+ def usage_count(excluded_orders: [])
30
+ adjustments.
31
+ eligible.
32
+ in_completed_orders(excluded_orders: excluded_orders).
33
+ count(:order_id)
33
34
  end
34
35
 
35
36
  def usage_limit
@@ -33,12 +33,12 @@ class ::Spree::PromotionCode::BatchBuilder
33
33
  def build_promotion_codes
34
34
  generate_random_codes
35
35
  promotion_code_batch.update!(state: "completed")
36
- rescue StandardError => e
36
+ rescue StandardError => error
37
37
  promotion_code_batch.update!(
38
- error: e.inspect,
38
+ error: error.inspect,
39
39
  state: "failed"
40
40
  )
41
- raise e
41
+ raise error
42
42
  end
43
43
 
44
44
  private
@@ -5,7 +5,7 @@ module Spree
5
5
  class PromotionRule < Spree::Base
6
6
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_rules, optional: true
7
7
 
8
- scope :of_type, ->(t) { where(type: t) }
8
+ scope :of_type, ->(type) { where(type: type) }
9
9
 
10
10
  validates :promotion, presence: true
11
11
  validate :unique_per_promotion, on: :create
@@ -68,8 +68,8 @@ module Spree
68
68
  end
69
69
 
70
70
  response
71
- rescue ActiveMerchant::ConnectionError => e
72
- logger.error(I18n.t('spree.gateway_error') + " #{e.inspect}")
71
+ rescue ActiveMerchant::ConnectionError => error
72
+ logger.error(I18n.t('spree.gateway_error') + " #{error.inspect}")
73
73
  raise Core::GatewayError.new(I18n.t('spree.unable_to_connect_to_gateway'))
74
74
  end
75
75
 
@@ -59,15 +59,7 @@ module Spree
59
59
  class_attribute :reimbursement_failure_hooks
60
60
  self.reimbursement_failure_hooks = []
61
61
 
62
- state_machine :reimbursement_status, initial: :pending do
63
- event :errored do
64
- transition to: :errored, from: [:pending, :errored]
65
- end
66
-
67
- event :reimbursed do
68
- transition to: :reimbursed, from: [:pending, :errored]
69
- end
70
- end
62
+ include ::Spree::Config.state_machines.reimbursement
71
63
 
72
64
  class << self
73
65
  def build_from_customer_return(customer_return)
@@ -112,11 +104,11 @@ module Spree
112
104
  if unpaid_amount_within_tolerance?
113
105
  reimbursed!
114
106
  Spree::Event.fire 'reimbursement_reimbursed', reimbursement: self
115
- reimbursement_success_hooks.each { |h| h.call self }
107
+ reimbursement_success_hooks.each { |hook| hook.call self }
116
108
  else
117
109
  errored!
118
110
  Spree::Event.fire 'reimbursement_errored', reimbursement: self
119
- reimbursement_failure_hooks.each { |h| h.call self }
111
+ reimbursement_failure_hooks.each { |hook| hook.call self }
120
112
  end
121
113
 
122
114
  if errored?
@@ -18,7 +18,7 @@ module Spree
18
18
 
19
19
  def initialize(return_items)
20
20
  @return_items = return_items
21
- @reimbursement_type_hash = Hash.new { |h, k| h[k] = [] }
21
+ @reimbursement_type_hash = Hash.new { |hash, key| hash[key] = [] }
22
22
  end
23
23
 
24
24
  def calculate_reimbursement_types
@@ -63,8 +63,8 @@ module Spree
63
63
 
64
64
  def sorted_eligible_refund_payments(payments)
65
65
  if eligible_refund_methods = self.eligible_refund_methods
66
- payments = payments.select { |p| eligible_refund_methods.include? p.payment_method.class }
67
- payments = payments.sort_by { |p| eligible_refund_methods.index(p.payment_method.class) }
66
+ payments = payments.select { |payment| eligible_refund_methods.include? payment.payment_method.class }
67
+ payments = payments.sort_by { |payment| eligible_refund_methods.index(payment.payment_method.class) }
68
68
  end
69
69
  payments
70
70
  end
@@ -22,13 +22,7 @@ module Spree
22
22
  validate :must_have_shipped_units, on: :create
23
23
  validate :no_previously_exchanged_inventory_units, on: :create
24
24
 
25
- state_machine initial: :authorized do
26
- before_transition to: :canceled, do: :cancel_return_items
27
-
28
- event :cancel do
29
- transition to: :canceled, from: :authorized, if: lambda { |return_authorization| return_authorization.can_cancel_return_items? }
30
- end
31
- end
25
+ include ::Spree::Config.state_machines.return_authorization
32
26
 
33
27
  extend DisplayMoney
34
28
  money_methods :pre_tax_total, :amount, :total_excluding_vat
@@ -77,22 +77,8 @@ module Spree
77
77
  before_create :set_default_amount, unless: :amount_changed?
78
78
  before_save :set_exchange_amount
79
79
 
80
- state_machine :reception_status, initial: :awaiting do
81
- after_transition to: COMPLETED_RECEPTION_STATUSES, do: :attempt_accept
82
- after_transition to: COMPLETED_RECEPTION_STATUSES, do: :check_unexchange
83
- after_transition to: :received, do: :process_inventory_unit!
84
-
85
- event(:cancel) { transition to: :cancelled, from: :awaiting }
86
-
87
- event(:receive) { transition to: :received, from: INTERMEDIATE_RECEPTION_STATUSES + [:awaiting] }
88
- event(:unexchange) { transition to: :unexchanged, from: [:awaiting] }
89
- event(:give) { transition to: :given_to_customer, from: :awaiting }
90
- event(:lost) { transition to: :lost_in_transit, from: :awaiting }
91
- event(:wrong_item_shipped) { transition to: :shipped_wrong_item, from: :awaiting }
92
- event(:short_shipped) { transition to: :short_shipped, from: :awaiting }
93
- event(:in_transit) { transition to: :in_transit, from: :awaiting }
94
- event(:expired) { transition to: :expired, from: :awaiting }
95
- end
80
+ include ::Spree::Config.state_machines.return_item_reception
81
+ include ::Spree::Config.state_machines.return_item_acceptance
96
82
 
97
83
  extend DisplayMoney
98
84
  money_methods :pre_tax_amount, :amount, :total, :total_excluding_vat
@@ -104,31 +90,6 @@ module Spree
104
90
  COMPLETED_RECEPTION_STATUSES.map(&:to_s).include?(reception_status.to_s)
105
91
  end
106
92
 
107
- state_machine :acceptance_status, initial: :pending do
108
- event :attempt_accept do
109
- transition to: :accepted, from: :accepted
110
- transition to: :accepted, from: :pending, if: ->(return_item) { return_item.eligible_for_return? }
111
- transition to: :manual_intervention_required, from: :pending, if: ->(return_item) { return_item.requires_manual_intervention? }
112
- transition to: :rejected, from: :pending
113
- end
114
-
115
- # bypasses eligibility checks
116
- event :accept do
117
- transition to: :accepted, from: [:accepted, :pending, :manual_intervention_required]
118
- end
119
-
120
- # bypasses eligibility checks
121
- event :reject do
122
- transition to: :rejected, from: [:accepted, :pending, :manual_intervention_required]
123
- end
124
-
125
- # bypasses eligibility checks
126
- event :require_manual_intervention do
127
- transition to: :manual_intervention_required, from: [:accepted, :pending, :manual_intervention_required]
128
- end
129
-
130
- after_transition any => any, do: :persist_acceptance_status_errors
131
- end
132
93
 
133
94
  attr_accessor :skip_customer_return_processing
134
95
 
@@ -214,7 +175,7 @@ module Spree
214
175
  event_paths.delete(:expired)
215
176
  event_paths.delete(:unexchange)
216
177
 
217
- status_paths.map{ |s| I18n.t("spree.reception_states.#{s}", default: s.to_s.humanize) }.zip(event_paths)
178
+ status_paths.map{ |status| I18n.t("spree.reception_states.#{status}", default: status.to_s.humanize) }.zip(event_paths)
218
179
  end
219
180
 
220
181
  def part_of_exchange?
@@ -28,7 +28,7 @@ module Spree
28
28
  private
29
29
 
30
30
  def validators
31
- @validators ||= permitted_eligibility_validators.map{ |v| v.new(@return_item) }
31
+ @validators ||= permitted_eligibility_validators.map{ |validator| validator.new(@return_item) }
32
32
  end
33
33
  end
34
34
  end
@@ -31,7 +31,7 @@ module Spree
31
31
  scope :ready, -> { with_state('ready') }
32
32
  scope :shipped, -> { with_state('shipped') }
33
33
  scope :trackable, -> { where("tracking IS NOT NULL AND tracking != ''") }
34
- scope :with_state, ->(*s) { where(state: s) }
34
+ scope :with_state, ->(*state) { where(state: state) }
35
35
  # sort by most recent shipped_at, falling back to created_at. add "id desc" to make specs that involve this scope more deterministic.
36
36
  scope :reverse_chronological, -> {
37
37
  order(Arel.sql("coalesce(#{Spree::Shipment.table_name}.shipped_at, #{Spree::Shipment.table_name}.created_at) desc"), id: :desc)
@@ -39,41 +39,7 @@ module Spree
39
39
 
40
40
  scope :by_store, ->(store) { joins(:order).merge(Spree::Order.by_store(store)) }
41
41
 
42
- # shipment state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
43
- state_machine initial: :pending, use_transactions: false do
44
- event :ready do
45
- transition from: :pending, to: :shipped, if: :can_transition_from_pending_to_shipped?
46
- transition from: :pending, to: :ready, if: :can_transition_from_pending_to_ready?
47
- end
48
-
49
- event :pend do
50
- transition from: :ready, to: :pending
51
- end
52
-
53
- event :ship do
54
- transition from: [:ready, :canceled], to: :shipped
55
- end
56
- after_transition to: :shipped, do: :after_ship
57
-
58
- event :cancel do
59
- transition to: :canceled, from: [:pending, :ready]
60
- end
61
- after_transition to: :canceled, do: :after_cancel
62
-
63
- event :resume do
64
- transition from: :canceled, to: :ready, if: :can_transition_from_canceled_to_ready?
65
- transition from: :canceled, to: :pending
66
- end
67
- after_transition from: :canceled, to: [:pending, :ready, :shipped], do: :after_resume
68
-
69
- after_transition do |shipment, transition|
70
- shipment.state_changes.create!(
71
- previous_state: transition.from,
72
- next_state: transition.to,
73
- name: 'shipment'
74
- )
75
- end
76
- end
42
+ include ::Spree::Config.state_machines.shipment
77
43
 
78
44
  self.whitelisted_ransackable_associations = ['order']
79
45
  self.whitelisted_ransackable_attributes = ['number']
@@ -142,7 +108,7 @@ module Spree
142
108
  # @return [BigDecimal] the amount of this item, taking into consideration
143
109
  # all non-tax adjustments.
144
110
  def total_before_tax
145
- amount + adjustments.select { |a| !a.tax? && a.eligible? }.sum(&:amount)
111
+ amount + adjustments.select { |adjustment| !adjustment.tax? && adjustment.eligible? }.sum(&:amount)
146
112
  end
147
113
 
148
114
  # @return [BigDecimal] the amount of this shipment before VAT tax
@@ -219,7 +185,7 @@ module Spree
219
185
  def select_shipping_method(shipping_method)
220
186
  estimator = Spree::Config.stock.estimator_class.new
221
187
  rates = estimator.shipping_rates(to_package, false)
222
- rate = rates.detect { |r| r.shipping_method_id == shipping_method.id }
188
+ rate = rates.detect { |detected| detected.shipping_method_id == shipping_method.id }
223
189
  rate.selected = true
224
190
  self.shipping_rates = [rate]
225
191
  end