solidus_core 4.3.5 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +2 -2
  3. data/app/mailers/spree/base_mailer.rb +1 -1
  4. data/app/mailers/spree/carton_mailer.rb +1 -1
  5. data/app/mailers/spree/order_mailer.rb +3 -3
  6. data/app/mailers/spree/reimbursement_mailer.rb +1 -1
  7. data/app/models/concerns/spree/active_storage_adapter/normalization.rb +1 -1
  8. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  9. data/app/models/concerns/spree/display_money.rb +1 -1
  10. data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
  11. data/app/models/concerns/spree/user_address_book.rb +4 -4
  12. data/app/models/concerns/spree/user_methods.rb +3 -3
  13. data/app/models/spree/address.rb +6 -6
  14. data/app/models/spree/adjustment.rb +13 -66
  15. data/app/models/spree/calculator/returns/default_refund_amount.rb +1 -1
  16. data/app/models/spree/carton.rb +2 -2
  17. data/app/models/spree/credit_card.rb +6 -6
  18. data/app/models/spree/deprecated_configurable_class.rb +40 -0
  19. data/app/models/spree/fulfilment_changer.rb +4 -4
  20. data/app/models/spree/inventory_unit.rb +2 -2
  21. data/app/models/spree/line_item.rb +1 -4
  22. data/app/models/spree/null_promotion_adjuster.rb +13 -0
  23. data/app/models/spree/null_promotion_advertiser.rb +9 -0
  24. data/app/models/spree/null_promotion_finder.rb +9 -0
  25. data/app/models/spree/null_promotion_handler.rb +44 -0
  26. data/app/models/spree/order.rb +15 -22
  27. data/app/models/spree/order_cancellations.rb +8 -8
  28. data/app/models/spree/order_mutex.rb +2 -2
  29. data/app/models/spree/order_shipping.rb +9 -9
  30. data/app/models/spree/order_updater.rb +6 -10
  31. data/app/models/spree/payment/processing.rb +2 -2
  32. data/app/models/spree/payment.rb +2 -2
  33. data/app/models/spree/payment_create.rb +1 -1
  34. data/app/models/spree/payment_method/store_credit.rb +1 -1
  35. data/app/models/spree/payment_source.rb +5 -1
  36. data/app/models/spree/permission_set.rb +11 -0
  37. data/app/models/spree/product.rb +7 -28
  38. data/app/models/spree/refund.rb +1 -1
  39. data/app/models/spree/reimbursement.rb +4 -4
  40. data/app/models/spree/reimbursement_performer.rb +3 -3
  41. data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
  42. data/app/models/spree/reimbursement_type/credit.rb +1 -1
  43. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
  44. data/app/models/spree/reimbursement_type/store_credit.rb +1 -1
  45. data/app/models/spree/return_item.rb +9 -9
  46. data/app/models/spree/role.rb +3 -1
  47. data/app/models/spree/role_permission.rb +8 -0
  48. data/app/models/spree/shipment.rb +7 -7
  49. data/app/models/spree/shipping_category.rb +2 -0
  50. data/app/models/spree/shipping_rate.rb +1 -1
  51. data/app/models/spree/{order_contents.rb → simple_order_contents.rb} +4 -11
  52. data/app/models/spree/stock/estimator.rb +1 -1
  53. data/app/models/spree/stock/inventory_unit_builder.rb +1 -1
  54. data/app/models/spree/stock/package.rb +2 -2
  55. data/app/models/spree/stock/simple_coordinator.rb +1 -1
  56. data/app/models/spree/stock_location.rb +5 -5
  57. data/app/models/spree/store.rb +1 -1
  58. data/app/models/spree/store_credit.rb +15 -15
  59. data/app/models/spree/store_credit_event.rb +3 -3
  60. data/app/models/spree/tax_calculator/default.rb +2 -2
  61. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -1
  62. data/app/models/spree/tax_category.rb +3 -1
  63. data/app/models/spree/tax_rate.rb +3 -3
  64. data/app/models/spree/taxonomy.rb +2 -2
  65. data/app/models/spree/unit_cancel.rb +1 -2
  66. data/app/models/spree/variant/vat_price_generator.rb +1 -1
  67. data/app/models/spree/variant.rb +7 -2
  68. data/app/models/spree/wallet.rb +2 -2
  69. data/app/views/spree/order_mailer/cancel_email.html.erb +1 -1
  70. data/app/views/spree/order_mailer/cancel_email.text.erb +1 -1
  71. data/app/views/spree/order_mailer/confirm_email.html.erb +5 -5
  72. data/app/views/spree/order_mailer/confirm_email.text.erb +5 -5
  73. data/config/locales/en.yml +4 -90
  74. data/db/default/spree/permission_sets.rb +10 -0
  75. data/db/default/spree/return_reasons.rb +3 -1
  76. data/db/default/spree/states.rb +1 -1
  77. data/db/migrate/20160101010000_solidus_one_four.rb +0 -127
  78. data/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb +9 -0
  79. data/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb +9 -0
  80. data/db/migrate/20240821173641_add_description_to_spree_roles.rb +5 -0
  81. data/db/migrate/20240904152041_add_privilege_and_category_to_spree_permission_sets.rb +6 -0
  82. data/db/seeds.rb +1 -0
  83. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
  84. data/lib/generators/solidus/update/update_generator.rb +1 -1
  85. data/lib/generators/spree/dummy/templates/rails/test.rb +6 -1
  86. data/lib/spree/app_configuration.rb +53 -84
  87. data/lib/spree/core/class_constantizer.rb +2 -2
  88. data/lib/spree/core/controller_helpers/payment_parameters.rb +1 -1
  89. data/lib/spree/core/engine.rb +1 -0
  90. data/lib/spree/core/environment/calculators.rb +35 -3
  91. data/lib/spree/core/environment/promotions.rb +25 -4
  92. data/lib/spree/core/environment_extension.rb +16 -2
  93. data/lib/spree/core/importer/order.rb +5 -5
  94. data/lib/spree/core/importer/product.rb +3 -3
  95. data/lib/spree/core/nested_class_set.rb +28 -0
  96. data/lib/spree/core/null_promotion_configuration.rb +84 -0
  97. data/lib/spree/core/product_filters.rb +1 -1
  98. data/lib/spree/core/search/variant.rb +2 -2
  99. data/lib/spree/core/state_machines/order.rb +0 -1
  100. data/lib/spree/core/validators/email.rb +1 -1
  101. data/lib/spree/core/version.rb +2 -2
  102. data/lib/spree/core.rb +2 -6
  103. data/lib/spree/deprecator.rb +9 -0
  104. data/lib/spree/i18n.rb +1 -1
  105. data/lib/spree/mailer_previews/carton_preview.rb +1 -1
  106. data/lib/spree/permission_sets/base.rb +13 -1
  107. data/lib/spree/permission_sets/configuration_display.rb +10 -0
  108. data/lib/spree/permission_sets/configuration_management.rb +10 -0
  109. data/lib/spree/permission_sets/dashboard_display.rb +12 -0
  110. data/lib/spree/permission_sets/default_customer.rb +11 -1
  111. data/lib/spree/permission_sets/order_display.rb +10 -0
  112. data/lib/spree/permission_sets/order_management.rb +10 -0
  113. data/lib/spree/permission_sets/product_display.rb +10 -0
  114. data/lib/spree/permission_sets/product_management.rb +10 -0
  115. data/lib/spree/permission_sets/restricted_stock_display.rb +10 -0
  116. data/lib/spree/permission_sets/restricted_stock_management.rb +10 -0
  117. data/lib/spree/permission_sets/stock_display.rb +10 -0
  118. data/lib/spree/permission_sets/stock_management.rb +10 -0
  119. data/lib/spree/permission_sets/super_user.rb +10 -0
  120. data/lib/spree/permission_sets/user_display.rb +10 -0
  121. data/lib/spree/permission_sets/user_management.rb +10 -0
  122. data/lib/spree/permission_sets.rb +0 -2
  123. data/lib/spree/permitted_attributes.rb +2 -2
  124. data/lib/spree/preferences/store.rb +2 -2
  125. data/lib/spree/testing_support/capybara_ext.rb +1 -1
  126. data/lib/spree/testing_support/dummy_ability.rb +7 -0
  127. data/lib/spree/testing_support/dummy_app/database.yml +2 -2
  128. data/lib/spree/testing_support/dummy_app/migrations.rb +8 -15
  129. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +2 -2
  130. data/lib/spree/testing_support/dummy_app.rb +17 -12
  131. data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -2
  132. data/lib/spree/testing_support/factories/calculator_factory.rb +1 -5
  133. data/lib/spree/testing_support/factories/carton_factory.rb +2 -2
  134. data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
  135. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +3 -3
  136. data/lib/spree/testing_support/factories/order_factory.rb +5 -24
  137. data/lib/spree/testing_support/factories/product_factory.rb +1 -1
  138. data/lib/spree/testing_support/factories/shipment_factory.rb +1 -1
  139. data/lib/spree/testing_support/factories/stock_item_factory.rb +5 -1
  140. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  141. data/lib/spree/testing_support/factories/user_factory.rb +1 -1
  142. data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
  143. data/lib/spree/testing_support/order_walkthrough.rb +3 -3
  144. data/lib/spree/testing_support/shared_examples/calculator.rb +10 -0
  145. data/lib/spree/testing_support/shared_examples/order_factory.rb +141 -0
  146. data/lib/spree/testing_support/shared_examples/working_factory.rb +15 -0
  147. data/lib/tasks/colorado_delivery_fee.rake +2 -2
  148. data/solidus_core.gemspec +7 -7
  149. metadata +60 -93
  150. data/app/jobs/spree/promotion_code_batch_job.rb +0 -26
  151. data/app/mailers/spree/promotion_code_batch_mailer.rb +0 -15
  152. data/app/models/spree/calculator/distributed_amount.rb +0 -33
  153. data/app/models/spree/calculator/flat_percent_item_total.rb +0 -23
  154. data/app/models/spree/calculator/flexi_rate.rb +0 -22
  155. data/app/models/spree/calculator/percent_on_line_item.rb +0 -13
  156. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -52
  157. data/app/models/spree/calculator/tiered_percent.rb +0 -62
  158. data/app/models/spree/line_item_action.rb +0 -8
  159. data/app/models/spree/order_promotion.rb +0 -27
  160. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -81
  161. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -98
  162. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -139
  163. data/app/models/spree/promotion/actions/free_shipping.rb +0 -59
  164. data/app/models/spree/promotion/order_adjustments_recalculator.rb +0 -92
  165. data/app/models/spree/promotion/rules/first_order.rb +0 -38
  166. data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +0 -36
  167. data/app/models/spree/promotion/rules/item_total.rb +0 -86
  168. data/app/models/spree/promotion/rules/minimum_quantity.rb +0 -59
  169. data/app/models/spree/promotion/rules/nth_order.rb +0 -45
  170. data/app/models/spree/promotion/rules/one_use_per_user.rb +0 -25
  171. data/app/models/spree/promotion/rules/option_value.rb +0 -50
  172. data/app/models/spree/promotion/rules/product.rb +0 -86
  173. data/app/models/spree/promotion/rules/store.rb +0 -26
  174. data/app/models/spree/promotion/rules/taxon.rb +0 -91
  175. data/app/models/spree/promotion/rules/user.rb +0 -34
  176. data/app/models/spree/promotion/rules/user_logged_in.rb +0 -20
  177. data/app/models/spree/promotion/rules/user_role.rb +0 -45
  178. data/app/models/spree/promotion.rb +0 -271
  179. data/app/models/spree/promotion_action.rb +0 -47
  180. data/app/models/spree/promotion_category.rb +0 -8
  181. data/app/models/spree/promotion_chooser.rb +0 -34
  182. data/app/models/spree/promotion_code/batch_builder.rb +0 -64
  183. data/app/models/spree/promotion_code.rb +0 -54
  184. data/app/models/spree/promotion_code_batch.rb +0 -27
  185. data/app/models/spree/promotion_handler/cart.rb +0 -75
  186. data/app/models/spree/promotion_handler/coupon.rb +0 -123
  187. data/app/models/spree/promotion_handler/page.rb +0 -26
  188. data/app/models/spree/promotion_handler/shipping.rb +0 -61
  189. data/app/models/spree/promotion_rule.rb +0 -55
  190. data/app/models/spree/promotion_rule_store.rb +0 -10
  191. data/app/models/spree/promotion_rule_taxon.rb +0 -8
  192. data/app/models/spree/promotion_rule_user.rb +0 -10
  193. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +0 -2
  194. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +0 -2
  195. data/bin/rails +0 -13
  196. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +0 -38
  197. data/db/migrate/20180202190713_create_promotion_rule_stores.rb +0 -12
  198. data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +0 -11
  199. data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +0 -42
  200. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +0 -20
  201. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +0 -5
  202. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +0 -6
  203. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +0 -13
  204. data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +0 -10
  205. data/db/migrate/20231031175215_add_promotion_order_promotion_foreign_key.rb +0 -10
  206. data/lib/solidus/migrations/promotions_with_code_handlers.rb +0 -66
  207. data/lib/spree/permission_sets/promotion_display.rb +0 -25
  208. data/lib/spree/permission_sets/promotion_management.rb +0 -25
  209. data/lib/spree/ransack_4_1_patch.rb +0 -16
  210. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  211. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -7
  212. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  213. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -98
