solidus_core 2.9.6 → 2.10.0.beta1

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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/spree/user_address_book.rb +2 -2
  3. data/app/models/spree/address.rb +2 -2
  4. data/app/models/spree/adjustment.rb +9 -9
  5. data/app/models/spree/asset.rb +1 -1
  6. data/app/models/spree/base.rb +0 -2
  7. data/app/models/spree/calculator.rb +1 -1
  8. data/app/models/spree/carton.rb +3 -3
  9. data/app/models/spree/classification.rb +2 -2
  10. data/app/models/spree/credit_card.rb +2 -2
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/image/paperclip_attachment.rb +1 -1
  13. data/app/models/spree/inventory_unit.rb +4 -4
  14. data/app/models/spree/line_item.rb +3 -3
  15. data/app/models/spree/line_item_action.rb +2 -2
  16. data/app/models/spree/log_entry.rb +1 -1
  17. data/app/models/spree/option_value.rb +1 -1
  18. data/app/models/spree/option_values_variant.rb +2 -2
  19. data/app/models/spree/order.rb +8 -25
  20. data/app/models/spree/order_cancellations.rb +1 -1
  21. data/app/models/spree/order_contents.rb +2 -2
  22. data/app/models/spree/order_mutex.rb +1 -1
  23. data/app/models/spree/order_promotion.rb +3 -3
  24. data/app/models/spree/order_shipping.rb +1 -1
  25. data/app/models/spree/order_taxation.rb +1 -1
  26. data/app/models/spree/payment/processing.rb +1 -1
  27. data/app/models/spree/payment.rb +4 -4
  28. data/app/models/spree/payment_capture_event.rb +1 -1
  29. data/app/models/spree/payment_method/bogus_credit_card.rb +1 -1
  30. data/app/models/spree/payment_method.rb +3 -0
  31. data/app/models/spree/payment_source.rb +1 -1
  32. data/app/models/spree/price.rb +2 -2
  33. data/app/models/spree/product/scopes.rb +217 -210
  34. data/app/models/spree/product.rb +2 -2
  35. data/app/models/spree/product_option_type.rb +2 -2
  36. data/app/models/spree/product_promotion_rule.rb +2 -2
  37. data/app/models/spree/product_property.rb +2 -2
  38. data/app/models/spree/promotion.rb +1 -1
  39. data/app/models/spree/promotion_action.rb +1 -1
  40. data/app/models/spree/promotion_code.rb +2 -2
  41. data/app/models/spree/promotion_code_batch.rb +1 -1
  42. data/app/models/spree/promotion_rule.rb +1 -1
  43. data/app/models/spree/promotion_rule_role.rb +2 -2
  44. data/app/models/spree/promotion_rule_store.rb +2 -2
  45. data/app/models/spree/promotion_rule_taxon.rb +2 -2
  46. data/app/models/spree/promotion_rule_user.rb +2 -2
  47. data/app/models/spree/refund.rb +3 -3
  48. data/app/models/spree/reimbursement/credit.rb +2 -2
  49. data/app/models/spree/reimbursement.rb +2 -2
  50. data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
  51. data/app/models/spree/return_authorization.rb +3 -3
  52. data/app/models/spree/return_item.rb +10 -10
  53. data/app/models/spree/role_user.rb +2 -2
  54. data/app/models/spree/shipment.rb +3 -3
  55. data/app/models/spree/shipping_manifest.rb +3 -3
  56. data/app/models/spree/shipping_method.rb +1 -1
  57. data/app/models/spree/shipping_method_category.rb +2 -2
  58. data/app/models/spree/shipping_method_stock_location.rb +2 -2
  59. data/app/models/spree/shipping_method_zone.rb +2 -2
  60. data/app/models/spree/shipping_rate.rb +2 -2
  61. data/app/models/spree/shipping_rate_tax.rb +2 -2
  62. data/app/models/spree/state.rb +1 -1
  63. data/app/models/spree/state_change.rb +2 -2
  64. data/app/models/spree/stock_item.rb +2 -2
  65. data/app/models/spree/stock_location.rb +2 -2
  66. data/app/models/spree/stock_movement.rb +2 -2
  67. data/app/models/spree/store_credit.rb +8 -8
  68. data/app/models/spree/store_credit_event.rb +3 -3
  69. data/app/models/spree/store_payment_method.rb +2 -2
  70. data/app/models/spree/store_shipping_method.rb +2 -2
  71. data/app/models/spree/tax_rate.rb +1 -1
  72. data/app/models/spree/tax_rate_tax_category.rb +2 -2
  73. data/app/models/spree/unit_cancel.rb +5 -2
  74. data/app/models/spree/user_address.rb +2 -2
  75. data/app/models/spree/user_stock_location.rb +2 -2
  76. data/app/models/spree/variant/scopes.rb +37 -29
  77. data/app/models/spree/variant.rb +1 -1
  78. data/app/models/spree/variant_property_rule.rb +1 -1
  79. data/app/models/spree/variant_property_rule_condition.rb +2 -2
  80. data/app/models/spree/variant_property_rule_value.rb +2 -2
  81. data/app/models/spree/wallet_payment_source.rb +2 -2
  82. data/app/models/spree/zone_member.rb +2 -2
  83. data/config/initializers/inflections.rb +5 -0
  84. data/config/locales/en.yml +22 -3
  85. data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
  86. data/lib/generators/spree/install/install_generator.rb +0 -3
  87. data/lib/spree/core/controller_helpers/strong_parameters.rb +7 -21
  88. data/lib/spree/core/environment_extension.rb +0 -9
  89. data/lib/spree/core/importer/order.rb +3 -4
  90. data/lib/spree/core/importer/product.rb +2 -2
  91. data/lib/spree/core/version.rb +1 -1
  92. data/lib/spree/permission_sets/default_customer.rb +1 -1
  93. data/lib/spree/permitted_attributes.rb +6 -75
  94. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +6 -2
  95. data/solidus_core.gemspec +4 -4
  96. data/spec/lib/search/base_spec.rb +5 -1
  97. data/spec/lib/search/variant_spec.rb +1 -1
  98. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +1 -8
  99. data/spec/lib/spree/core/environment_extension_spec.rb +1 -12
  100. data/spec/lib/spree/event_spec.rb +15 -3
  101. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +18 -4
  102. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +1 -1
  103. data/spec/models/spree/carton_spec.rb +2 -2
  104. data/spec/models/spree/concerns/user_methods_spec.rb +3 -3
  105. data/spec/models/spree/credit_card_spec.rb +2 -2
  106. data/spec/models/spree/customer_return_spec.rb +1 -1
  107. data/spec/models/spree/order/checkout_spec.rb +1 -1
  108. data/spec/models/spree/order/outstanding_balance_integration_spec.rb +5 -5
  109. data/spec/models/spree/order/payment_spec.rb +1 -1
  110. data/spec/models/spree/order_contents_spec.rb +1 -1
  111. data/spec/models/spree/order_inventory_spec.rb +3 -3
  112. data/spec/models/spree/order_shipping_spec.rb +1 -1
  113. data/spec/models/spree/order_spec.rb +6 -6
  114. data/spec/models/spree/payment_create_spec.rb +2 -2
  115. data/spec/models/spree/payment_spec.rb +12 -12
  116. data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -2
  117. data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -2
  118. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -1
  119. data/spec/models/spree/promotion_spec.rb +0 -4
  120. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +2 -2
  121. data/spec/models/spree/return_item_spec.rb +11 -11
  122. data/spec/models/spree/shipment_spec.rb +6 -6
  123. data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +4 -4
  124. data/spec/models/spree/stock/quantifier_spec.rb +2 -2
  125. data/spec/models/spree/store_credit_spec.rb +7 -7
  126. data/spec/models/spree/tax_category_spec.rb +1 -1
  127. data/spec/models/spree/taxon_spec.rb +2 -2
  128. data/spec/models/spree/unit_cancel_spec.rb +5 -0
  129. data/spec/models/spree/user_spec.rb +3 -3
  130. metadata +32 -32
  131. data/spec/lib/spree/permitted_attributes_spec.rb +0 -41
