solidus_core 2.9.5 → 2.10.2
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.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +4 -4
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
- data/app/models/concerns/spree/user_address_book.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +13 -17
- data/app/models/spree/adjustment.rb +20 -9
- data/app/models/spree/asset.rb +1 -1
- data/app/models/spree/base.rb +0 -2
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/calculator/price_sack.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
- data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
- data/app/models/spree/calculator/tiered_percent.rb +6 -6
- data/app/models/spree/carton.rb +3 -3
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/credit_card.rb +4 -4
- data/app/models/spree/customer_return.rb +1 -1
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/inventory_unit.rb +5 -23
- data/app/models/spree/line_item.rb +4 -4
- data/app/models/spree/line_item_action.rb +2 -2
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/option_values_variant.rb +2 -2
- data/app/models/spree/order.rb +11 -27
- data/app/models/spree/order/checkout.rb +1 -1
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order_cancellations.rb +1 -1
- data/app/models/spree/order_capturing.rb +2 -2
- data/app/models/spree/order_contents.rb +2 -2
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_promotion.rb +3 -3
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_taxation.rb +3 -3
- data/app/models/spree/payment.rb +8 -45
- data/app/models/spree/payment/processing.rb +3 -3
- data/app/models/spree/payment_capture_event.rb +1 -1
- data/app/models/spree/payment_method.rb +5 -2
- data/app/models/spree/payment_method/bogus_credit_card.rb +1 -1
- data/app/models/spree/payment_source.rb +1 -1
- data/app/models/spree/price.rb +2 -2
- data/app/models/spree/product.rb +5 -5
- data/app/models/spree/product/scopes.rb +218 -210
- data/app/models/spree/product_option_type.rb +2 -2
- data/app/models/spree/product_promotion_rule.rb +2 -2
- data/app/models/spree/product_property.rb +2 -2
- data/app/models/spree/promotion.rb +28 -13
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion_action.rb +2 -2
- data/app/models/spree/promotion_chooser.rb +2 -2
- data/app/models/spree/promotion_code.rb +11 -10
- data/app/models/spree/promotion_code/batch_builder.rb +3 -3
- data/app/models/spree/promotion_code_batch.rb +1 -1
- data/app/models/spree/promotion_rule.rb +2 -2
- data/app/models/spree/promotion_rule_role.rb +2 -2
- data/app/models/spree/promotion_rule_store.rb +2 -2
- data/app/models/spree/promotion_rule_taxon.rb +2 -2
- data/app/models/spree/promotion_rule_user.rb +2 -2
- data/app/models/spree/refund.rb +5 -5
- data/app/models/spree/reimbursement.rb +5 -13
- data/app/models/spree/reimbursement/credit.rb +2 -2
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
- data/app/models/spree/return_authorization.rb +4 -10
- data/app/models/spree/return_item.rb +13 -52
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/role_user.rb +2 -2
- data/app/models/spree/shipment.rb +7 -41
- data/app/models/spree/shipping_calculator.rb +0 -4
- data/app/models/spree/shipping_manifest.rb +3 -3
- data/app/models/spree/shipping_method.rb +2 -2
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_method_stock_location.rb +2 -2
- data/app/models/spree/shipping_method_zone.rb +2 -2
- data/app/models/spree/shipping_rate.rb +2 -2
- data/app/models/spree/shipping_rate_tax.rb +2 -2
- data/app/models/spree/state.rb +2 -2
- data/app/models/spree/state_change.rb +2 -2
- data/app/models/spree/stock/differentiator.rb +1 -1
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/stock_quantities.rb +13 -12
- data/app/models/spree/store_credit.rb +8 -8
- data/app/models/spree/store_credit_event.rb +3 -3
- data/app/models/spree/store_payment_method.rb +2 -2
- data/app/models/spree/store_shipping_method.rb +2 -2
- data/app/models/spree/tax_calculator/default.rb +0 -4
- data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
- data/app/models/spree/tax_rate.rb +5 -1
- data/app/models/spree/tax_rate_tax_category.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
- data/app/models/spree/unit_cancel.rb +5 -2
- data/app/models/spree/user_address.rb +2 -2
- data/app/models/spree/user_last_url_storer.rb +46 -0
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
- data/app/models/spree/user_stock_location.rb +2 -2
- data/app/models/spree/variant.rb +10 -10
- data/app/models/spree/variant/scopes.rb +37 -29
- data/app/models/spree/variant_property_rule.rb +1 -1
- data/app/models/spree/variant_property_rule_condition.rb +2 -2
- data/app/models/spree/variant_property_rule_value.rb +2 -2
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +2 -2
- data/app/models/spree/zone.rb +1 -1
- data/app/models/spree/zone_member.rb +2 -2
- data/config/initializers/inflections.rb +5 -0
- data/config/initializers/money.rb +2 -0
- data/config/locales/en.yml +34 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
- data/lib/spree/app_configuration.rb +18 -3
- data/lib/spree/core.rb +12 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -13
- data/lib/spree/core/controller_helpers/strong_parameters.rb +21 -7
- data/lib/spree/core/engine.rb +2 -2
- data/lib/spree/core/importer/order.rb +29 -28
- data/lib/spree/core/importer/product.rb +2 -2
- data/lib/spree/core/product_filters.rb +15 -15
- data/lib/spree/core/role_configuration.rb +2 -2
- data/lib/spree/core/search/variant.rb +1 -1
- data/lib/spree/core/state_machines.rb +78 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
- data/lib/spree/core/state_machines/payment.rb +61 -0
- data/lib/spree/core/state_machines/reimbursement.rb +33 -0
- data/lib/spree/core/state_machines/return_authorization.rb +32 -0
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/lib/spree/core/state_machines/shipment.rb +58 -0
- data/lib/spree/core/stock_configuration.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -8
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +2 -2
- data/lib/spree/permission_sets/default_customer.rb +1 -1
- data/lib/spree/permission_sets/user_management.rb +3 -0
- data/lib/spree/permitted_attributes.rb +78 -9
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +4 -1
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +6 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -1
- data/solidus_core.gemspec +6 -6
- data/spec/lib/search/base_spec.rb +5 -1
- data/spec/lib/search/variant_spec.rb +1 -1
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +8 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
- data/spec/lib/spree/core/validators/email_spec.rb +18 -18
- data/spec/lib/spree/event_spec.rb +15 -3
- data/spec/lib/spree/permitted_attributes_spec.rb +41 -0
- data/spec/models/spree/ability_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +23 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
- data/spec/models/spree/carton_spec.rb +10 -2
- data/spec/models/spree/classification_spec.rb +21 -9
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/concerns/user_methods_spec.rb +5 -4
- data/spec/models/spree/credit_card_spec.rb +2 -2
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +1 -1
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +5 -5
- data/spec/models/spree/order/payment_spec.rb +1 -1
- data/spec/models/spree/order_contents_spec.rb +1 -1
- data/spec/models/spree/order_inventory_spec.rb +3 -3
- data/spec/models/spree/order_merger_spec.rb +3 -3
- data/spec/models/spree/order_shipping_spec.rb +1 -1
- data/spec/models/spree/order_spec.rb +14 -21
- data/spec/models/spree/order_updater_spec.rb +4 -3
- data/spec/models/spree/payment_create_spec.rb +6 -16
- data/spec/models/spree/payment_spec.rb +12 -12
- data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
- data/spec/models/spree/preference_spec.rb +4 -4
- data/spec/models/spree/preferences/preferable_spec.rb +3 -3
- data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/taxon_spec.rb +1 -0
- data/spec/models/spree/promotion_rule_spec.rb +6 -6
- data/spec/models/spree/promotion_spec.rb +71 -54
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +3 -3
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
- data/spec/models/spree/return_item_spec.rb +11 -11
- data/spec/models/spree/returns_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +6 -6
- data/spec/models/spree/shipping_calculator_spec.rb +1 -13
- data/spec/models/spree/shipping_method_spec.rb +32 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
- data/spec/models/spree/stock/differentiator_spec.rb +2 -2
- data/spec/models/spree/stock/estimator_spec.rb +3 -3
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +4 -4
- data/spec/models/spree/stock/package_spec.rb +28 -28
- data/spec/models/spree/stock/quantifier_spec.rb +2 -2
- data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
- data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
- data/spec/models/spree/stock_quantities_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +8 -8
- data/spec/models/spree/tax_category_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +1 -0
- data/spec/models/spree/taxon_spec.rb +2 -2
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
- data/spec/models/spree/unit_cancel_spec.rb +5 -0
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
- data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
- data/spec/models/spree/user_spec.rb +3 -3
- metadata +46 -39
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -148
- data/spec/models/spree/order/updating_spec.rb +0 -18
|
@@ -28,11 +28,11 @@ module Spree
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def update
|
|
31
|
-
if product.
|
|
31
|
+
if product.update(product_attrs)
|
|
32
32
|
variants_attrs.each do |variant_attribute|
|
|
33
33
|
# update the variant if the id is present in the payload
|
|
34
34
|
if variant_attribute['id'].present?
|
|
35
|
-
product.variants.find(variant_attribute['id'].to_i).
|
|
35
|
+
product.variants.find(variant_attribute['id'].to_i).update(variant_attribute)
|
|
36
36
|
else
|
|
37
37
|
# make sure the product is assigned before the options=
|
|
38
38
|
product.variants.create({ product: product }.merge(variant_attribute))
|
|
@@ -55,7 +55,7 @@ module Spree
|
|
|
55
55
|
# below scope would be something like ["$10 - $15", "$15 - $18", "$18 - $20"]
|
|
56
56
|
#
|
|
57
57
|
Spree::Product.add_search_scope :price_range_any do |*opts|
|
|
58
|
-
conds = opts.map { |
|
|
58
|
+
conds = opts.map { |element| Spree::Core::ProductFilters.price_filter[:conds][element] }.reject(&:nil?)
|
|
59
59
|
scope = conds.shift
|
|
60
60
|
conds.each do |new_scope|
|
|
61
61
|
scope = scope.or(new_scope)
|
|
@@ -68,17 +68,17 @@ module Spree
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def self.price_filter
|
|
71
|
-
|
|
72
|
-
conds = [[I18n.t('spree.under_price', price: format_price(10)),
|
|
73
|
-
["#{format_price(10)} - #{format_price(15)}",
|
|
74
|
-
["#{format_price(15)} - #{format_price(18)}",
|
|
75
|
-
["#{format_price(18)} - #{format_price(20)}",
|
|
76
|
-
[I18n.t('spree.or_over_price', price: format_price(20)),
|
|
71
|
+
value = Spree::Price.arel_table
|
|
72
|
+
conds = [[I18n.t('spree.under_price', price: format_price(10)), value[:amount].lteq(10)],
|
|
73
|
+
["#{format_price(10)} - #{format_price(15)}", value[:amount].in(10..15)],
|
|
74
|
+
["#{format_price(15)} - #{format_price(18)}", value[:amount].in(15..18)],
|
|
75
|
+
["#{format_price(18)} - #{format_price(20)}", value[:amount].in(18..20)],
|
|
76
|
+
[I18n.t('spree.or_over_price', price: format_price(20)), value[:amount].gteq(20)]]
|
|
77
77
|
{
|
|
78
78
|
name: I18n.t('spree.price_range'),
|
|
79
79
|
scope: :price_range_any,
|
|
80
80
|
conds: Hash[*conds.flatten],
|
|
81
|
-
labels: conds.map { |
|
|
81
|
+
labels: conds.map { |key, _value| [key, key] }
|
|
82
82
|
}
|
|
83
83
|
end
|
|
84
84
|
|
|
@@ -95,7 +95,7 @@ module Spree
|
|
|
95
95
|
# being blank: note that this relies on with_property doing a left outer join
|
|
96
96
|
# rather than an inner join.
|
|
97
97
|
Spree::Product.add_search_scope :brand_any do |*opts|
|
|
98
|
-
conds = opts.map { |
|
|
98
|
+
conds = opts.map { |value| ProductFilters.brand_filter[:conds][value] }.reject(&:nil?)
|
|
99
99
|
scope = conds.shift
|
|
100
100
|
conds.each do |new_scope|
|
|
101
101
|
scope = scope.or(new_scope)
|
|
@@ -107,12 +107,12 @@ module Spree
|
|
|
107
107
|
brand_property = Spree::Property.find_by(name: 'brand')
|
|
108
108
|
brands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []
|
|
109
109
|
pp = Spree::ProductProperty.arel_table
|
|
110
|
-
conds = Hash[*brands.map { |
|
|
110
|
+
conds = Hash[*brands.map { |brand| [brand, pp[:value].eq(brand)] }.flatten]
|
|
111
111
|
{
|
|
112
112
|
name: 'Brands',
|
|
113
113
|
scope: :brand_any,
|
|
114
114
|
conds: conds,
|
|
115
|
-
labels: brands.sort.map { |
|
|
115
|
+
labels: brands.sort.map { |key| [key, key] }
|
|
116
116
|
}
|
|
117
117
|
end
|
|
118
118
|
|
|
@@ -149,7 +149,7 @@ module Spree
|
|
|
149
149
|
{
|
|
150
150
|
name: 'Applicable Brands',
|
|
151
151
|
scope: :selective_brand_any,
|
|
152
|
-
labels: brands.sort.map { |
|
|
152
|
+
labels: brands.sort.map { |key| [key, key] }
|
|
153
153
|
}
|
|
154
154
|
end
|
|
155
155
|
|
|
@@ -171,7 +171,7 @@ module Spree
|
|
|
171
171
|
{
|
|
172
172
|
name: 'Taxons under ' + taxon.name,
|
|
173
173
|
scope: :taxons_id_in_tree_any,
|
|
174
|
-
labels: taxon.children.sort_by(&:position).map { |
|
|
174
|
+
labels: taxon.children.sort_by(&:position).map { |element| [element.name, element.id] },
|
|
175
175
|
conds: nil
|
|
176
176
|
}
|
|
177
177
|
end
|
|
@@ -184,11 +184,11 @@ module Spree
|
|
|
184
184
|
# idea: expand the format to allow nesting of labels?
|
|
185
185
|
def self.all_taxons
|
|
186
186
|
Spree::Deprecation.warn "all_taxons is deprecated in solidus_core. Please add it to your own application to continue using it."
|
|
187
|
-
taxons = Spree::Taxonomy.all.map { |
|
|
187
|
+
taxons = Spree::Taxonomy.all.map { |element| [element.root] + element.root.descendants }.flatten
|
|
188
188
|
{
|
|
189
189
|
name: 'All taxons',
|
|
190
190
|
scope: :taxons_id_equals_any,
|
|
191
|
-
labels: taxons.sort_by(&:name).map { |
|
|
191
|
+
labels: taxons.sort_by(&:name).map { |element| [element.name, element.id] },
|
|
192
192
|
conds: nil # not needed
|
|
193
193
|
}
|
|
194
194
|
end
|
|
@@ -69,8 +69,8 @@ module Spree
|
|
|
69
69
|
# Not public due to the fact this class is a Singleton
|
|
70
70
|
# @!visibility private
|
|
71
71
|
def initialize
|
|
72
|
-
@roles = Hash.new do |
|
|
73
|
-
|
|
72
|
+
@roles = Hash.new do |hash, name|
|
|
73
|
+
hash[name] = Role.new(name, Set.new)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
attr_writer :reimbursement,
|
|
7
|
+
:return_authorization,
|
|
8
|
+
:return_item_acceptance,
|
|
9
|
+
:return_item_reception,
|
|
10
|
+
:payment,
|
|
11
|
+
:inventory_unit,
|
|
12
|
+
:shipment
|
|
13
|
+
|
|
14
|
+
def return_authorization
|
|
15
|
+
@return_authorization ||= begin
|
|
16
|
+
require 'spree/core/state_machines/return_authorization'
|
|
17
|
+
'Spree::Core::StateMachines::ReturnAuthorization'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@return_authorization.constantize
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def return_item_reception
|
|
24
|
+
@return_item_reception_status ||= begin
|
|
25
|
+
require 'spree/core/state_machines/return_item/reception_status'
|
|
26
|
+
'Spree::Core::StateMachines::ReturnItem::ReceptionStatus'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@return_item_reception_status.constantize
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def return_item_acceptance
|
|
33
|
+
@return_item_acceptance_status ||= begin
|
|
34
|
+
require 'spree/core/state_machines/return_item/acceptance_status'
|
|
35
|
+
'Spree::Core::StateMachines::ReturnItem::AcceptanceStatus'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@return_item_acceptance_status.constantize
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def payment
|
|
42
|
+
@payment ||= begin
|
|
43
|
+
require 'spree/core/state_machines/payment'
|
|
44
|
+
'Spree::Core::StateMachines::Payment'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@payment.constantize
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def inventory_unit
|
|
51
|
+
@inventory_unit ||= begin
|
|
52
|
+
require 'spree/core/state_machines/inventory_unit'
|
|
53
|
+
'Spree::Core::StateMachines::InventoryUnit'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@inventory_unit.constantize
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def shipment
|
|
60
|
+
@shipment ||= begin
|
|
61
|
+
require 'spree/core/state_machines/shipment'
|
|
62
|
+
'Spree::Core::StateMachines::Shipment'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
@shipment.constantize
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def reimbursement
|
|
69
|
+
@reimbursement ||= begin
|
|
70
|
+
require 'spree/core/state_machines/reimbursement'
|
|
71
|
+
'Spree::Core::StateMachines::Reimbursement'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
@reimbursement.constantize
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
# Inventory Units' state machine
|
|
7
|
+
#
|
|
8
|
+
# for each event the following instance methods are dynamically implemented:
|
|
9
|
+
# #<event_name>
|
|
10
|
+
# #<event_name>!
|
|
11
|
+
# #can_<event_name>?
|
|
12
|
+
#
|
|
13
|
+
# for each state the following instance methods are implemented:
|
|
14
|
+
# #<state_name>?
|
|
15
|
+
#
|
|
16
|
+
module InventoryUnit
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
state_machine initial: :on_hand do
|
|
21
|
+
event :fill_backorder do
|
|
22
|
+
transition to: :on_hand, from: :backordered
|
|
23
|
+
end
|
|
24
|
+
after_transition on: :fill_backorder, do: :fulfill_order
|
|
25
|
+
|
|
26
|
+
event :ship do
|
|
27
|
+
transition to: :shipped, if: :allow_ship?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
event :return do
|
|
31
|
+
transition to: :returned, from: :shipped
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
event :cancel do
|
|
35
|
+
transition to: :canceled, from: ::Spree::InventoryUnit::CANCELABLE_STATES.map(&:to_sym)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
# Payments' state machine
|
|
7
|
+
#
|
|
8
|
+
# for each event the following instance methods are dynamically implemented:
|
|
9
|
+
# #<event_name>
|
|
10
|
+
# #<event_name>!
|
|
11
|
+
# #can_<event_name>?
|
|
12
|
+
#
|
|
13
|
+
# for each state the following instance methods are implemented:
|
|
14
|
+
# #<state_name>?
|
|
15
|
+
#
|
|
16
|
+
module Payment
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
state_machine initial: :checkout do
|
|
21
|
+
# With card payments, happens before purchase or authorization happens
|
|
22
|
+
#
|
|
23
|
+
# Setting it after creating a profile and authorizing a full amount will
|
|
24
|
+
# prevent the payment from being authorized again once Order transitions
|
|
25
|
+
# to complete
|
|
26
|
+
event :started_processing do
|
|
27
|
+
transition from: [:checkout, :pending, :completed, :processing], to: :processing
|
|
28
|
+
end
|
|
29
|
+
# When processing during checkout fails
|
|
30
|
+
event :failure do
|
|
31
|
+
transition from: [:pending, :processing], to: :failed
|
|
32
|
+
end
|
|
33
|
+
# With card payments this represents authorizing the payment
|
|
34
|
+
event :pend do
|
|
35
|
+
transition from: [:checkout, :processing], to: :pending
|
|
36
|
+
end
|
|
37
|
+
# With card payments this represents completing a purchase or capture transaction
|
|
38
|
+
event :complete do
|
|
39
|
+
transition from: [:processing, :pending, :checkout], to: :completed
|
|
40
|
+
end
|
|
41
|
+
event :void do
|
|
42
|
+
transition from: [:pending, :processing, :completed, :checkout], to: :void
|
|
43
|
+
end
|
|
44
|
+
# when the card brand isnt supported
|
|
45
|
+
event :invalidate do
|
|
46
|
+
transition from: [:checkout], to: :invalid
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
after_transition do |payment, transition|
|
|
50
|
+
payment.state_changes.create!(
|
|
51
|
+
previous_state: transition.from,
|
|
52
|
+
next_state: transition.to,
|
|
53
|
+
name: 'payment'
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
# Reimbursement' state machine
|
|
7
|
+
#
|
|
8
|
+
# for each event the following instance methods are dynamically implemented:
|
|
9
|
+
# #<event_name>
|
|
10
|
+
# #<event_name>!
|
|
11
|
+
# #can_<event_name>?
|
|
12
|
+
#
|
|
13
|
+
# for each state the following instance methods are implemented:
|
|
14
|
+
# #<state_name>?
|
|
15
|
+
#
|
|
16
|
+
module Reimbursement
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
state_machine :reimbursement_status, initial: :pending do
|
|
21
|
+
event :errored do
|
|
22
|
+
transition to: :errored, from: [:pending, :errored]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
event :reimbursed do
|
|
26
|
+
transition to: :reimbursed, from: [:pending, :errored]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
# Return Authorizations' state machine
|
|
7
|
+
#
|
|
8
|
+
# for each event the following instance methods are dynamically implemented:
|
|
9
|
+
# #<event_name>
|
|
10
|
+
# #<event_name>!
|
|
11
|
+
# #can_<event_name>?
|
|
12
|
+
#
|
|
13
|
+
# for each state the following instance methods are implemented:
|
|
14
|
+
# #<state_name>?
|
|
15
|
+
#
|
|
16
|
+
module ReturnAuthorization
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
|
|
19
|
+
included do
|
|
20
|
+
state_machine initial: :authorized do
|
|
21
|
+
before_transition to: :canceled, do: :cancel_return_items
|
|
22
|
+
|
|
23
|
+
event :cancel do
|
|
24
|
+
transition to: :canceled, from: :authorized,
|
|
25
|
+
if: lambda { |return_authorization| return_authorization.can_cancel_return_items? }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
module ReturnItem
|
|
7
|
+
# Return Items' acceptance status state machine
|
|
8
|
+
#
|
|
9
|
+
# for each event the following instance methods are dynamically implemented:
|
|
10
|
+
# #<event_name>
|
|
11
|
+
# #<event_name>!
|
|
12
|
+
# #can_<event_name>?
|
|
13
|
+
#
|
|
14
|
+
# for each state the following instance methods are implemented:
|
|
15
|
+
# #<state_name>?
|
|
16
|
+
#
|
|
17
|
+
module AcceptanceStatus
|
|
18
|
+
extend ActiveSupport::Concern
|
|
19
|
+
|
|
20
|
+
included do
|
|
21
|
+
state_machine :acceptance_status, initial: :pending do
|
|
22
|
+
event :attempt_accept do
|
|
23
|
+
transition to: :accepted, from: :accepted
|
|
24
|
+
transition to: :accepted, from: :pending, if: ->(return_item) { return_item.eligible_for_return? }
|
|
25
|
+
transition to: :manual_intervention_required, from: :pending, if: ->(return_item) { return_item.requires_manual_intervention? }
|
|
26
|
+
transition to: :rejected, from: :pending
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# bypasses eligibility checks
|
|
30
|
+
event :accept do
|
|
31
|
+
transition to: :accepted, from: [:accepted, :pending, :manual_intervention_required]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# bypasses eligibility checks
|
|
35
|
+
event :reject do
|
|
36
|
+
transition to: :rejected, from: [:accepted, :pending, :manual_intervention_required]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# bypasses eligibility checks
|
|
40
|
+
event :require_manual_intervention do
|
|
41
|
+
transition to: :manual_intervention_required, from: [:accepted, :pending, :manual_intervention_required]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
after_transition any => any, do: :persist_acceptance_status_errors
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Core
|
|
5
|
+
class StateMachines
|
|
6
|
+
module ReturnItem
|
|
7
|
+
# Return Items' reception status state machine
|
|
8
|
+
#
|
|
9
|
+
# for each event the following instance methods are dynamically implemented:
|
|
10
|
+
# #<event_name>
|
|
11
|
+
# #<event_name>!
|
|
12
|
+
# #can_<event_name>?
|
|
13
|
+
#
|
|
14
|
+
# for each state the following instance methods are implemented:
|
|
15
|
+
# #<state_name>?
|
|
16
|
+
#
|
|
17
|
+
module ReceptionStatus
|
|
18
|
+
extend ActiveSupport::Concern
|
|
19
|
+
|
|
20
|
+
included do
|
|
21
|
+
state_machine :reception_status, initial: :awaiting do
|
|
22
|
+
after_transition to: ::Spree::ReturnItem::COMPLETED_RECEPTION_STATUSES, do: :attempt_accept
|
|
23
|
+
after_transition to: ::Spree::ReturnItem::COMPLETED_RECEPTION_STATUSES, do: :check_unexchange
|
|
24
|
+
after_transition to: :received, do: :process_inventory_unit!
|
|
25
|
+
|
|
26
|
+
event(:cancel) { transition to: :cancelled, from: :awaiting }
|
|
27
|
+
|
|
28
|
+
event(:receive) { transition to: :received, from: ::Spree::ReturnItem::INTERMEDIATE_RECEPTION_STATUSES + [:awaiting] }
|
|
29
|
+
event(:unexchange) { transition to: :unexchanged, from: [:awaiting] }
|
|
30
|
+
event(:give) { transition to: :given_to_customer, from: :awaiting }
|
|
31
|
+
event(:lost) { transition to: :lost_in_transit, from: :awaiting }
|
|
32
|
+
event(:wrong_item_shipped) { transition to: :shipped_wrong_item, from: :awaiting }
|
|
33
|
+
event(:short_shipped) { transition to: :short_shipped, from: :awaiting }
|
|
34
|
+
event(:in_transit) { transition to: :in_transit, from: :awaiting }
|
|
35
|
+
event(:expired) { transition to: :expired, from: :awaiting }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|