@@ -4,8 +4,10 @@ module Spree
4
4
  class Role < Spree::Base
5
5
  has_many :role_users, class_name: "Spree::RoleUser", dependent: :destroy
6
6
  has_many :users, through: :role_users
7
+ has_many :role_permissions, dependent: :destroy
8
+ has_many :permission_sets, through: :role_permissions
7
9
 
8
- validates_uniqueness_of :name, case_sensitive: true
10
+ validates :name, presence: true, uniqueness: { case_sensitive: true, allow_blank: true }
9
11
 
10
12
  def admin?
11
13
  name == "admin"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class RolePermission < Spree::Base
5
+ belongs_to :role
6
+ belongs_to :permission_set
7
+ end
8
+ 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, ->(*state) { where(state: state) }
34
+ scope :with_state, ->(*state) { where(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)
@@ -92,7 +92,7 @@ module Spree
92
92
  # @return [BigDecimal] the amount of this item, taking into consideration
93
93
  # all non-tax adjustments.
94
94
  def total_before_tax
95
- amount + adjustments.select { |adjustment| !adjustment.tax? && adjustment.eligible? }.sum(&:amount)
95
+ amount + adjustments.reject(&:tax?).sum(&:amount)
96
96
  end
97
97
 
98
98
  # @return [BigDecimal] the amount of this shipment before VAT tax
@@ -175,7 +175,7 @@ module Spree
175
175
  end
176
176
 
177
177
  def manifest
178
- @manifest ||= Spree::ShippingManifest.new(inventory_units: inventory_units).items
178
+ @manifest ||= Spree::ShippingManifest.new(inventory_units:).items
179
179
  end
180
180
 
181
181
  def selected_shipping_rate_id
@@ -217,7 +217,7 @@ module Spree
217
217
 
218
218
  def set_up_inventory(state, variant, _order, line_item)
219
219
  inventory_units.create(
220
- state: state,
220
+ state:,
221
221
  variant_id: variant.id,
222
222
  line_item_id: line_item.id
223
223
  )
@@ -263,7 +263,7 @@ module Spree
263
263
  self.cost = selected_shipping_rate.cost
264
264
  if changed?
265
265
  update_columns(
266
- cost: cost,
266
+ cost:,
267
267
  updated_at: Time.current
268
268
  )
269
269
  end
@@ -312,7 +312,7 @@ module Spree
312
312
  end
313
313
 
314
314
  def after_ship
315
- order.shipping.ship_shipment(self, suppress_mailer: suppress_mailer)
315
+ order.shipping.ship_shipment(self, suppress_mailer:)
316
316
  end
317
317
 
318
318
  def can_get_rates?
@@ -339,7 +339,7 @@ module Spree
339
339
 
340
340
  def ensure_can_destroy
341
341
  if shipped? || canceled?
342
- errors.add(:state, :cannot_destroy, state: state)
342
+ errors.add(:state, :cannot_destroy, state:)
343
343
  throw :abort
344
344
  end
345
345
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class ShippingCategory < Spree::Base
5
+ self.allowed_ransackable_attributes = %w[name]
6
+
5
7
  validates :name, presence: true
6
8
  has_many :products, inverse_of: :shipping_category
7
9
  has_many :shipping_method_categories, inverse_of: :shipping_category
@@ -31,7 +31,7 @@ module Spree
31
31
  tax_explanations = taxes.map(&:label).join(tax_label_separator)
32
32
 
33
33
  I18n.t 'spree.shipping_rate.display_price.display_price_with_explanations',
34
- price: price,
34
+ price:,
35
35
  explanations: tax_explanations
36
36
  end
37
37
  alias_method :display_cost, :display_price
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- class OrderContents
4
+ class SimpleOrderContents
5
5
  attr_accessor :order
6
6
 
7
7
  def initialize(order)
@@ -38,12 +38,7 @@ module Spree
38
38
  if order.update(params)
39
39
  unless order.completed?
40
40
  order.line_items = order.line_items.select { |li| li.quantity > 0 }
41
- # Update totals, then check if the order is eligible for any cart promotions.
42
- # If we do not update first, then the item total will be wrong and ItemTotal
43
- # promotion rules would not be triggered.
44
- reload_totals
45
41
  order.check_shipments_and_restart_checkout
46
- PromotionHandler::Cart.new(order).activate
47
42
  end
48
43
  reload_totals
49
44
  true
@@ -71,10 +66,8 @@ module Spree
71
66
  private
72
67
 
73
68
  def after_add_or_remove(line_item, options = {})
74
- reload_totals
75
69
  shipment = options[:shipment]
76
70
  shipment.present? ? shipment.update_amounts : order.check_shipments_and_restart_checkout
77
- PromotionHandler::Cart.new(order, line_item).activate
78
71
  reload_totals
79
72
  line_item
80
73
  end
@@ -88,8 +81,8 @@ module Spree
88
81
 
89
82
  line_item ||= order.line_items.new(
90
83
  quantity: 0,
91
- variant: variant,
92
- adjustments: [],
84
+ variant:,
85
+ adjustments: []
93
86
  )
94
87
 
95
88
  line_item.quantity += quantity.to_i
@@ -117,7 +110,7 @@ module Spree
117
110
  def grab_line_item_by_variant(variant, raise_error = false, options = {})
118
111
  line_item = order.find_line_item_by_variant(variant, options)
119
112
 
120
- if !line_item.present? && raise_error
113
+ if line_item.blank? && raise_error
121
114
  raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
122
115
  end
123
116
 
@@ -39,7 +39,7 @@ module Spree
39
39
  cost = shipping_method.calculator.compute(package)
40
40
  if cost
41
41
  rate = shipping_method.shipping_rates.new(
42
- cost: cost,
42
+ cost:,
43
43
  shipment: package.shipment
44
44
  )
45
45
  tax_calculator.calculate(rate).each do |tax|
@@ -25,7 +25,7 @@ module Spree
25
25
  Spree::InventoryUnit.new(
26
26
  pending: true,
27
27
  variant: line_item.variant,
28
- line_item: line_item
28
+ line_item:
29
29
  )
30
30
  end
31
31
  end
@@ -124,8 +124,8 @@ module Spree
124
124
  contents.each { |content_item| content_item.inventory_unit.state = content_item.state.to_s }
125
125
 
126
126
  Spree::Shipment.new(
127
- order: order,
128
- stock_location: stock_location,
127
+ order:,
128
+ stock_location:,
129
129
  inventory_units: contents.map(&:inventory_unit)
130
130
  )
131
131
  end
@@ -41,7 +41,7 @@ module Spree
41
41
  @desired = Spree::StockQuantities.new(inventory_units_by_variant.transform_values(&:count))
42
42
  @availability = Spree::Stock::Availability.new(
43
43
  variants: desired.variants,
44
- stock_locations: stock_locations
44
+ stock_locations:
45
45
  )
46
46
 
47
47
  @allocator = Spree::Config.stock.allocator_class.new(availability)
@@ -39,7 +39,7 @@ module Spree
39
39
 
40
40
  # Wrapper for creating a new stock item respecting the backorderable config
41
41
  def propagate_variant(variant)
42
- stock_items.create!(variant: variant, backorderable: backorderable_default)
42
+ stock_items.create!(variant:, backorderable: backorderable_default)
43
43
  end
44
44
 
45
45
  # Return either an existing stock item or create a new one. Useful in
@@ -55,7 +55,7 @@ module Spree
55
55
  #
56
56
  # @return [StockItem] Corresponding StockItem for the StockLocation's variant.
57
57
  def stock_item(variant_id)
58
- stock_items.where(variant_id: variant_id).order(:id).first
58
+ stock_items.where(variant_id:).order(:id).first
59
59
  end
60
60
 
61
61
  # Attempts to look up StockItem for the variant, and creates one if not found.
@@ -101,8 +101,8 @@ module Spree
101
101
  if quantity < 1 && !stock_item(variant)
102
102
  raise InvalidMovementError.new(I18n.t('spree.negative_movement_absent_item'))
103
103
  end
104
- stock_item_or_create(variant).stock_movements.create!(quantity: quantity,
105
- originator: originator)
104
+ stock_item_or_create(variant).stock_movements.create!(quantity:,
105
+ originator:)
106
106
  end
107
107
 
108
108
  def fill_status(variant, quantity)
@@ -121,7 +121,7 @@ module Spree
121
121
 
122
122
  def ensure_one_default
123
123
  if default
124
- Spree::StockLocation.where(default: true).where.not(id: id).find_each do |stock_location|
124
+ Spree::StockLocation.where(default: true).where.not(id:).find_each do |stock_location|
125
125
  stock_location.default = false
126
126
  stock_location.save!
127
127
  end
@@ -58,7 +58,7 @@ module Spree
58
58
 
59
59
  def ensure_default_exists_and_is_unique
60
60
  if default
61
- Spree::Store.where.not(id: id).update_all(default: false)
61
+ Spree::Store.where.not(id:).update_all(default: false)
62
62
  elsif Spree::Store.where(default: true).count == 0
63
63
  self.default = true
64
64
  end
@@ -58,7 +58,7 @@ class Spree::StoreCredit < Spree::PaymentSource
58
58
  def authorize(amount, order_currency, options = {})
59
59
  authorization_code = options[:action_authorization_code]
60
60
  if authorization_code
61
- if store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
61
+ if store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:)
62
62
  # Don't authorize again on capture