@@ -4,8 +4,8 @@ module Spree
4
4
  class Reimbursement < Spree::Base
5
5
  class IncompleteReimbursementError < StandardError; end
6
6
 
7
- belongs_to :order, inverse_of: :reimbursements
8
- belongs_to :customer_return, inverse_of: :reimbursements, touch: true
7
+ belongs_to :order, inverse_of: :reimbursements, optional: true
8
+ belongs_to :customer_return, inverse_of: :reimbursements, touch: true, optional: true
9
9
 
10
10
  has_many :refunds, inverse_of: :reimbursement
11
11
  has_many :credits, inverse_of: :reimbursement, class_name: 'Spree::Reimbursement::Credit'
@@ -25,7 +25,7 @@ module Spree
25
25
  additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
26
26
  included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
27
27
 
28
- return_item.update_attributes!({
28
+ return_item.update!({
29
29
  additional_tax_total: additional_tax_total,
30
30
  included_tax_total: included_tax_total
31
31
  })
@@ -4,14 +4,14 @@ module Spree
4
4
  # Models the return of Inventory Units to a Stock Location for an Order.
5
5
  #
6
6
  class ReturnAuthorization < Spree::Base
7
- belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations
7
+ belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations, optional: true
8
8
 
9
9
  has_many :return_items, inverse_of: :return_authorization, dependent: :destroy
10
10
  has_many :inventory_units, through: :return_items, dependent: :nullify
11
11
  has_many :customer_returns, through: :return_items
12
12
 
13
- belongs_to :stock_location
14
- belongs_to :reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id
13
+ belongs_to :stock_location, optional: true
14
+ belongs_to :reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id, optional: true
15
15
 
16
16
  before_create :generate_number
17
17
 
@@ -29,15 +29,15 @@ module Spree
29
29
  class_attribute :refund_amount_calculator
30
30
  self.refund_amount_calculator = Calculator::Returns::DefaultRefundAmount
31
31
 
32
- belongs_to :return_authorization, inverse_of: :return_items
33
- belongs_to :inventory_unit, inverse_of: :return_items
34
- belongs_to :exchange_variant, class_name: 'Spree::Variant'
35
- belongs_to :exchange_inventory_unit, class_name: 'Spree::InventoryUnit', inverse_of: :original_return_item
36
- belongs_to :customer_return, inverse_of: :return_items
37
- belongs_to :reimbursement, inverse_of: :return_items
38
- belongs_to :preferred_reimbursement_type, class_name: 'Spree::ReimbursementType'
39
- belongs_to :override_reimbursement_type, class_name: 'Spree::ReimbursementType'
40
- belongs_to :return_reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id
32
+ belongs_to :return_authorization, inverse_of: :return_items, optional: true
33
+ belongs_to :inventory_unit, inverse_of: :return_items, optional: true
34
+ belongs_to :exchange_variant, class_name: 'Spree::Variant', optional: true
35
+ belongs_to :exchange_inventory_unit, class_name: 'Spree::InventoryUnit', inverse_of: :original_return_item, optional: true
36
+ belongs_to :customer_return, inverse_of: :return_items, optional: true
37
+ belongs_to :reimbursement, inverse_of: :return_items, optional: true
38
+ belongs_to :preferred_reimbursement_type, class_name: 'Spree::ReimbursementType', optional: true
39
+ belongs_to :override_reimbursement_type, class_name: 'Spree::ReimbursementType', optional: true
40
+ belongs_to :return_reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id, optional: true
41
41
 
42
42
  validate :eligible_exchange_variant
43
43
  validate :belongs_to_same_customer_order
@@ -226,7 +226,7 @@ module Spree
226
226
  private
227
227
 
228
228
  def persist_acceptance_status_errors
229
- update_attributes(acceptance_status_errors: validator.errors)
229
+ update(acceptance_status_errors: validator.errors)
230
230
  end
231
231
 
232
232
  def currency
@@ -3,8 +3,8 @@
3
3
  module Spree
4
4
  class RoleUser < Spree::Base
5
5
  self.table_name = "spree_roles_users"
6
- belongs_to :role, class_name: "Spree::Role"
7
- belongs_to :user, class_name: Spree::UserClassHandle.new
6
+ belongs_to :role, class_name: "Spree::Role", optional: true
7
+ belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
8
8
 
9
9
  after_create :auto_generate_spree_api_key
10
10
 
@@ -4,8 +4,8 @@ module Spree
4
4
  # An order's planned shipments including tracking and cost.
5
5
  #
6
6
  class Shipment < Spree::Base
7
- belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments
8
- belongs_to :stock_location, class_name: 'Spree::StockLocation'
7
+ belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments, optional: true
8
+ belongs_to :stock_location, class_name: 'Spree::StockLocation', optional: true
9
9
 
10
10
  has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :delete_all
11
11
  has_many :inventory_units, dependent: :destroy, inverse_of: :shipment
@@ -326,7 +326,7 @@ module Spree
326
326
 
327
327
  # Update Shipment and make sure Order states follow the shipment changes
328
328
  def update_attributes_and_order(params = {})
329
- if update_attributes params
329
+ if update(params)
330
330
  if params.key? :selected_shipping_rate_id
331
331
  # Changing the selected Shipping Rate won't update the cost (for now)
332
332
  # so we persist the Shipment#cost before running `order.recalculate`
@@ -21,9 +21,9 @@ class Spree::ShippingManifest
21
21
  states = {}
22
22
  units.group_by(&:state).each { |state, iu| states[state] = iu.count }
23
23
 
24
- line_item = units.first.line_item
25
- variant = units.first.variant
26
- ManifestItem.new(line_item, variant, units.length, states)
24
+ first_unit = units.first
25
+
26
+ ManifestItem.new(first_unit.line_item, first_unit.variant, units.length, states)
27
27
  end
28
28
  end.flatten
29
29
  end
@@ -28,7 +28,7 @@ module Spree
28
28
  has_many :shipping_method_zones, dependent: :destroy
29
29
  has_many :zones, through: :shipping_method_zones
30
30
 
31
- belongs_to :tax_category, -> { with_deleted }, class_name: 'Spree::TaxCategory'
31
+ belongs_to :tax_category, -> { with_deleted }, class_name: 'Spree::TaxCategory', optional: true
32
32
  has_many :shipping_method_stock_locations, dependent: :destroy, class_name: "Spree::ShippingMethodStockLocation"
33
33
  has_many :stock_locations, through: :shipping_method_stock_locations
34
34
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class ShippingMethodCategory < Spree::Base
5
- belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
6
- belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :shipping_method_categories
5
+ belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', optional: true
6
+ belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :shipping_method_categories, optional: true
7
7
  end
8
8
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Spree::ShippingMethodStockLocation < Spree::Base
4
- belongs_to :shipping_method
5
- belongs_to :stock_location
4
+ belongs_to :shipping_method, optional: true
5
+ belongs_to :stock_location, optional: true
6
6
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class ShippingMethodZone < Spree::Base
5
- belongs_to :zone
6
- belongs_to :shipping_method
5
+ belongs_to :zone, optional: true
6
+ belongs_to :shipping_method, optional: true
7
7
  end
8
8
  end
@@ -5,8 +5,8 @@ module Spree
5
5
  # method has been selected to deliver the shipment.
6
6
  #
7
7
  class ShippingRate < Spree::Base
8
- belongs_to :shipment, class_name: 'Spree::Shipment', touch: true
9
- belongs_to :shipping_method, -> { with_deleted }, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
8
+ belongs_to :shipment, class_name: 'Spree::Shipment', touch: true, optional: true
9
+ belongs_to :shipping_method, -> { with_deleted }, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates, optional: true
10
10
 
11
11
  has_many :taxes,
12
12
  class_name: "Spree::ShippingRateTax",
@@ -7,8 +7,8 @@ module Spree
7
7
  # @since 1.3.0
8
8
  # @see Spree::Tax::ShippingRateTaxer
9
9
  class ShippingRateTax < ActiveRecord::Base
10
- belongs_to :shipping_rate, class_name: "Spree::ShippingRate"
11
- belongs_to :tax_rate, class_name: "Spree::TaxRate"
10
+ belongs_to :shipping_rate, class_name: "Spree::ShippingRate", optional: true
11
+ belongs_to :tax_rate, class_name: "Spree::TaxRate", optional: true
12
12
 
13
13
  extend DisplayMoney
14
14
  money_methods :absolute_amount
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class State < Spree::Base
5
- belongs_to :country, class_name: 'Spree::Country'
5
+ belongs_to :country, class_name: 'Spree::Country', optional: true
6
6
  has_many :addresses, dependent: :nullify
7
7
 
8
8
  validates :country, :name, presence: true
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class StateChange < Spree::Base
5
- belongs_to :user
6
- belongs_to :stateful, polymorphic: true
5
+ belongs_to :user, optional: true
6
+ belongs_to :stateful, polymorphic: true, optional: true
7
7
  before_create :assign_user
8
8
 
9
9
  def <=>(other)
@@ -10,8 +10,8 @@ module Spree
10
10
  include Discard::Model
11
11
  self.discard_column = :deleted_at
12
12
 
13
- belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
14
- belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant', inverse_of: :stock_items
13
+ belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items, optional: true
14
+ belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant', inverse_of: :stock_items, optional: true
15
15
  has_many :stock_movements, inverse_of: :stock_item
16
16
 
17
17
  validates :stock_location, :variant, presence: true
@@ -16,8 +16,8 @@ module Spree
16
16
  has_many :user_stock_locations, dependent: :delete_all
17
17
  has_many :users, through: :user_stock_locations
18
18
 
19
- belongs_to :state, class_name: 'Spree::State'
20
- belongs_to :country, class_name: 'Spree::Country'
19
+ belongs_to :state, class_name: 'Spree::State', optional: true
20
+ belongs_to :country, class_name: 'Spree::Country', optional: true
21
21
 
22
22
  has_many :shipping_method_stock_locations, dependent: :destroy
23
23
  has_many :shipping_methods, through: :shipping_method_stock_locations
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class StockMovement < Spree::Base
5
- belongs_to :stock_item, class_name: 'Spree::StockItem', inverse_of: :stock_movements
6
- belongs_to :originator, polymorphic: true
5
+ belongs_to :stock_item, class_name: 'Spree::StockItem', inverse_of: :stock_movements, optional: true
6
+ belongs_to :originator, polymorphic: true, optional: true
7
7
 
8
8
  after_create :update_stock_item_quantity
9
9
 
@@ -18,10 +18,10 @@ class Spree::StoreCredit < Spree::PaymentSource
18
18
  ADJUSTMENT_ACTION = 'adjustment'
19
19
  INVALIDATE_ACTION = 'invalidate'
20
20
 
21
- belongs_to :user, class_name: Spree::UserClassHandle.new
22
- belongs_to :created_by, class_name: Spree::UserClassHandle.new
23
- belongs_to :category, class_name: "Spree::StoreCreditCategory"
24
- belongs_to :credit_type, class_name: 'Spree::StoreCreditType', foreign_key: 'type_id'
21
+ belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
22
+ belongs_to :created_by, class_name: Spree::UserClassHandle.new, optional: true
23
+ belongs_to :category, class_name: "Spree::StoreCreditCategory", optional: true
24
+ belongs_to :credit_type, class_name: 'Spree::StoreCreditType', foreign_key: 'type_id', optional: true
25
25
  has_many :store_credit_events
26
26
 
27
27
  validates_presence_of :user_id, :category_id, :type_id, :created_by_id, :currency
@@ -63,7 +63,7 @@ class Spree::StoreCredit < Spree::PaymentSource
63
63
  end
64
64
 
65
65
  if validate_authorization(amount, order_currency)
66
- update_attributes!({
66
+ update!({
67
67
  action: AUTHORIZE_ACTION,
68
68
  action_amount: amount,
69
69
  action_originator: options[:action_originator],
@@ -95,7 +95,7 @@ class Spree::StoreCredit < Spree::PaymentSource
95
95
  errors.add(:base, I18n.t('spree.store_credit.currency_mismatch'))
96
96
  false
97
97
  else
98
- update_attributes!({
98
+ update!({
99
99
  action: CAPTURE_ACTION,
100
100
  action_amount: amount,
101
101
  action_originator: options[:action_originator],
@@ -114,7 +114,7 @@ class Spree::StoreCredit < Spree::PaymentSource
114
114
 
115
115
  def void(authorization_code, options = {})
116
116
  if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
117
- update_attributes!({
117
+ update!({
118
118
  action: VOID_ACTION,
119
119
  action_amount: auth_event.amount,
120
120
  action_authorization_code: authorization_code,
@@ -235,7 +235,7 @@ class Spree::StoreCredit < Spree::PaymentSource
235
235
  store_credit_events.where(action: ALLOCATION_ACTION).first_or_initialize
236
236
  end
237
237
 
238
- event.update_attributes!({
238
+ event.update!({
239
239
  amount: action_amount || amount,
240
240
  authorization_code: action_authorization_code || event.authorization_code || generate_authorization_code,
241
241
  amount_remaining: amount_remaining,
@@ -10,9 +10,9 @@ module Spree
10
10
  include Discard::Model
11
11
  self.discard_column = :deleted_at
12
12
 
13
- belongs_to :store_credit
14
- belongs_to :originator, polymorphic: true
15
- belongs_to :store_credit_reason, class_name: 'Spree::StoreCreditReason', inverse_of: :store_credit_events
13
+ belongs_to :store_credit, optional: true
14
+ belongs_to :originator, polymorphic: true, optional: true
15
+ belongs_to :store_credit_reason, class_name: 'Spree::StoreCreditReason', inverse_of: :store_credit_events, optional: true
16
16
 
17
17
  validates_presence_of :store_credit_reason, if: :action_requires_reason?
18
18
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class StorePaymentMethod < Spree::Base
5
- belongs_to :store, inverse_of: :store_payment_methods
6
- belongs_to :payment_method, inverse_of: :store_payment_methods
5
+ belongs_to :store, inverse_of: :store_payment_methods, optional: true
6
+ belongs_to :payment_method, inverse_of: :store_payment_methods, optional: true
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class StoreShippingMethod < Spree::Base
5
- belongs_to :store, inverse_of: :store_shipping_methods
6
- belongs_to :shipping_method, inverse_of: :store_shipping_methods
5
+ belongs_to :store, inverse_of: :store_shipping_methods, optional: true
6
+ belongs_to :shipping_method, inverse_of: :store_shipping_methods, optional: true
7
7
  end
8
8
  end
@@ -17,7 +17,7 @@ module Spree
17
17
  include Spree::CalculatedAdjustments
18
18
  include Spree::AdjustmentSource
19
19
 
20
- belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates
20
+ belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates, optional: true
21
21
 
22
22
  has_many :tax_rate_tax_categories,
23
23
  class_name: 'Spree::TaxRateTaxCategory',
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class TaxRateTaxCategory < Spree::Base
5
- belongs_to :tax_rate, class_name: 'Spree::TaxRate', inverse_of: :tax_rate_tax_categories
6
- belongs_to :tax_category, class_name: 'Spree::TaxCategory', inverse_of: :tax_rate_tax_categories
5
+ belongs_to :tax_rate, class_name: 'Spree::TaxRate', inverse_of: :tax_rate_tax_categories, optional: true
6
+ belongs_to :tax_category, class_name: 'Spree::TaxCategory', inverse_of: :tax_rate_tax_categories, optional: true
7
7
  end
8
8
  end
@@ -7,7 +7,7 @@ class Spree::UnitCancel < Spree::Base
7
7
  SHORT_SHIP = 'Short Ship'
8
8
  DEFAULT_REASON = 'Cancel'
9
9
 
10
- belongs_to :inventory_unit
10
+ belongs_to :inventory_unit, optional: true
11
11
  has_one :adjustment, as: :source, dependent: :destroy
12
12
 
13
13
  validates :inventory_unit, presence: true
@@ -41,7 +41,10 @@ class Spree::UnitCancel < Spree::Base
41
41
  private
42
42
 
43
43
  def weighted_line_item_amount(line_item)
44
- line_item.total_before_tax / quantity_of_line_item(line_item)
44
+ quantity_of_line_item = quantity_of_line_item(line_item)
45
+ raise ZeroDivisionError, "Line Item does not have any inventory units available to cancel" if quantity_of_line_item.zero?
46
+
47
+ line_item.total_before_tax / quantity_of_line_item
45
48
  end
46
49
 
47
50
  def quantity_of_line_item(line_item)
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class UserAddress < Spree::Base
5
- belongs_to :user, class_name: UserClassHandle.new, foreign_key: "user_id"
6
- belongs_to :address, class_name: "Spree::Address"
5
+ belongs_to :user, class_name: UserClassHandle.new, foreign_key: "user_id", optional: true
6
+ belongs_to :address, class_name: "Spree::Address", optional: true
7
7
 
8
8
  validates_uniqueness_of :address_id, scope: :user_id
9
9
  validates_uniqueness_of :user_id, conditions: -> { active.default }, message: :default_address_exists, if: :default?
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class UserStockLocation < Spree::Base
5
- belongs_to :user, class_name: Spree::UserClassHandle.new, inverse_of: :user_stock_locations
6
- belongs_to :stock_location, class_name: "Spree::StockLocation", inverse_of: :user_stock_locations
5
+ belongs_to :user, class_name: Spree::UserClassHandle.new, inverse_of: :user_stock_locations, optional: true
6
+ belongs_to :stock_location, class_name: "Spree::StockLocation", inverse_of: :user_stock_locations, optional: true
7
7
  end
8
8
  end
@@ -2,41 +2,49 @@
2
2
 
3
3
  module Spree
4
4
  class Variant < Spree::Base
5
- # FIXME: WARNING tested only under sqlite and postgresql
6
- scope :descend_by_popularity, -> {
7
- order(Arel.sql("COALESCE((SELECT COUNT(*) FROM #{Spree::LineItem.quoted_table_name} GROUP BY #{Spree::LineItem.quoted_table_name}.variant_id HAVING #{Spree::LineItem.quoted_table_name}.variant_id = #{Spree::Variant.quoted_table_name}.id), 0) DESC"))
8
- }
9
-
10
- class << self
11
- # Returns variants that match a given option value
12
- #
13
- # Example:
14
- #
15
- # product.variants_including_master.has_option(OptionType.find_by(name: 'shoe-size'), OptionValue.find_by(name: '8'))
16
- def has_option(option_type, *option_values)
17
- option_types = Spree::OptionType.table_name
18
-
19
- option_type_conditions = case option_type
20
- when OptionType then { "#{option_types}.name" => option_type.name }
21
- when String then { "#{option_types}.name" => option_type }
22
- else { "#{option_types}.id" => option_type }
23
- end
5
+ module Scopes
6
+ def self.prepended(base)
7
+ base.class_eval do
8
+ # FIXME: WARNING tested only under sqlite and postgresql
9
+ scope :descend_by_popularity, -> {
10
+ order(Arel.sql("COALESCE((SELECT COUNT(*) FROM #{Spree::LineItem.quoted_table_name} GROUP BY #{Spree::LineItem.quoted_table_name}.variant_id HAVING #{Spree::LineItem.quoted_table_name}.variant_id = #{Spree::Variant.quoted_table_name}.id), 0) DESC"))
11
+ }
12
+
13
+ class << self
14
+ # Returns variants that match a given option value
15
+ #
16
+ # Example:
17
+ #
18
+ # product.variants_including_master.has_option(OptionType.find_by(name: 'shoe-size'), OptionValue.find_by(name: '8'))
19
+ def has_option(option_type, *option_values)
20
+ option_types = Spree::OptionType.table_name
21
+
22
+ option_type_conditions = case option_type
23
+ when OptionType then { "#{option_types}.name" => option_type.name }
24
+ when String then { "#{option_types}.name" => option_type }
25
+ else { "#{option_types}.id" => option_type }
26
+ end
24
27
 
25
- relation = joins(option_values: :option_type).where(option_type_conditions)
28
+ relation = joins(option_values: :option_type).where(option_type_conditions)
26
29
 
27
- option_values.each do |option_value|
28
- option_value_conditions = case option_value
29
- when OptionValue then { "#{Spree::OptionValue.table_name}.name" => option_value.name }
30
- when String then { "#{Spree::OptionValue.table_name}.name" => option_value }
31
- else { "#{Spree::OptionValue.table_name}.id" => option_value }
30
+ option_values.each do |option_value|
31
+ option_value_conditions = case option_value
32
+ when OptionValue then { "#{Spree::OptionValue.table_name}.name" => option_value.name }
33
+ when String then { "#{Spree::OptionValue.table_name}.name" => option_value }
34
+ else { "#{Spree::OptionValue.table_name}.id" => option_value }
35
+ end
36
+ relation = relation.where(option_value_conditions)
37
+ end
38
+
39
+ relation
40
+ end
41
+
42
+ alias_method :has_options, :has_option
32
43
  end
33
- relation = relation.where(option_value_conditions)
34
44
  end
35
-
36
- relation
37
45
  end
38
46
 
39
- alias_method :has_options, :has_option
47
+ ::Spree::Variant.prepend self
40
48
  end
41
49
  end
42
50
  end
@@ -37,7 +37,7 @@ module Spree
37
37
  include Spree::DefaultPrice
38
38
 
39
39
  belongs_to :product, -> { with_deleted }, touch: true, class_name: 'Spree::Product', inverse_of: :variants, optional: false
40
- belongs_to :tax_category, class_name: 'Spree::TaxCategory'
40
+ belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
41
41
 
42
42
  delegate :name, :description, :slug, :available_on, :shipping_category_id,
43
43
  :meta_description, :meta_keywords, :shipping_category,
@@ -13,7 +13,7 @@
13
13
  # targeted by the rule, the properties will automatically apply to the variant.
14
14
  module Spree
15
15
  class VariantPropertyRule < Spree::Base
16
- belongs_to :product, touch: true
16
+ belongs_to :product, touch: true, optional: true
17
17
 
18
18
  has_many :values, class_name: 'Spree::VariantPropertyRuleValue', dependent: :destroy
19
19
  has_many :properties, through: :values
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class VariantPropertyRuleCondition < Spree::Base
5
- belongs_to :option_value
6
- belongs_to :variant_property_rule, touch: true
5
+ belongs_to :option_value, optional: true
6
+ belongs_to :variant_property_rule, touch: true, optional: true
7
7
 
8
8
  validates_uniqueness_of :option_value_id, scope: :variant_property_rule_id
9
9
  end
@@ -6,7 +6,7 @@ module Spree
6
6
 
7
7
  acts_as_list scope: :variant_property_rule
8
8
 
9
- belongs_to :property
10
- belongs_to :variant_property_rule, touch: true
9
+ belongs_to :property, optional: true
10
+ belongs_to :variant_property_rule, touch: true, optional: true
11
11
  end
12
12
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class WalletPaymentSource < Spree::Base
5
- belongs_to :user, class_name: Spree::UserClassHandle.new, foreign_key: 'user_id', inverse_of: :wallet_payment_sources
6
- belongs_to :payment_source, polymorphic: true, inverse_of: :wallet_payment_sources
5
+ belongs_to :user, class_name: Spree::UserClassHandle.new, foreign_key: 'user_id', inverse_of: :wallet_payment_sources, optional: true
6
+ belongs_to :payment_source, polymorphic: true, inverse_of: :wallet_payment_sources, optional: true
7
7
 
8
8
  validates_presence_of :user
9
9
  validates_presence_of :payment_source
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Spree
4
4
  class ZoneMember < Spree::Base
5
- belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members
6
- belongs_to :zoneable, polymorphic: true
5
+ belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members, optional: true
6
+ belongs_to :zoneable, polymorphic: true, optional: true
7
7
 
8
8
  delegate :name, to: :zoneable, allow_nil: true
9
9
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
4
+ inflect.acronym 'RMA'
5
+ end