solidus_core 1.0.0.pre → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/mailers/spree/carton_mailer.rb +1 -1
- data/app/mailers/spree/reimbursement_mailer.rb +3 -2
- data/app/mailers/spree/test_mailer.rb +1 -1
- data/app/models/concerns/spree/user_methods.rb +49 -0
- data/app/models/spree/ability.rb +2 -0
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/adjustment_reason.rb +12 -0
- data/app/models/spree/app_configuration.rb +1 -1
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/inventory_unit.rb +10 -6
- data/app/models/spree/legacy_user.rb +4 -12
- data/app/models/spree/order.rb +15 -15
- data/app/models/spree/order/checkout.rb +20 -15
- data/app/models/spree/order/payments.rb +1 -5
- data/app/models/spree/order_cancellations.rb +1 -1
- data/app/models/spree/order_capturing.rb +1 -1
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/payment/processing.rb +39 -13
- data/app/models/spree/payment_method.rb +2 -2
- data/app/models/spree/permission_sets/base.rb +17 -0
- data/app/models/spree/permission_sets/configuration_display.rb +24 -0
- data/app/models/spree/permission_sets/configuration_management.rb +24 -0
- data/app/models/spree/permission_sets/dashboard_display.rb +9 -0
- data/app/models/spree/permission_sets/order_display.rb +15 -0
- data/app/models/spree/permission_sets/order_management.rb +15 -0
- data/app/models/spree/permission_sets/product_display.rb +18 -0
- data/app/models/spree/permission_sets/product_management.rb +19 -0
- data/app/models/spree/permission_sets/promotion_display.rb +12 -0
- data/app/models/spree/permission_sets/promotion_management.rb +12 -0
- data/app/models/spree/permission_sets/report_display.rb +9 -0
- data/app/models/spree/permission_sets/stock_display.rb +10 -0
- data/app/models/spree/permission_sets/stock_management.rb +11 -0
- data/app/models/spree/permission_sets/user_display.rb +11 -0
- data/app/models/spree/permission_sets/user_management.rb +11 -0
- data/app/models/spree/promotion/rules/item_total.rb +12 -33
- data/app/models/spree/promotion/rules/user.rb +2 -2
- data/app/models/spree/promotion_rule.rb +2 -2
- data/app/models/spree/reimbursement.rb +0 -12
- data/app/models/spree/return_authorization.rb +2 -2
- data/app/models/spree/return_item.rb +1 -0
- data/app/models/spree/return_reason.rb +18 -0
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +9 -26
- data/app/models/spree/store_credit.rb +31 -7
- data/app/models/spree/store_credit_event.rb +13 -11
- data/app/models/spree/store_credit_update_reason.rb +2 -0
- data/app/models/spree/user_class_handle.rb +21 -0
- data/app/models/spree/user_stock_location.rb +1 -1
- data/config/initializers/spree_user.rb +10 -0
- data/config/locales/en.yml +58 -16
- data/db/default/spree/return_reasons.rb +9 -0
- data/db/migrate/20140713140455_create_spree_return_authorization_reasons.rb +11 -9
- data/db/migrate/20150618212517_create_spree_store_credit_update_reasons.rb +8 -0
- data/db/migrate/20150619160613_create_adjustment_reason.rb +18 -0
- data/db/migrate/20150622144655_add_update_reason_to_store_credit_events.rb +5 -0
- data/db/migrate/20150623194316_add_return_authorization_reason_id_to_return_items.rb +7 -0
- data/db/migrate/20150623214058_seed_store_credit_update_reasons.rb +9 -0
- data/db/migrate/20150626200816_remove_shipping_method_id_from_spree_orders.rb +9 -0
- data/db/seeds.rb +9 -0
- data/lib/spree/core.rb +1 -4
- data/lib/spree/core/controller_helpers/auth.rb +15 -20
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/importer/order.rb +8 -5
- data/lib/spree/core/role_configuration.rb +70 -0
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +6 -0
- data/lib/spree/testing_support/factories/order_factory.rb +14 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +2 -4
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +3 -3
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +10 -0
- data/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/store_factory.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +2 -7
- metadata +36 -10
- data/app/assets/images/logo/solidus.png +0 -0
- data/app/models/spree/item_adjustments.rb.orig +0 -93
- data/app/models/spree/return_authorization_reason.rb +0 -7
- data/app/models/spree/static_model_preferences.rb +0 -32
- data/config/initializers/user_class_extensions.rb +0 -42
@@ -16,14 +16,14 @@ module Spree
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def provider_class
|
19
|
-
raise ::NotImplementedError,
|
19
|
+
raise ::NotImplementedError, "You must implement provider_class method for #{self.class}."
|
20
20
|
end
|
21
21
|
|
22
22
|
# The class that will process payments for this payment type, used for @payment.source
|
23
23
|
# e.g. CreditCard in the case of a the Gateway payment type
|
24
24
|
# nil means the payment method doesn't require a source e.g. check
|
25
25
|
def payment_source_class
|
26
|
-
raise ::NotImplementedError,
|
26
|
+
raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.available(display_on = 'both')
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class ConfigurationDisplay < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can [:edit, :admin], :general_settings
|
6
|
+
can [:display, :admin], Spree::TaxCategory
|
7
|
+
can [:display, :admin], Spree::TaxRate
|
8
|
+
can [:display, :admin], Spree::Zone
|
9
|
+
can [:display, :admin], Spree::Country
|
10
|
+
can [:display, :admin], Spree::State
|
11
|
+
can [:display, :admin], Spree::PaymentMethod
|
12
|
+
can [:display, :admin], Spree::Taxonomy
|
13
|
+
can [:display, :admin], Spree::ShippingMethod
|
14
|
+
can [:display, :admin], Spree::ShippingCategory
|
15
|
+
can [:display, :admin], Spree::StockLocation
|
16
|
+
can [:display, :admin], Spree::StockMovement
|
17
|
+
can [:display, :admin], Spree::Tracker
|
18
|
+
can [:display, :admin], Spree::RefundReason
|
19
|
+
can [:display, :admin], Spree::ReimbursementType
|
20
|
+
can [:display, :admin], Spree::ReturnReason
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class ConfigurationManagement < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can :manage, :general_settings
|
6
|
+
can :manage, Spree::TaxCategory
|
7
|
+
can :manage, Spree::TaxRate
|
8
|
+
can :manage, Spree::Zone
|
9
|
+
can :manage, Spree::Country
|
10
|
+
can :manage, Spree::State
|
11
|
+
can :manage, Spree::PaymentMethod
|
12
|
+
can :manage, Spree::Taxonomy
|
13
|
+
can :manage, Spree::ShippingMethod
|
14
|
+
can :manage, Spree::ShippingCategory
|
15
|
+
can :manage, Spree::StockLocation
|
16
|
+
can :manage, Spree::StockMovement
|
17
|
+
can :manage, Spree::Tracker
|
18
|
+
can :manage, Spree::RefundReason
|
19
|
+
can :manage, Spree::ReimbursementType
|
20
|
+
can :manage, Spree::ReturnReason
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class OrderDisplay < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can [:display, :admin, :edit, :cart], Spree::Order
|
6
|
+
can [:display, :admin], Spree::Payment
|
7
|
+
can [:display, :admin], Spree::Shipment
|
8
|
+
can [:display, :admin], Spree::Adjustment
|
9
|
+
can [:display, :admin], Spree::LineItem
|
10
|
+
can [:display, :admin], Spree::ReturnAuthorization
|
11
|
+
can [:display, :admin], Spree::CustomerReturn
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class OrderManagement < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can :manage, Spree::Order
|
6
|
+
can :manage, Spree::Payment
|
7
|
+
can :manage, Spree::Shipment
|
8
|
+
can :manage, Spree::Adjustment
|
9
|
+
can :manage, Spree::LineItem
|
10
|
+
can :manage, Spree::ReturnAuthorization
|
11
|
+
can :manage, Spree::CustomerReturn
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class ProductDisplay < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can [:display, :admin, :edit], Spree::Product
|
6
|
+
can [:display, :admin], Spree::Image
|
7
|
+
can [:display, :admin], Spree::Variant
|
8
|
+
can [:display, :admin], Spree::OptionValue
|
9
|
+
can [:display, :admin], Spree::ProductProperty
|
10
|
+
can [:display, :admin], Spree::OptionType
|
11
|
+
can [:display, :admin], Spree::Property
|
12
|
+
can [:display, :admin], Spree::Prototype
|
13
|
+
can [:display, :admin], Spree::Taxonomy
|
14
|
+
can [:display, :admin], Spree::Taxon
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class ProductManagement < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can :manage, Spree::Product
|
6
|
+
can :manage, Spree::Image
|
7
|
+
can :manage, Spree::Variant
|
8
|
+
can :manage, Spree::OptionValue
|
9
|
+
can :manage, Spree::ProductProperty
|
10
|
+
can :manage, Spree::OptionType
|
11
|
+
can :manage, Spree::Property
|
12
|
+
can :manage, Spree::Prototype
|
13
|
+
can :manage, Spree::Taxonomy
|
14
|
+
can :manage, Spree::Taxon
|
15
|
+
can :manage, Spree::Classification
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class PromotionDisplay < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can [:display, :admin], Spree::Promotion
|
6
|
+
can [:display, :admin], Spree::PromotionRule
|
7
|
+
can [:display, :admin], Spree::PromotionAction
|
8
|
+
can [:display, :admin], Spree::PromotionCategory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class PromotionManagement < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can :manage, Spree::Promotion
|
6
|
+
can :manage, Spree::PromotionRule
|
7
|
+
can :manage, Spree::PromotionAction
|
8
|
+
can :manage, Spree::PromotionCategory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
class UserDisplay < PermissionSets::Base
|
4
|
+
def activate!
|
5
|
+
can [:display, :admin, :edit, :addresses, :orders, :items], Spree.user_class
|
6
|
+
can [:display, :admin], Spree::StoreCredit
|
7
|
+
can :display, Spree::Role
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -4,14 +4,10 @@ module Spree
|
|
4
4
|
# A rule to apply to an order greater than (or greater than or equal to)
|
5
5
|
# a specific amount
|
6
6
|
class ItemTotal < PromotionRule
|
7
|
-
preference :
|
8
|
-
preference :
|
9
|
-
preference :amount_max, :decimal, default: 1000.00
|
10
|
-
preference :operator_max, :string, default: '<'
|
7
|
+
preference :amount, :decimal, default: 100.00
|
8
|
+
preference :operator, :string, default: '>'
|
11
9
|
|
12
|
-
|
13
|
-
OPERATORS_MIN = ['gt', 'gte']
|
14
|
-
OPERATORS_MAX = ['lt','lte']
|
10
|
+
OPERATORS = ['gt', 'gte']
|
15
11
|
|
16
12
|
def applicable?(promotable)
|
17
13
|
promotable.is_a?(Spree::Order)
|
@@ -19,42 +15,25 @@ module Spree
|
|
19
15
|
|
20
16
|
def eligible?(order, options = {})
|
21
17
|
item_total = order.item_total
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
eligibility_errors.add(:base, ineligible_message_max) unless upper_limit_condition
|
27
|
-
eligibility_errors.add(:base, ineligible_message_min) unless lower_limit_condition
|
18
|
+
unless item_total.send(preferred_operator == 'gte' ? :>= : :>, BigDecimal.new(preferred_amount.to_s))
|
19
|
+
eligibility_errors.add(:base, ineligible_message)
|
20
|
+
end
|
28
21
|
|
29
22
|
eligibility_errors.empty?
|
30
23
|
end
|
31
24
|
|
32
25
|
private
|
33
|
-
def
|
34
|
-
Spree::Money.new(
|
35
|
-
end
|
36
|
-
|
37
|
-
def formatted_amount_max
|
38
|
-
Spree::Money.new(preferred_amount_max).to_s
|
26
|
+
def formatted_amount
|
27
|
+
Spree::Money.new(preferred_amount).to_s
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
eligibility_error_message(:item_total_more_than_or_equal, amount: formatted_amount_max)
|
45
|
-
else
|
46
|
-
eligibility_error_message(:item_total_more_than, amount: formatted_amount_max)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def ineligible_message_min
|
51
|
-
if preferred_operator_min == 'gte'
|
52
|
-
eligibility_error_message(:item_total_less_than, amount: formatted_amount_min)
|
30
|
+
def ineligible_message
|
31
|
+
if preferred_operator == 'gte'
|
32
|
+
eligibility_error_message(:item_total_less_than, amount: formatted_amount)
|
53
33
|
else
|
54
|
-
eligibility_error_message(:item_total_less_than_or_equal, amount:
|
34
|
+
eligibility_error_message(:item_total_less_than_or_equal, amount: formatted_amount)
|
55
35
|
end
|
56
36
|
end
|
57
|
-
|
58
37
|
end
|
59
38
|
end
|
60
39
|
end
|
@@ -2,9 +2,9 @@ module Spree
|
|
2
2
|
class Promotion
|
3
3
|
module Rules
|
4
4
|
class User < PromotionRule
|
5
|
-
belongs_to :user, class_name:
|
5
|
+
belongs_to :user, class_name: Spree::UserClassHandle.new
|
6
6
|
|
7
|
-
has_and_belongs_to_many :users, class_name:
|
7
|
+
has_and_belongs_to_many :users, class_name: Spree::UserClassHandle.new,
|
8
8
|
join_table: 'spree_promotion_rules_users',
|
9
9
|
foreign_key: 'promotion_rule_id',
|
10
10
|
association_foreign_key: :user_id
|
@@ -13,11 +13,11 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def applicable?(promotable)
|
16
|
-
raise
|
16
|
+
raise NotImplementedError, "applicable? should be implemented in a sub-class of Spree::PromotionRule"
|
17
17
|
end
|
18
18
|
|
19
19
|
def eligible?(promotable, options = {})
|
20
|
-
raise
|
20
|
+
raise NotImplementedError, "eligible? should be implemented in a sub-class of Spree::PromotionRule"
|
21
21
|
end
|
22
22
|
|
23
23
|
# This states if a promotion can be applied to the specified line item
|
@@ -172,17 +172,5 @@ module Spree
|
|
172
172
|
end
|
173
173
|
unpaid_amount.abs.between?(0, leniency)
|
174
174
|
end
|
175
|
-
|
176
|
-
|
177
|
-
# If there are multiple different reimbursement types for a single reimbursement,
|
178
|
-
# We open ourselves to a one-cent rounding error for every type over the first one.
|
179
|
-
# This is due to how we round #unpaid_amount and how each reimbursement type will round as well.
|
180
|
-
# Since at this point, the payments and credits have already been processed, we should
|
181
|
-
# allow the reimbursement to show as 'reimbursed' and not 'errored'
|
182
|
-
def unpaid_amount_within_tolerance?
|
183
|
-
reimbursement_count = reimbursement_models.count { |model| model.total_amount_reimbursed_for(self) > 0 }
|
184
|
-
leniency = reimbursement_count > 0 ? (reimbursement_count - 1) * 0.01.to_d : 0
|
185
|
-
unpaid_amount.abs.between?(0, leniency)
|
186
|
-
end
|
187
175
|
end
|
188
176
|
end
|
@@ -7,7 +7,8 @@ module Spree
|
|
7
7
|
has_many :customer_returns, through: :return_items
|
8
8
|
|
9
9
|
belongs_to :stock_location
|
10
|
-
belongs_to :reason, class_name: 'Spree::
|
10
|
+
belongs_to :reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id
|
11
|
+
|
11
12
|
before_create :generate_number
|
12
13
|
|
13
14
|
after_save :generate_expedited_exchange_reimbursements
|
@@ -15,7 +16,6 @@ module Spree
|
|
15
16
|
accepts_nested_attributes_for :return_items, allow_destroy: true
|
16
17
|
|
17
18
|
validates :order, presence: true
|
18
|
-
validates :reason, presence: true
|
19
19
|
validates :stock_location, presence: true
|
20
20
|
validate :must_have_shipped_units, on: :create
|
21
21
|
validate :no_previously_exchanged_inventory_units, on: :create
|
@@ -36,6 +36,7 @@ module Spree
|
|
36
36
|
belongs_to :reimbursement, inverse_of: :return_items
|
37
37
|
belongs_to :preferred_reimbursement_type, class_name: 'Spree::ReimbursementType'
|
38
38
|
belongs_to :override_reimbursement_type, class_name: 'Spree::ReimbursementType'
|
39
|
+
belongs_to :return_reason, class_name: 'Spree::ReturnReason', foreign_key: :return_reason_id
|
39
40
|
|
40
41
|
validate :eligible_exchange_variant
|
41
42
|
validate :belongs_to_same_customer_order
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
class ReturnReason < ActiveRecord::Base
|
3
|
+
include Spree::NamedType
|
4
|
+
|
5
|
+
has_many :return_authorizations
|
6
|
+
|
7
|
+
def self.reasons_for_return_items(return_items)
|
8
|
+
reasons = Spree::ReturnReason.active
|
9
|
+
# Only allow an inactive reason if it's already associated to a return item
|
10
|
+
return_items.each do |return_item|
|
11
|
+
if return_item.return_reason && !return_item.return_reason.active?
|
12
|
+
reasons << return_item.return_reason
|
13
|
+
end
|
14
|
+
end
|
15
|
+
reasons
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
class RoleUser < ActiveRecord::Base
|
3
3
|
self.table_name = "spree_roles_users"
|
4
4
|
belongs_to :role, class_name: "Spree::Role"
|
5
|
-
belongs_to :user, class_name: Spree.
|
5
|
+
belongs_to :user, class_name: Spree::UserClassHandle.new
|
6
6
|
|
7
7
|
after_save :generate_admin_api_key
|
8
8
|
|
@@ -19,6 +19,8 @@ module Spree
|
|
19
19
|
|
20
20
|
before_validation :set_cost_zero_when_nil
|
21
21
|
|
22
|
+
before_destroy :ensure_can_destroy
|
23
|
+
|
22
24
|
# TODO remove the suppress_mailer temporary variable once we are calling 'ship'
|
23
25
|
# from outside of the state machine and can actually pass variables through.
|
24
26
|
attr_accessor :special_instructions, :suppress_mailer
|
@@ -152,32 +154,6 @@ module Spree
|
|
152
154
|
inventory_units.includes(:line_item).map(&:line_item).uniq
|
153
155
|
end
|
154
156
|
|
155
|
-
def process_order_payments
|
156
|
-
pending_payments = order.pending_payments
|
157
|
-
.sort_by(&:uncaptured_amount).reverse
|
158
|
-
|
159
|
-
shipment_to_pay = final_price_with_items
|
160
|
-
payments_amount = 0
|
161
|
-
|
162
|
-
payments_pool = pending_payments.each_with_object([]) do |payment, pool|
|
163
|
-
break if payments_amount >= shipment_to_pay
|
164
|
-
payments_amount += payment.uncaptured_amount
|
165
|
-
pool << payment
|
166
|
-
end
|
167
|
-
|
168
|
-
payments_pool.each do |payment|
|
169
|
-
capturable_amount = if payment.amount >= shipment_to_pay
|
170
|
-
shipment_to_pay
|
171
|
-
else
|
172
|
-
payment.amount
|
173
|
-
end
|
174
|
-
|
175
|
-
cents = (capturable_amount * 100).to_i
|
176
|
-
payment.capture!(cents)
|
177
|
-
shipment_to_pay -= capturable_amount
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
157
|
def line_items
|
182
158
|
inventory_units.includes(:line_item).map(&:line_item).uniq
|
183
159
|
end
|
@@ -423,5 +399,12 @@ module Spree
|
|
423
399
|
end
|
424
400
|
end
|
425
401
|
|
402
|
+
|
403
|
+
def ensure_can_destroy
|
404
|
+
unless pending?
|
405
|
+
errors.add(:state, :cannot_destroy, state: self.state)
|
406
|
+
return false
|
407
|
+
end
|
408
|
+
end
|
426
409
|
end
|
427
410
|
end
|