63
63
  return true
64
64
  end
@@ -92,7 +92,7 @@ class Spree::StoreCredit < Spree::PaymentSource
92
92
 
93
93
  def capture(amount, authorization_code, order_currency, options = {})
94
94
  return false unless authorize(amount, order_currency, action_authorization_code: authorization_code)
95
- auth_event = store_credit_events.find_by!(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
95
+ auth_event = store_credit_events.find_by!(action: AUTHORIZE_ACTION, authorization_code:)
96
96
 
97
97
  if amount <= auth_event.amount
98
98
  if currency != order_currency
@@ -117,7 +117,7 @@ class Spree::StoreCredit < Spree::PaymentSource
117
117
  end
118
118
 
119
119
  def void(authorization_code, options = {})
120
- if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
120
+ if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:)
121
121
  update!({
122
122
  action: VOID_ACTION,
123
123
  action_amount: auth_event.amount,
@@ -135,7 +135,7 @@ class Spree::StoreCredit < Spree::PaymentSource
135
135
 
136
136
  def credit(amount, authorization_code, order_currency, options = {})
137
137
  # Find the amount related to this authorization_code in order to add the store credit back
138
- capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code: authorization_code)
138
+ capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code:)
139
139
 
140
140
  if currency != order_currency # sanity check to make sure the order currency hasn't changed since the auth
