solidus_core 2.9.6 → 2.10.3
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/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/engine.rb +2 -2
- data/lib/spree/core/importer/order.rb +28 -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 +3 -3
- 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/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/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_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 +49 -43
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -148
- data/spec/models/spree/order/updating_spec.rb +0 -18
@@ -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
|
@@ -77,22 +77,8 @@ module Spree
|
|
77
77
|
before_create :set_default_amount, unless: :amount_changed?
|
78
78
|
before_save :set_exchange_amount
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
after_transition to: COMPLETED_RECEPTION_STATUSES, do: :check_unexchange
|
83
|
-
after_transition to: :received, do: :process_inventory_unit!
|
84
|
-
|
85
|
-
event(:cancel) { transition to: :cancelled, from: :awaiting }
|
86
|
-
|
87
|
-
event(:receive) { transition to: :received, from: INTERMEDIATE_RECEPTION_STATUSES + [:awaiting] }
|
88
|
-
event(:unexchange) { transition to: :unexchanged, from: [:awaiting] }
|
89
|
-
event(:give) { transition to: :given_to_customer, from: :awaiting }
|
90
|
-
event(:lost) { transition to: :lost_in_transit, from: :awaiting }
|
91
|
-
event(:wrong_item_shipped) { transition to: :shipped_wrong_item, from: :awaiting }
|
92
|
-
event(:short_shipped) { transition to: :short_shipped, from: :awaiting }
|
93
|
-
event(:in_transit) { transition to: :in_transit, from: :awaiting }
|
94
|
-
event(:expired) { transition to: :expired, from: :awaiting }
|
95
|
-
end
|
80
|
+
include ::Spree::Config.state_machines.return_item_reception
|
81
|
+
include ::Spree::Config.state_machines.return_item_acceptance
|
96
82
|
|
97
83
|
extend DisplayMoney
|
98
84
|
money_methods :pre_tax_amount, :amount, :total, :total_excluding_vat
|
@@ -104,31 +90,6 @@ module Spree
|
|
104
90
|
COMPLETED_RECEPTION_STATUSES.map(&:to_s).include?(reception_status.to_s)
|
105
91
|
end
|
106
92
|
|
107
|
-
state_machine :acceptance_status, initial: :pending do
|
108
|
-
event :attempt_accept do
|
109
|
-
transition to: :accepted, from: :accepted
|
110
|
-
transition to: :accepted, from: :pending, if: ->(return_item) { return_item.eligible_for_return? }
|
111
|
-
transition to: :manual_intervention_required, from: :pending, if: ->(return_item) { return_item.requires_manual_intervention? }
|
112
|
-
transition to: :rejected, from: :pending
|
113
|
-
end
|
114
|
-
|
115
|
-
# bypasses eligibility checks
|
116
|
-
event :accept do
|
117
|
-
transition to: :accepted, from: [:accepted, :pending, :manual_intervention_required]
|
118
|
-
end
|
119
|
-
|
120
|
-
# bypasses eligibility checks
|
121
|
-
event :reject do
|
122
|
-
transition to: :rejected, from: [:accepted, :pending, :manual_intervention_required]
|
123
|
-
end
|
124
|
-
|
125
|
-
# bypasses eligibility checks
|
126
|
-
event :require_manual_intervention do
|
127
|
-
transition to: :manual_intervention_required, from: [:accepted, :pending, :manual_intervention_required]
|
128
|
-
end
|
129
|
-
|
130
|
-
after_transition any => any, do: :persist_acceptance_status_errors
|
131
|
-
end
|
132
93
|
|
133
94
|
attr_accessor :skip_customer_return_processing
|
134
95
|
|
@@ -214,7 +175,7 @@ module Spree
|
|
214
175
|
event_paths.delete(:expired)
|
215
176
|
event_paths.delete(:unexchange)
|
216
177
|
|
217
|
-
status_paths.map{ |
|
178
|
+
status_paths.map{ |status| I18n.t("spree.reception_states.#{status}", default: status.to_s.humanize) }.zip(event_paths)
|
218
179
|
end
|
219
180
|
|
220
181
|
def part_of_exchange?
|
@@ -226,7 +187,7 @@ module Spree
|
|
226
187
|
private
|
227
188
|
|
228
189
|
def persist_acceptance_status_errors
|
229
|
-
|
190
|
+
update(acceptance_status_errors: validator.errors)
|
230
191
|
end
|
231
192
|
|
232
193
|
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
|
@@ -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, ->(*
|
34
|
+
scope :with_state, ->(*state) { where(state: state) }
|
35
35
|
# sort by most recent shipped_at, falling back to created_at. add "id desc" to make specs that involve this scope more deterministic.
|
36
36
|
scope :reverse_chronological, -> {
|
37
37
|
order(Arel.sql("coalesce(#{Spree::Shipment.table_name}.shipped_at, #{Spree::Shipment.table_name}.created_at) desc"), id: :desc)
|
@@ -39,41 +39,7 @@ module Spree
|
|
39
39
|
|
40
40
|
scope :by_store, ->(store) { joins(:order).merge(Spree::Order.by_store(store)) }
|
41
41
|
|
42
|
-
|
43
|
-
state_machine initial: :pending, use_transactions: false do
|
44
|
-
event :ready do
|
45
|
-
transition from: :pending, to: :shipped, if: :can_transition_from_pending_to_shipped?
|
46
|
-
transition from: :pending, to: :ready, if: :can_transition_from_pending_to_ready?
|
47
|
-
end
|
48
|
-
|
49
|
-
event :pend do
|
50
|
-
transition from: :ready, to: :pending
|
51
|
-
end
|
52
|
-
|
53
|
-
event :ship do
|
54
|
-
transition from: [:ready, :canceled], to: :shipped
|
55
|
-
end
|
56
|
-
after_transition to: :shipped, do: :after_ship
|
57
|
-
|
58
|
-
event :cancel do
|
59
|
-
transition to: :canceled, from: [:pending, :ready]
|
60
|
-
end
|
61
|
-
after_transition to: :canceled, do: :after_cancel
|
62
|
-
|
63
|
-
event :resume do
|
64
|
-
transition from: :canceled, to: :ready, if: :can_transition_from_canceled_to_ready?
|
65
|
-
transition from: :canceled, to: :pending
|
66
|
-
end
|
67
|
-
after_transition from: :canceled, to: [:pending, :ready, :shipped], do: :after_resume
|
68
|
-
|
69
|
-
after_transition do |shipment, transition|
|
70
|
-
shipment.state_changes.create!(
|
71
|
-
previous_state: transition.from,
|
72
|
-
next_state: transition.to,
|
73
|
-
name: 'shipment'
|
74
|
-
)
|
75
|
-
end
|
76
|
-
end
|
42
|
+
include ::Spree::Config.state_machines.shipment
|
77
43
|
|
78
44
|
self.whitelisted_ransackable_associations = ['order']
|
79
45
|
self.whitelisted_ransackable_attributes = ['number']
|
@@ -142,7 +108,7 @@ module Spree
|
|
142
108
|
# @return [BigDecimal] the amount of this item, taking into consideration
|
143
109
|
# all non-tax adjustments.
|
144
110
|
def total_before_tax
|
145
|
-
amount + adjustments.select { |
|
111
|
+
amount + adjustments.select { |adjustment| !adjustment.tax? && adjustment.eligible? }.sum(&:amount)
|
146
112
|
end
|
147
113
|
|
148
114
|
# @return [BigDecimal] the amount of this shipment before VAT tax
|
@@ -219,7 +185,7 @@ module Spree
|
|
219
185
|
def select_shipping_method(shipping_method)
|
220
186
|
estimator = Spree::Config.stock.estimator_class.new
|
221
187
|
rates = estimator.shipping_rates(to_package, false)
|
222
|
-
rate = rates.detect { |
|
188
|
+
rate = rates.detect { |detected| detected.shipping_method_id == shipping_method.id }
|
223
189
|
rate.selected = true
|
224
190
|
self.shipping_rates = [rate]
|
225
191
|
end
|
@@ -326,7 +292,7 @@ module Spree
|
|
326
292
|
|
327
293
|
# Update Shipment and make sure Order states follow the shipment changes
|
328
294
|
def update_attributes_and_order(params = {})
|
329
|
-
if
|
295
|
+
if update(params)
|
330
296
|
if params.key? :selected_shipping_rate_id
|
331
297
|
# Changing the selected Shipping Rate won't update the cost (for now)
|
332
298
|
# so we persist the Shipment#cost before running `order.recalculate`
|
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
class ShippingCalculator < Calculator
|
5
|
-
def compute_shipment(_shipment)
|
6
|
-
raise NotImplementedError, "Please implement 'compute_shipment(shipment)' in your calculator: #{self.class.name}"
|
7
|
-
end
|
8
|
-
|
9
5
|
def compute_package(_package)
|
10
6
|
raise NotImplementedError, "Please implement 'compute_package(package)' in your calculator: #{self.class.name}"
|
11
7
|
end
|
@@ -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
|
-
|
25
|
-
|
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
|
|
@@ -41,7 +41,7 @@ module Spree
|
|
41
41
|
|
42
42
|
scope :available_to_store, ->(store) do
|
43
43
|
raise ArgumentError, "You must provide a store" if store.nil?
|
44
|
-
store.shipping_methods.empty? ? all : where(id: store.
|
44
|
+
store.shipping_methods.empty? ? all : where(id: store.shipping_methods.ids)
|
45
45
|
end
|
46
46
|
|
47
47
|
# @param shipping_category_ids [Array<Integer>] ids of desired shipping categories
|
@@ -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
|
@@ -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
|
data/app/models/spree/state.rb
CHANGED
@@ -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
|
@@ -24,7 +24,7 @@ module Spree
|
|
24
24
|
# table of { country.id => [ state.id , state.name ] }, arrays sorted by name
|
25
25
|
# blank is added elsewhere, if needed
|
26
26
|
def self.states_group_by_country_id
|
27
|
-
state_info = Hash.new { |
|
27
|
+
state_info = Hash.new { |hash, key| hash[key] = [] }
|
28
28
|
order(:name).each { |state|
|
29
29
|
state_info[state.country_id.to_s].push [state.id, state.name]
|
30
30
|
}
|
@@ -85,7 +85,7 @@ module Spree
|
|
85
85
|
# @return [Fixnum] the number of inventory units in the package,
|
86
86
|
# counting only those in the given state if it was specified
|
87
87
|
def quantity(state = nil)
|
88
|
-
matched_contents = state.nil? ? contents : contents.select { |
|
88
|
+
matched_contents = state.nil? ? contents : contents.select { |content| content.state.to_s == state.to_s }
|
89
89
|
matched_contents.map(&:quantity).sum
|
90
90
|
end
|
91
91
|
|
@@ -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
|
@@ -111,7 +111,7 @@ module Spree
|
|
111
111
|
def should_touch_variant?
|
112
112
|
# the variant_id changes from nil when a new stock location is added
|
113
113
|
inventory_cache_threshold &&
|
114
|
-
(saved_change_to_count_on_hand
|
114
|
+
(saved_change_to_count_on_hand&.any? { |cache| cache < inventory_cache_threshold }) ||
|
115
115
|
saved_change_to_variant_id?
|
116
116
|
end
|
117
117
|
|
@@ -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
|
|
@@ -8,8 +8,8 @@ module Spree
|
|
8
8
|
|
9
9
|
# @param quantities [Hash<Spree::Variant=>Numeric>]
|
10
10
|
def initialize(quantities = {})
|
11
|
-
raise ArgumentError unless quantities.keys.all?{ |
|
12
|
-
raise ArgumentError unless quantities.values.all?{ |
|
11
|
+
raise ArgumentError unless quantities.keys.all?{ |value| value.is_a?(Spree::Variant) }
|
12
|
+
raise ArgumentError unless quantities.values.all?{ |value| value.is_a?(Numeric) }
|
13
13
|
|
14
14
|
@quantities = quantities
|
15
15
|
end
|
@@ -33,16 +33,16 @@ module Spree
|
|
33
33
|
# Adds two StockQuantities together
|
34
34
|
# @return [Spree::StockQuantities]
|
35
35
|
def +(other)
|
36
|
-
combine_with(other) do |_variant,
|
37
|
-
(
|
36
|
+
combine_with(other) do |_variant, first, second|
|
37
|
+
(first || 0) + (second || 0)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
# Subtracts another StockQuantities from this one
|
42
42
|
# @return [Spree::StockQuantities]
|
43
43
|
def -(other)
|
44
|
-
combine_with(other) do |_variant,
|
45
|
-
(
|
44
|
+
combine_with(other) do |_variant, first, second|
|
45
|
+
(first || 0) - (second || 0)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,9 +50,10 @@ module Spree
|
|
50
50
|
# stock which exists in both StockQuantities.
|
51
51
|
# @return [Spree::StockQuantities]
|
52
52
|
def &(other)
|
53
|
-
combine_with(other) do |_variant,
|
54
|
-
next unless
|
55
|
-
|
53
|
+
combine_with(other) do |_variant, first, second|
|
54
|
+
next unless first && second
|
55
|
+
|
56
|
+
[first, second].min
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -72,9 +73,9 @@ module Spree
|
|
72
73
|
def combine_with(other)
|
73
74
|
self.class.new(
|
74
75
|
(variants | other.variants).map do |variant|
|
75
|
-
|
76
|
-
|
77
|
-
value = yield variant,
|
76
|
+
self_v = self[variant]
|
77
|
+
other_v = other[variant]
|
78
|
+
value = yield variant, self_v, other_v
|
78
79
|
[variant, value]
|
79
80
|
end.to_h.compact
|
80
81
|
)
|