141
141
  errors.add(:base, I18n.t('spree.store_credit.currency_mismatch'))
@@ -221,25 +221,25 @@ class Spree::StoreCredit < Spree::PaymentSource
221
221
 
222
222
  def create_credit_record_params(amount)
223
223
  {
224
- amount: amount,
225
- user_id: user_id,
226
- category_id: category_id,
227
- created_by_id: created_by_id,
228
- currency: currency,
229
- type_id: type_id,
224
+ amount:,
225
+ user_id:,
226
+ category_id:,
227
+ created_by_id:,
228
+ currency:,
229
+ type_id:,
230
230
  memo: credit_allocation_memo
231
231
  }
232
232
  end
233
233
 
234
234
  def credit_allocation_memo
235
- I18n.t("spree.store_credit.credit_allocation_memo", id: id)
235
+ I18n.t("spree.store_credit.credit_allocation_memo", id:)
236
236
  end
237
237
 
238
238
  def store_event
239
239
  return unless saved_change_to_amount? || saved_change_to_amount_used? || saved_change_to_amount_authorized? || [ELIGIBLE_ACTION, INVALIDATE_ACTION].include?(action)
240
240
 
241
241
  event = if action
242
- store_credit_events.build(action: action)
242
+ store_credit_events.build(action:)
243
243
  else
244
244
  store_credit_events.where(action: ALLOCATION_ACTION).first_or_initialize
245
245
  end
@@ -247,10 +247,10 @@ class Spree::StoreCredit < Spree::PaymentSource
247
247
  event.update!({
248
248
  amount: action_amount || amount,
249
249
  authorization_code: action_authorization_code || event.authorization_code || generate_authorization_code,
250
- amount_remaining: amount_remaining,
251
- user_total_amount: user.available_store_credit_total(currency: currency),
250
+ amount_remaining:,
251
+ user_total_amount: user.available_store_credit_total(currency:),
252
252
  originator: action_originator,
253
- store_credit_reason: store_credit_reason
253
+ store_credit_reason:
254
254
  })
255
255
  end
256
256
 
@@ -33,15 +33,15 @@ module Spree
33
33
  end
34
34
 
35
35
  def display_amount
36
- Spree::Money.new(amount, { currency: currency })
36
+ Spree::Money.new(amount, { currency: })
37
37
  end
38
38
 
39
39
  def display_user_total_amount
40
- Spree::Money.new(user_total_amount, { currency: currency })
40
+ Spree::Money.new(user_total_amount, { currency: })
41
41
  end
42
42
 
43
43
  def display_remaining_amount
44
- Spree::Money.new(amount_remaining, { currency: currency })
44
+ Spree::Money.new(amount_remaining, { currency: })
45
45
  end
46
46
 
47
47
  def display_event_date
@@ -46,7 +46,7 @@ module Spree
46
46
  Spree::Tax::ItemTax.new(
47
47
  label: rate.adjustment_label(amount),
48
48
  tax_rate: rate,
49
- amount: amount,
49
+ amount:,
50
50
  included_in_price: rate.included_in_price
51
51
  )
52
52
  end
@@ -89,7 +89,7 @@ module Spree
89
89
  item_id: item.id,
90
90
  label: rate.adjustment_label(amount),
91
91
  tax_rate: rate,
92
- amount: amount,
92
+ amount:,
93
93
  included_in_price: rate.included_in_price
94
94
  )
95
95
  end
@@ -35,7 +35,7 @@ module Spree
35
35
  item_id: shipping_rate.id,
36
36
  label: rate.adjustment_label(amount),
37
37
  tax_rate: rate,
38
- amount: amount
38
+ amount:
39
39
  )
40
40
  end
41
41
  end
@@ -4,6 +4,8 @@ module Spree
4
4
  class TaxCategory < Spree::Base
5
5
  include Spree::SoftDeletable
6
6
 
7
+ self.allowed_ransackable_attributes = %w[name description]
8
+
7
9
  after_discard do
8
10
  self.tax_rate_tax_categories = []
9
11
  end
@@ -28,7 +30,7 @@ module Spree
28
30
 
29
31
  def ensure_one_default
30
32
  if is_default
31
- Spree::TaxCategory.where(is_default: true).where.not(id: id).update_all(is_default: false, updated_at: Time.current)
33
+ Spree::TaxCategory.where(is_default: true).where.not(id:).update_all(is_default: false, updated_at: Time.current)
32
34
  end
33
35
  end
34
36
  end
@@ -11,10 +11,10 @@ module Spree
11
11
  include Spree::CalculatedAdjustments
12
12
  include Spree::AdjustmentSource
13
13
 
14
- enum level: {
14
+ enum :level, {
15
15
  item: 0,
16
16
  order: 1
17
- }, _suffix: true
17
+ }, suffix: true
18
18
 
19
19
  belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates, optional: true
20
20
 
@@ -37,7 +37,7 @@ module Spree
37
37
  # Finds all tax rates whose zones match a given address
38
38
  scope :for_address, ->(address) { joins(:zone).merge(Spree::Zone.for_address(address)) }
39
39
  scope :for_country,
40
- ->(country) { for_address(Spree::Tax::TaxLocation.new(country: country)) }
40
+ ->(country) { for_address(Spree::Tax::TaxLocation.new(country:)) }
41
41
  scope :active, -> do
42
42
  table = arel_table
43
43
  time = Time.current
@@ -21,11 +21,11 @@ module Spree
21
21
  def set_name
22
22
  if root
23
23
  root.update_columns(
24
- name: name,
24
+ name:,
25
25
  updated_at: Time.current
26
26
  )
27
27
  else
28
- self.root = Spree::Taxon.create!(taxonomy_id: id, name: name)
28
+ self.root = Spree::Taxon.create!(taxonomy_id: id, name:)
29
29
  end
30
30
  end
31
31
  end
@@ -20,10 +20,9 @@ class Spree::UnitCancel < Spree::Base
20
20
 
21
21
  self.adjustment = inventory_unit.line_item.adjustments.create!(
22
22
  source: self,
23
- amount: amount,
23
+ amount:,
24
24
  order: inventory_unit.order,
25
25
  label: "#{I18n.t('spree.cancellation')} - #{reason}",
26
- eligible: true,
27
26
  finalized: true
28
27
  )
29
28
 
@@ -41,7 +41,7 @@ module Spree
41
41
  def find_or_initialize_price_by(country_iso, currency)
42
42
  variant.prices.detect do |price|
43
43
  price.country_iso == country_iso && price.currency == currency
44
- end || variant.prices.build(country_iso: country_iso, currency: currency)
44
+ end || variant.prices.build(country_iso:, currency:)
45
45
  end
46
46
 
47
47
  # nil is added to the array so we always have an export price.
@@ -80,6 +80,11 @@ module Spree
80
80
 
81
81
  after_destroy :destroy_option_values_variants
82
82
 
83
+ scope :template_variants, -> do
84
+ left_joins(product: { option_types: :option_values }).where(is_master: true).where.not(spree_option_values: { id: nil }).reorder(nil).distinct
85
+ end
86
+ scope :non_template_variants, -> { where.not(id: template_variants) }
87
+
83
88
  # Returns variants that are in stock. When stock locations are provided as
84
89
  # a parameter, the scope is limited to variants that are in stock in the
85
90
  # provided stock locations.
@@ -94,7 +99,7 @@ module Spree
94
99
  if stock_locations.present?
95
100
  in_stock_variants = in_stock_variants.where(spree_stock_items: { stock_location_id: stock_locations.map(&:id) })
96
101
  end
97
- in_stock_variants
102
+ in_stock_variants.distinct
98
103
  end
99
104
 
100
105
  # Returns a scope of Variants which are suppliable. This includes:
@@ -194,7 +199,7 @@ module Spree
194
199
  #
195
200
  # @return [String] a sentence-ified string of option values.
196
201
  def options_text
197
- values = option_values.includes(:option_type).sort_by do |option_value|
202
+ values = option_values.sort_by do |option_value|
198
203
  option_value.option_type.position
199
204
  end
200
205
 
@@ -28,7 +28,7 @@ class Spree::Wallet
28
28
  # @param payment_source [PaymentSource] The payment source to add to the wallet
29
29
  # @return [WalletPaymentSource] the generated WalletPaymentSource
30
30
  def add(payment_source)
31
- user.wallet_payment_sources.find_or_create_by!(payment_source: payment_source)
31
+ user.wallet_payment_sources.find_or_create_by!(payment_source:)
32
32
  end
33
33
 
34
34
  # Remove a PaymentSource from the wallet.
@@ -37,7 +37,7 @@ class Spree::Wallet
37
37
  # @raise [ActiveRecord::RecordNotFound] if the source is not in the wallet.
38
38
  # @return [WalletPaymentSource] the destroyed WalletPaymentSource
39
39
  def remove(payment_source)
40
- user.wallet_payment_sources.find_by!(payment_source: payment_source).destroy!
40
+ user.wallet_payment_sources.find_by!(payment_source:).destroy!
41
41
  end
42
42
 
43
43
  # Find a WalletPaymentSource in the wallet by id.
@@ -26,7 +26,7 @@
26
26
  <td><%= t('.subtotal') %></td>
27
27
  <td><%= @order.display_item_total %></td>
28
28
  </tr>
29
- <% @order.adjustments.eligible.each do |adjustment| %>
29
+ <% @order.adjustments.each do |adjustment| %>
30
30
  <tr>
31
31
  <td></td>
32
32
  <td><%= sanitize(adjustment.label) %></td>
@@ -10,7 +10,7 @@
10
10
  <% end %>
11
11
  ============================================================
12
12
  <%= t('.subtotal') %> <%= @order.display_item_total %>
13
- <% @order.adjustments.eligible.each do |adjustment| %>
13
+ <% @order.adjustments.each do |adjustment| %>
14
14
  <%= raw(adjustment.label) %> <%= adjustment.display_amount %>
15
15
  <% end %>
16
16
  <%= t('.total') %> <%= @order.display_total %>
@@ -31,8 +31,8 @@
31
31
  </td>
32
32
  </tr>
33
33
  <% if @order.line_item_adjustments.exists? %>
34
- <% if @order.all_adjustments.promotion.eligible.exists? %>
35
- <% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
34
+ <% if @order.all_adjustments.promotion.exists? %>
35
+ <% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
36
36
  <tr>
37
37
  <td></td>
38
38
  <td><%= t('spree.promotion') %> <%= label %>:</td>
@@ -48,8 +48,8 @@
48
48
  <td><%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %></td>
49
49
  </tr>
50
50
  <% end %>
51
- <% if @order.all_adjustments.eligible.tax.exists? %>
52
- <% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %>
51
+ <% if @order.all_adjustments.tax.exists? %>
52
+ <% @order.all_adjustments.tax.group_by(&:label).each do |label, adjustments| %>
53
53
  <tr>
54
54
  <td></td>
55
55
  <td><%= t('spree.tax') %> <%= label %>:</td>
@@ -57,7 +57,7 @@
57
57
  </tr>
58
58
  <% end %>
59
59
  <% end %>
60
- <% @order.adjustments.eligible.each do |adjustment| %>
60
+ <% @order.adjustments.each do |adjustment| %>
61
61
  <% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
62
62
  <tr>
63
63
  <td></td>
@@ -11,8 +11,8 @@
11
11
  ============================================================
12
12
  <%= t('.subtotal') %> <%= @order.display_item_total %>
13
13
  <% if @order.line_item_adjustments.exists? %>
14
- <% if @order.all_adjustments.promotion.eligible.exists? %>
15
- <% @order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
14
+ <% if @order.all_adjustments.promotion.exists? %>
15
+ <% @order.all_adjustments.promotion.group_by(&:label).each do |label, adjustments| %>
16
16
  <%= t('spree.promotion') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
17
17
  <% end %>
18
18
  <% end %>
@@ -22,13 +22,13 @@
22
22
  <%= t('spree.shipping') %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:total_before_tax), currency: @order.currency) %>
23
23
  <% end %>
24
24
 
25
- <% if @order.all_adjustments.eligible.tax.exists? %>
26
- <% @order.all_adjustments.eligible.tax.group_by(&:label).each do |label, adjustments| %>
25
+ <% if @order.all_adjustments.tax.exists? %>
26
+ <% @order.all_adjustments.tax.group_by(&:label).each do |label, adjustments| %>
27
27
  <%= t('spree.tax') %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: @order.currency) %>
28
28
  <% end %>
29
29
  <% end %>
30
30
 
31
- <% @order.adjustments.eligible.each do |adjustment| %>
31
+ <% @order.adjustments.each do |adjustment| %>
32
32
  <% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
33
33
  <%= adjustment.label %> <%= adjustment.display_amount %>
34
34
  <% end %>