solidus_core 4.6.2 → 4.7.0
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/Rakefile +13 -13
- data/app/controllers/spree/base_controller.rb +2 -2
- data/app/helpers/spree/base_helper.rb +24 -24
- data/app/helpers/spree/checkout_helper.rb +7 -7
- data/app/helpers/spree/core/controller_helpers/auth.rb +1 -1
- data/app/helpers/spree/core/controller_helpers/common.rb +3 -2
- data/app/helpers/spree/core/controller_helpers/order.rb +3 -5
- data/app/helpers/spree/core/controller_helpers/payment_parameters.rb +1 -2
- data/app/helpers/spree/core/controller_helpers/strong_parameters.rb +10 -10
- data/app/helpers/spree/products_helper.rb +5 -5
- data/app/helpers/spree/store_helper.rb +1 -1
- data/app/mailers/spree/carton_mailer.rb +3 -3
- data/app/mailers/spree/order_mailer.rb +4 -4
- data/app/mailers/spree/reimbursement_mailer.rb +2 -2
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +5 -5
- data/app/models/concerns/spree/active_storage_adapter/normalization.rb +5 -5
- data/app/models/concerns/spree/active_storage_adapter.rb +2 -2
- data/app/models/concerns/spree/adjustment_source.rb +4 -4
- data/app/models/concerns/spree/display_money.rb +2 -2
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/ordered_property_value_list.rb +2 -2
- data/app/models/concerns/spree/preferences/persistable.rb +1 -1
- data/app/models/concerns/spree/ransackable_attributes.rb +1 -0
- data/app/models/concerns/spree/soft_deletable.rb +2 -1
- data/app/models/concerns/spree/state_change_tracking.rb +1 -1
- data/app/models/concerns/spree/user_address_book.rb +12 -12
- data/app/models/concerns/spree/user_methods.rb +9 -9
- data/app/models/concerns/spree/user_reporting.rb +1 -0
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/address/name.rb +1 -1
- data/app/models/spree/address.rb +7 -7
- data/app/models/spree/adjustment.rb +11 -10
- data/app/models/spree/adjustment_reason.rb +2 -2
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +2 -2
- data/app/models/spree/calculator/flat_fee.rb +1 -1
- data/app/models/spree/calculator/flat_rate.rb +2 -2
- data/app/models/spree/calculator/returns/default_refund_amount.rb +3 -3
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +2 -2
- data/app/models/spree/calculator/shipping/flat_rate.rb +3 -3
- data/app/models/spree/calculator/shipping/flexi_rate.rb +8 -8
- data/app/models/spree/calculator/shipping/per_item.rb +3 -3
- data/app/models/spree/calculator/shipping/price_sack.rb +3 -3
- data/app/models/spree/calculator.rb +31 -6
- data/app/models/spree/carton.rb +4 -4
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/core/state_machines/order/class_methods.rb +3 -3
- data/app/models/spree/core/state_machines/return_item/acceptance_status.rb +1 -1
- data/app/models/spree/country.rb +1 -1
- data/app/models/spree/credit_card.rb +27 -27
- data/app/models/spree/customer_return.rb +5 -4
- data/app/models/spree/distributed_amounts_handler.rb +1 -1
- data/app/models/spree/fulfilment_changer.rb +22 -22
- data/app/models/spree/image/active_storage_attachment.rb +2 -2
- data/app/models/spree/image/paperclip_attachment.rb +8 -8
- data/app/models/spree/in_memory_order_updater.rb +262 -0
- data/app/models/spree/inventory_unit.rb +11 -11
- data/app/models/spree/item_total.rb +1 -1
- data/app/models/spree/legacy_user.rb +2 -2
- data/app/models/spree/line_item.rb +21 -11
- data/app/models/spree/log_entry.rb +3 -3
- data/app/models/spree/mergeable_orders_finder.rb +44 -0
- data/app/models/spree/money.rb +2 -1
- data/app/models/spree/null_promotion_adjuster.rb +1 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +2 -2
- data/app/models/spree/order/number_generator.rb +1 -1
- data/app/models/spree/order.rb +66 -64
- data/app/models/spree/order_cancellations.rb +1 -3
- data/app/models/spree/order_inventory.rb +5 -8
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_updater.rb +59 -37
- data/app/models/spree/payment/cancellation.rb +2 -2
- data/app/models/spree/payment/processing.rb +22 -22
- data/app/models/spree/payment.rb +25 -25
- data/app/models/spree/payment_capture_event.rb +2 -2
- data/app/models/spree/payment_create.rb +1 -1
- data/app/models/spree/payment_method/bogus_credit_card.rb +18 -18
- data/app/models/spree/payment_method/check.rb +3 -3
- data/app/models/spree/payment_method/credit_card.rb +1 -1
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +3 -3
- data/app/models/spree/payment_method/store_credit.rb +13 -13
- data/app/models/spree/payment_method.rb +12 -11
- data/app/models/spree/payment_source.rb +2 -2
- data/app/models/spree/permission_sets/dashboard_display.rb +3 -3
- data/app/models/spree/permission_sets/default_customer.rb +1 -1
- data/app/models/spree/preference.rb +1 -1
- data/app/models/spree/price.rb +7 -6
- data/app/models/spree/product/scopes.rb +23 -23
- data/app/models/spree/product.rb +37 -41
- data/app/models/spree/product_option_type.rb +2 -2
- data/app/models/spree/product_property.rb +3 -3
- data/app/models/spree/refund.rb +10 -10
- data/app/models/spree/refund_reason.rb +2 -2
- data/app/models/spree/reimbursement/credit.rb +1 -1
- data/app/models/spree/reimbursement.rb +8 -8
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -1
- data/app/models/spree/reimbursement_type.rb +2 -2
- data/app/models/spree/return_authorization.rb +7 -6
- data/app/models/spree/return_item/eligibility_validator/base_validator.rb +2 -2
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/order_completed.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/rma_required.rb +1 -1
- data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
- data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +6 -6
- data/app/models/spree/return_item.rb +31 -30
- data/app/models/spree/return_reason.rb +1 -1
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +37 -29
- data/app/models/spree/shipping_method.rb +9 -9
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_rate.rb +12 -10
- data/app/models/spree/shipping_rate_tax.rb +5 -4
- data/app/models/spree/simple_order_contents.rb +2 -2
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/stock/availability.rb +9 -9
- data/app/models/spree/stock/availability_validator.rb +3 -3
- data/app/models/spree/stock/differentiator.rb +2 -2
- data/app/models/spree/stock/estimator.rb +4 -4
- data/app/models/spree/stock/inventory_validator.rb +1 -1
- data/app/models/spree/stock/package.rb +3 -3
- data/app/models/spree/stock_item.rb +5 -5
- data/app/models/spree/stock_location.rb +6 -6
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/stock_quantities.rb +2 -2
- data/app/models/spree/store.rb +3 -3
- data/app/models/spree/store_credit.rb +30 -29
- data/app/models/spree/store_credit_category.rb +2 -2
- data/app/models/spree/store_credit_event.rb +6 -6
- data/app/models/spree/store_credit_reason.rb +1 -1
- data/app/models/spree/store_credit_type.rb +3 -3
- data/app/models/spree/store_selector/by_server_name.rb +1 -1
- data/app/models/spree/store_selector/legacy.rb +1 -1
- data/app/models/spree/tax/item_tax.rb +1 -0
- data/app/models/spree/tax/order_tax.rb +1 -0
- data/app/models/spree/tax_category.rb +3 -3
- data/app/models/spree/tax_rate.rb +5 -5
- data/app/models/spree/tax_rate_tax_category.rb +2 -2
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +4 -4
- data/app/models/spree/taxon.rb +16 -17
- data/app/models/spree/taxon_brand_selector.rb +3 -3
- data/app/models/spree/unauthorized_redirect_handler.rb +1 -1
- data/app/models/spree/unit_cancel.rb +4 -4
- data/app/models/spree/user_address.rb +3 -3
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +6 -8
- data/app/models/spree/user_last_url_storer.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +1 -1
- data/app/models/spree/variant/scopes.rb +9 -9
- data/app/models/spree/variant.rb +25 -25
- data/app/models/spree/variant_property_rule.rb +2 -2
- data/app/models/spree/variant_property_rule_condition.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +4 -4
- data/app/models/spree/wallet/default_payment_builder.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +2 -2
- data/app/models/spree/zone.rb +18 -18
- data/app/models/spree/zone_member.rb +1 -1
- data/app/subscribers/spree/carton_shipped_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_cancel_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_confirmation_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/order_inventory_cancellation_mailer_subscriber.rb +2 -2
- data/app/subscribers/spree/reimbursement_mailer_subscriber.rb +2 -2
- data/config/initializers/assets.rb +1 -1
- data/config/initializers/db_query_matchers.rb +9 -0
- data/config/initializers/friendly_id.rb +2 -2
- data/config/initializers/inflections.rb +1 -1
- data/config/initializers/money.rb +1 -1
- data/config/locales/en.yml +1 -0
- data/db/default/spree/countries.rb +7 -7
- data/db/default/spree/return_reasons.rb +11 -11
- data/db/default/spree/stock_locations.rb +1 -1
- data/db/default/spree/store_credit.rb +3 -4
- data/db/default/spree/stores.rb +1 -1
- data/db/default/spree/zones.rb +5 -5
- data/db/migrate/20160101010000_solidus_one_four.rb +16 -16
- data/db/migrate/20160420044191_create_spree_wallet_payment_sources.rb +3 -3
- data/db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb +7 -6
- data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +10 -10
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +6 -6
- data/db/migrate/20161129035810_add_index_to_spree_payments_number.rb +1 -1
- data/db/migrate/20170319191942_remove_order_id_from_inventory_units.rb +4 -4
- data/db/migrate/20180322142651_add_amount_remaining_to_store_credit_events.rb +9 -16
- data/db/migrate/20200320144521_add_default_billng_flag_to_user_addresses.rb +1 -0
- data/db/migrate/20210815004823_add_unique_index_to_option_values_variants.rb +3 -3
- data/db/migrate/20250207104016_add_primary_taxon_to_products.rb +1 -1
- data/db/migrate/20250214094207_add_reverse_charge_status_to_store.rb +1 -1
- data/db/migrate/20250225051308_add_vat_id_email_and_reverse_charge_status_to_addresses.rb +1 -1
- data/db/seeds.rb +3 -3
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +2 -2
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +3 -3
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +1 -1
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/braintree.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +1 -1
- data/lib/generators/solidus/install/app_templates/payment_method/stripe.rb +2 -2
- data/lib/generators/solidus/install/install_generator.rb +51 -51
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -0
- data/lib/generators/solidus/update/update_generator.rb +29 -29
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -6
- data/lib/generators/spree/dummy/dummy_generator.rb +22 -24
- data/lib/generators/spree/dummy/templates/rails/boot.rb +3 -3
- data/lib/generators/spree/dummy/templates/rails/test.rb +4 -4
- data/lib/solidus_core.rb +1 -1
- data/lib/spree/app_configuration.rb +59 -47
- data/lib/spree/bus.rb +1 -1
- data/lib/spree/config.rb +1 -1
- data/lib/spree/core/active_merchant_dependencies.rb +8 -8
- data/lib/spree/core/class_constantizer.rb +1 -1
- data/lib/spree/core/engine.rb +15 -15
- data/lib/spree/core/environment.rb +1 -1
- data/lib/spree/core/environment_extension.rb +2 -2
- data/lib/spree/core/importer/order.rb +15 -15
- data/lib/spree/core/importer/product.rb +4 -4
- data/lib/spree/core/importer.rb +2 -2
- data/lib/spree/core/null_promotion_configuration.rb +7 -7
- data/lib/spree/core/permalinks.rb +1 -1
- data/lib/spree/core/product_filters.rb +94 -93
- data/lib/spree/core/role_configuration.rb +3 -3
- data/lib/spree/core/search/base.rb +5 -6
- data/lib/spree/core/search/variant.rb +3 -3
- data/lib/spree/core/stock_configuration.rb +10 -49
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +3 -3
- data/lib/spree/core/versioned_value.rb +4 -6
- data/lib/spree/core.rb +49 -49
- data/lib/spree/deprecated_instance_variable_proxy.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/deprecator.rb +2 -2
- data/lib/spree/i18n.rb +2 -2
- data/lib/spree/localized_number.rb +3 -3
- data/lib/spree/manipulative_query_monitor.rb +19 -0
- data/lib/spree/migrations.rb +2 -2
- data/lib/spree/permitted_attributes.rb +10 -10
- data/lib/spree/preferences/configuration.rb +5 -5
- data/lib/spree/preferences/preferable.rb +8 -10
- data/lib/spree/preferences/preferable_class_methods.rb +16 -16
- data/lib/spree/preferences/preference_differentiator.rb +1 -1
- data/lib/spree/preferences/scoped_store.rb +2 -2
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/preferences/store.rb +6 -6
- data/lib/spree/testing_support/ability_helpers.rb +30 -30
- data/lib/spree/testing_support/authorization_helpers.rb +6 -5
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +1 -1
- data/lib/spree/testing_support/capybara_driver.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +12 -12
- data/lib/spree/testing_support/common_rake.rb +17 -16
- data/lib/spree/testing_support/dummy_ability.rb +1 -1
- data/lib/spree/testing_support/dummy_app/migrations.rb +1 -1
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +5 -5
- data/lib/spree/testing_support/dummy_app/routes.rb +1 -1
- data/lib/spree/testing_support/dummy_app.rb +34 -34
- data/lib/spree/testing_support/extension_rake.rb +2 -2
- data/lib/spree/testing_support/factories/address_factory.rb +12 -12
- data/lib/spree/testing_support/factories/adjustment_factory.rb +7 -7
- data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/calculator_factory.rb +6 -6
- data/lib/spree/testing_support/factories/carton_factory.rb +1 -1
- data/lib/spree/testing_support/factories/country_factory.rb +3 -3
- data/lib/spree/testing_support/factories/credit_card_factory.rb +3 -3
- data/lib/spree/testing_support/factories/customer_return_factory.rb +2 -2
- data/lib/spree/testing_support/factories/image_factory.rb +2 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/line_item_factory.rb +2 -2
- data/lib/spree/testing_support/factories/option_type_factory.rb +2 -2
- data/lib/spree/testing_support/factories/option_value_factory.rb +2 -2
- data/lib/spree/testing_support/factories/order_factory.rb +16 -16
- data/lib/spree/testing_support/factories/payment_factory.rb +9 -9
- data/lib/spree/testing_support/factories/payment_method_factory.rb +10 -10
- data/lib/spree/testing_support/factories/price_factory.rb +2 -2
- data/lib/spree/testing_support/factories/product_factory.rb +2 -2
- data/lib/spree/testing_support/factories/product_option_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/property_factory.rb +3 -3
- data/lib/spree/testing_support/factories/refund_factory.rb +2 -2
- data/lib/spree/testing_support/factories/refund_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +3 -3
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/role_factory.rb +2 -2
- data/lib/spree/testing_support/factories/shipment_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipping_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +7 -7
- data/lib/spree/testing_support/factories/shipping_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/state_factory.rb +4 -4
- data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +7 -7
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +3 -3
- data/lib/spree/testing_support/factories/stock_package_factory.rb +3 -3
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +8 -8
- data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +6 -6
- data/lib/spree/testing_support/factories/store_factory.rb +2 -2
- data/lib/spree/testing_support/factories/tax_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +3 -3
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +2 -2
- data/lib/spree/testing_support/factories/variant_factory.rb +2 -2
- data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_factory.rb +3 -3
- data/lib/spree/testing_support/factory_bot.rb +1 -1
- data/lib/spree/testing_support/flaky.rb +3 -2
- data/lib/spree/testing_support/flash.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +7 -7
- data/lib/spree/testing_support/preferences.rb +1 -1
- data/lib/spree/testing_support/rake.rb +1 -1
- data/lib/spree/testing_support/shared_examples/calculator.rb +1 -1
- data/lib/spree/testing_support/shared_examples/gallery.rb +7 -7
- data/lib/spree/testing_support/shared_examples/order_factory.rb +9 -9
- data/lib/spree/testing_support/shared_examples/working_factory.rb +1 -1
- data/lib/spree/testing_support/translations.rb +1 -1
- data/lib/spree_core.rb +1 -1
- data/lib/tasks/payment_method.rake +2 -2
- data/solidus_core.gemspec +49 -49
- metadata +60 -54
|
@@ -5,14 +5,15 @@ 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:
|
|
9
|
-
belongs_to :shipping_method, -> { with_discarded }, class_name:
|
|
8
|
+
belongs_to :shipment, class_name: "Spree::Shipment", touch: true, optional: true, inverse_of: :shipping_rates
|
|
9
|
+
belongs_to :shipping_method, -> { with_discarded }, class_name: "Spree::ShippingMethod", inverse_of: :shipping_rates, optional: true
|
|
10
10
|
|
|
11
11
|
has_many :taxes,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
class_name: "Spree::ShippingRateTax",
|
|
13
|
+
foreign_key: "shipping_rate_id",
|
|
14
|
+
inverse_of: :shipping_rate,
|
|
15
|
+
dependent: :destroy,
|
|
16
|
+
autosave: true
|
|
16
17
|
|
|
17
18
|
delegate :order, :currency, to: :shipment
|
|
18
19
|
delegate :name, :tax_category, :tax_category_id, to: :shipping_method
|
|
@@ -21,6 +22,7 @@ module Spree
|
|
|
21
22
|
alias_attribute :total_before_tax, :cost
|
|
22
23
|
|
|
23
24
|
extend DisplayMoney
|
|
25
|
+
|
|
24
26
|
money_methods :amount
|
|
25
27
|
|
|
26
28
|
def display_price
|
|
@@ -30,16 +32,16 @@ module Spree
|
|
|
30
32
|
|
|
31
33
|
tax_explanations = taxes.map(&:label).join(tax_label_separator)
|
|
32
34
|
|
|
33
|
-
I18n.t
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
I18n.t "spree.shipping_rate.display_price.display_price_with_explanations",
|
|
36
|
+
price:,
|
|
37
|
+
explanations: tax_explanations
|
|
36
38
|
end
|
|
37
39
|
alias_method :display_cost, :display_price
|
|
38
40
|
|
|
39
41
|
private
|
|
40
42
|
|
|
41
43
|
def tax_label_separator
|
|
42
|
-
I18n.t
|
|
44
|
+
I18n.t "spree.shipping_rate.display_price.tax_label_separator"
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
end
|
|
@@ -11,13 +11,14 @@ module Spree
|
|
|
11
11
|
belongs_to :tax_rate, class_name: "Spree::TaxRate", optional: true
|
|
12
12
|
|
|
13
13
|
extend DisplayMoney
|
|
14
|
+
|
|
14
15
|
money_methods :absolute_amount
|
|
15
16
|
|
|
16
17
|
delegate :currency, to: :shipping_rate, allow_nil: true
|
|
17
18
|
|
|
18
19
|
def label
|
|
19
20
|
I18n.t translation_key,
|
|
20
|
-
scope:
|
|
21
|
+
scope: "spree.shipping_rate_tax.label",
|
|
21
22
|
amount: display_absolute_amount,
|
|
22
23
|
tax_rate_name: tax_rate.name
|
|
23
24
|
end
|
|
@@ -30,9 +31,9 @@ module Spree
|
|
|
30
31
|
|
|
31
32
|
def translation_key
|
|
32
33
|
if tax_rate.included_in_price?
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
:vat
|
|
35
|
+
else
|
|
36
|
+
:sales_tax
|
|
36
37
|
end
|
|
37
38
|
end
|
|
38
39
|
end
|
|
@@ -53,7 +53,7 @@ module Spree
|
|
|
53
53
|
|
|
54
54
|
def approve(user: nil, name: nil)
|
|
55
55
|
if user.blank? && name.blank?
|
|
56
|
-
raise ArgumentError,
|
|
56
|
+
raise ArgumentError, "user or name must be specified"
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
order.update!(
|
|
@@ -86,7 +86,7 @@ module Spree
|
|
|
86
86
|
)
|
|
87
87
|
|
|
88
88
|
permitted_attributes = Spree::PermittedAttributes.line_item_attributes.dup
|
|
89
|
-
permitted_attributes << {
|
|
89
|
+
permitted_attributes << {admin_metadata: {}} if options[:admin_metadata].present?
|
|
90
90
|
|
|
91
91
|
line_item.quantity += quantity.to_i
|
|
92
92
|
line_item.options = ActionController::Parameters.new(options).permit(permitted_attributes).to_h
|
data/app/models/spree/state.rb
CHANGED
|
@@ -52,22 +52,22 @@ module Spree
|
|
|
52
52
|
|
|
53
53
|
def counts_on_hand
|
|
54
54
|
@counts_on_hand ||=
|
|
55
|
-
stock_item_scope
|
|
56
|
-
group(:variant_id, :stock_location_id)
|
|
57
|
-
sum(:count_on_hand)
|
|
55
|
+
stock_item_scope
|
|
56
|
+
.group(:variant_id, :stock_location_id)
|
|
57
|
+
.sum(:count_on_hand)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def backorderables
|
|
61
61
|
@backorderables ||=
|
|
62
|
-
stock_item_scope
|
|
63
|
-
where(backorderable: true)
|
|
64
|
-
pluck(:variant_id, :stock_location_id)
|
|
62
|
+
stock_item_scope
|
|
63
|
+
.where(backorderable: true)
|
|
64
|
+
.pluck(:variant_id, :stock_location_id)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def stock_item_scope
|
|
68
|
-
Spree::StockItem
|
|
69
|
-
where(variant_id: @variants)
|
|
70
|
-
where(stock_location_id: @stock_locations)
|
|
68
|
+
Spree::StockItem
|
|
69
|
+
.where(variant_id: @variants)
|
|
70
|
+
.where(stock_location_id: @stock_locations)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def restore_location_order(quantities_by_location_id)
|
|
@@ -12,7 +12,7 @@ module Spree
|
|
|
12
12
|
display_name += %{ (#{variant.options_text})} unless variant.options_text.blank?
|
|
13
13
|
|
|
14
14
|
line_item.errors.add(:quantity, I18n.t(
|
|
15
|
-
|
|
15
|
+
"spree.selected_quantity_not_available",
|
|
16
16
|
item: display_name.inspect
|
|
17
17
|
))
|
|
18
18
|
false
|
|
@@ -23,11 +23,11 @@ module Spree
|
|
|
23
23
|
|
|
24
24
|
def is_valid?(line_item)
|
|
25
25
|
if line_item.inventory_units.empty?
|
|
26
|
-
|
|
26
|
+
Spree::Config.stock.quantifier_class.new(line_item.variant).can_supply?(line_item.quantity)
|
|
27
27
|
else
|
|
28
28
|
quantity_by_stock_location_id = line_item.inventory_units.pending.joins(:shipment).group(:stock_location_id).count
|
|
29
29
|
quantity_by_stock_location_id.all? do |stock_location_id, quantity|
|
|
30
|
-
|
|
30
|
+
Spree::Config.stock.quantifier_class.new(line_item.variant, stock_location_id).can_supply?(quantity)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -22,8 +22,8 @@ module Spree
|
|
|
22
22
|
def build_missing
|
|
23
23
|
@missing = Hash.new(0)
|
|
24
24
|
required.keys.each do |variant|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
missing = required[variant] - packed[variant]
|
|
26
|
+
@missing[variant] = missing if missing > 0
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -60,10 +60,10 @@ module Spree
|
|
|
60
60
|
.includes(:calculator)
|
|
61
61
|
.to_a
|
|
62
62
|
.select do |ship_method|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
calculator = ship_method.calculator
|
|
64
|
+
calculator.available?(package) &&
|
|
65
|
+
(calculator.preferences[:currency].blank? ||
|
|
66
|
+
calculator.preferences[:currency] == package.shipment.order.currency)
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
end
|
|
@@ -109,9 +109,9 @@ module Spree
|
|
|
109
109
|
# @return [ActiveRecord::Relation] the [Spree::ShippingMethod]s available
|
|
110
110
|
# for this pacakge based on the stock location and shipping categories.
|
|
111
111
|
def shipping_methods
|
|
112
|
-
Spree::ShippingMethod
|
|
113
|
-
with_all_shipping_category_ids(shipping_category_ids)
|
|
114
|
-
available_in_stock_location(stock_location)
|
|
112
|
+
Spree::ShippingMethod
|
|
113
|
+
.with_all_shipping_category_ids(shipping_category_ids)
|
|
114
|
+
.available_in_stock_location(stock_location)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
# @return [Spree::Shipment] a new shipment containing this package's
|
|
@@ -4,13 +4,13 @@ module Spree
|
|
|
4
4
|
class StockItem < Spree::Base
|
|
5
5
|
include Spree::SoftDeletable
|
|
6
6
|
|
|
7
|
-
belongs_to :stock_location, class_name:
|
|
8
|
-
belongs_to :variant, -> { with_discarded }, class_name:
|
|
7
|
+
belongs_to :stock_location, class_name: "Spree::StockLocation", inverse_of: :stock_items, optional: true
|
|
8
|
+
belongs_to :variant, -> { with_discarded }, class_name: "Spree::Variant", inverse_of: :stock_items, optional: true
|
|
9
9
|
has_many :stock_movements, inverse_of: :stock_item
|
|
10
10
|
|
|
11
11
|
validates :stock_location, :variant, presence: true
|
|
12
|
-
validates :variant_id, uniqueness: {
|
|
13
|
-
validates :count_on_hand, numericality: {
|
|
12
|
+
validates :variant_id, uniqueness: {scope: [:stock_location_id, :deleted_at]}, allow_blank: true, unless: :deleted_at
|
|
13
|
+
validates :count_on_hand, numericality: {greater_than_or_equal_to: 0}, unless: :backorderable?
|
|
14
14
|
|
|
15
15
|
delegate :weight, :should_track_inventory?, to: :variant
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ module Spree
|
|
|
20
20
|
after_save :conditional_variant_touch, if: :saved_changes?
|
|
21
21
|
after_touch { variant.touch }
|
|
22
22
|
|
|
23
|
-
self.allowed_ransackable_attributes = [
|
|
23
|
+
self.allowed_ransackable_attributes = ["count_on_hand", "stock_location_id"]
|
|
24
24
|
self.allowed_ransackable_associations = %w[variant]
|
|
25
25
|
|
|
26
26
|
# @return [Array<Spree::InventoryUnit>] the backordered inventory units
|
|
@@ -17,14 +17,14 @@ module Spree
|
|
|
17
17
|
has_many :users, through: :user_stock_locations
|
|
18
18
|
has_many :customer_returns, inverse_of: :stock_location, dependent: :restrict_with_error
|
|
19
19
|
|
|
20
|
-
belongs_to :state, class_name:
|
|
21
|
-
belongs_to :country, class_name:
|
|
20
|
+
belongs_to :state, class_name: "Spree::State", optional: true
|
|
21
|
+
belongs_to :country, class_name: "Spree::Country", optional: true
|
|
22
22
|
|
|
23
23
|
has_many :shipping_method_stock_locations, dependent: :destroy
|
|
24
24
|
has_many :shipping_methods, through: :shipping_method_stock_locations
|
|
25
25
|
|
|
26
26
|
validates :name, presence: true
|
|
27
|
-
validates :code, uniqueness: {
|
|
27
|
+
validates :code, uniqueness: {allow_blank: true, case_sensitive: false}
|
|
28
28
|
|
|
29
29
|
scope :active, -> { where(active: true) }
|
|
30
30
|
scope :order_default, -> { order(default: :desc, position: :asc) }
|
|
@@ -100,14 +100,14 @@ module Spree
|
|
|
100
100
|
|
|
101
101
|
def move(variant, quantity, originator = nil)
|
|
102
102
|
if quantity < 1 && !stock_item(variant)
|
|
103
|
-
raise InvalidMovementError.new(I18n.t(
|
|
103
|
+
raise InvalidMovementError.new(I18n.t("spree.negative_movement_absent_item"))
|
|
104
104
|
end
|
|
105
105
|
stock_item_or_create(variant).stock_movements.create!(quantity:,
|
|
106
|
-
|
|
106
|
+
originator:)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
def fill_status(variant, quantity)
|
|
110
|
-
if item = stock_item(variant)
|
|
110
|
+
if (item = stock_item(variant))
|
|
111
111
|
item.fill_status(quantity)
|
|
112
112
|
else
|
|
113
113
|
[0, 0]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
4
|
class StockMovement < Spree::Base
|
|
5
|
-
belongs_to :stock_item, class_name:
|
|
5
|
+
belongs_to :stock_item, class_name: "Spree::StockItem", inverse_of: :stock_movements, optional: true
|
|
6
6
|
belongs_to :originator, polymorphic: true, optional: true
|
|
7
7
|
has_one :variant, through: :stock_item
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ module Spree
|
|
|
14
14
|
scope :recent, -> { order(created_at: :desc) }
|
|
15
15
|
|
|
16
16
|
self.allowed_ransackable_associations = %w[variant]
|
|
17
|
-
self.allowed_ransackable_attributes = [
|
|
17
|
+
self.allowed_ransackable_attributes = ["quantity"]
|
|
18
18
|
|
|
19
19
|
def readonly?
|
|
20
20
|
!new_record?
|
|
@@ -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?{ |value| value.is_a?(Spree::Variant) }
|
|
12
|
-
raise ArgumentError unless quantities.values.all?{ |value| value.is_a?(Numeric) }
|
|
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
|
data/app/models/spree/store.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Spree
|
|
|
17
17
|
|
|
18
18
|
has_many :orders, class_name: "Spree::Order"
|
|
19
19
|
|
|
20
|
-
validates :code, presence: true, uniqueness: {
|
|
20
|
+
validates :code, presence: true, uniqueness: {allow_blank: true, case_sensitive: true}
|
|
21
21
|
validates :name, presence: true
|
|
22
22
|
validates :url, presence: true
|
|
23
23
|
validates :mail_from_address, presence: true
|
|
@@ -34,9 +34,9 @@ module Spree
|
|
|
34
34
|
}, prefix: true
|
|
35
35
|
|
|
36
36
|
def available_locales
|
|
37
|
-
locales = super
|
|
37
|
+
locales = super
|
|
38
38
|
if locales
|
|
39
|
-
super
|
|
39
|
+
super.split(",").map(&:to_sym)
|
|
40
40
|
else
|
|
41
41
|
Spree.i18n_available_locales
|
|
42
42
|
end
|
|
@@ -3,31 +3,31 @@
|
|
|
3
3
|
class Spree::StoreCredit < Spree::PaymentSource
|
|
4
4
|
include Spree::SoftDeletable
|
|
5
5
|
|
|
6
|
-
VOID_ACTION
|
|
7
|
-
CREDIT_ACTION
|
|
8
|
-
CAPTURE_ACTION
|
|
9
|
-
ELIGIBLE_ACTION
|
|
10
|
-
AUTHORIZE_ACTION
|
|
11
|
-
ALLOCATION_ACTION =
|
|
12
|
-
ADJUSTMENT_ACTION =
|
|
13
|
-
INVALIDATE_ACTION =
|
|
6
|
+
VOID_ACTION = "void"
|
|
7
|
+
CREDIT_ACTION = "credit"
|
|
8
|
+
CAPTURE_ACTION = "capture"
|
|
9
|
+
ELIGIBLE_ACTION = "eligible"
|
|
10
|
+
AUTHORIZE_ACTION = "authorize"
|
|
11
|
+
ALLOCATION_ACTION = "allocation"
|
|
12
|
+
ADJUSTMENT_ACTION = "adjustment"
|
|
13
|
+
INVALIDATE_ACTION = "invalidate"
|
|
14
14
|
|
|
15
15
|
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
|
|
16
16
|
belongs_to :created_by, class_name: Spree::UserClassHandle.new, optional: true
|
|
17
17
|
belongs_to :category, class_name: "Spree::StoreCreditCategory", optional: true
|
|
18
|
-
belongs_to :credit_type, class_name:
|
|
18
|
+
belongs_to :credit_type, class_name: "Spree::StoreCreditType", foreign_key: "type_id", optional: true
|
|
19
19
|
has_many :store_credit_events
|
|
20
20
|
|
|
21
21
|
validates :user_id, :category_id, :type_id, :created_by_id, :currency, presence: true
|
|
22
|
-
validates :amount, numericality: {
|
|
23
|
-
validates :amount_used, numericality: {
|
|
22
|
+
validates :amount, numericality: {greater_than: 0}
|
|
23
|
+
validates :amount_used, numericality: {greater_than_or_equal_to: 0}
|
|
24
24
|
validate :amount_used_less_than_or_equal_to_amount
|
|
25
25
|
validate :amount_authorized_less_than_or_equal_to_amount
|
|
26
26
|
|
|
27
27
|
delegate :name, to: :category, prefix: true
|
|
28
28
|
delegate :email, to: :created_by, prefix: true
|
|
29
29
|
|
|
30
|
-
scope :order_by_priority, -> { includes(:credit_type).order(
|
|
30
|
+
scope :order_by_priority, -> { includes(:credit_type).order("spree_store_credit_types.priority ASC") }
|
|
31
31
|
|
|
32
32
|
after_save :store_event
|
|
33
33
|
before_validation :associate_credit_type
|
|
@@ -38,6 +38,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
38
38
|
attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :store_credit_reason
|
|
39
39
|
|
|
40
40
|
extend Spree::DisplayMoney
|
|
41
|
+
|
|
41
42
|
money_methods :amount, :amount_used, :amount_authorized
|
|
42
43
|
|
|
43
44
|
alias_method :display_number, :category_name
|
|
@@ -51,7 +52,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
def amount_remaining
|
|
54
|
-
return 0.0
|
|
55
|
+
return BigDecimal("0.0") if invalidated?
|
|
55
56
|
amount - amount_used - amount_authorized
|
|
56
57
|
end
|
|
57
58
|
|
|
@@ -83,9 +84,9 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
83
84
|
|
|
84
85
|
def validate_authorization(amount, order_currency)
|
|
85
86
|
if amount_remaining.to_d < amount.to_d
|
|
86
|
-
errors.add(:base, I18n.t(
|
|
87
|
+
errors.add(:base, I18n.t("spree.store_credit.insufficient_funds"))
|
|
87
88
|
elsif currency != order_currency
|
|
88
|
-
errors.add(:base, I18n.t(
|
|
89
|
+
errors.add(:base, I18n.t("spree.store_credit.currency_mismatch"))
|
|
89
90
|
end
|
|
90
91
|
errors.blank?
|
|
91
92
|
end
|
|
@@ -96,7 +97,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
96
97
|
|
|
97
98
|
if amount <= auth_event.amount
|
|
98
99
|
if currency != order_currency
|
|
99
|
-
errors.add(:base, I18n.t(
|
|
100
|
+
errors.add(:base, I18n.t("spree.store_credit.currency_mismatch"))
|
|
100
101
|
false
|
|
101
102
|
else
|
|
102
103
|
update!({
|
|
@@ -111,13 +112,13 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
111
112
|
authorization_code
|
|
112
113
|
end
|
|
113
114
|
else
|
|
114
|
-
errors.add(:base, I18n.t(
|
|
115
|
+
errors.add(:base, I18n.t("spree.store_credit.insufficient_authorized_amount"))
|
|
115
116
|
false
|
|
116
117
|
end
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
def void(authorization_code, options = {})
|
|
120
|
-
if auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:)
|
|
121
|
+
if (auth_event = store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code:))
|
|
121
122
|
update!({
|
|
122
123
|
action: VOID_ACTION,
|
|
123
124
|
action_amount: auth_event.amount,
|
|
@@ -128,7 +129,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
128
129
|
})
|
|
129
130
|
true
|
|
130
131
|
else
|
|
131
|
-
errors.add(:base, I18n.t(
|
|
132
|
+
errors.add(:base, I18n.t("spree.store_credit.unable_to_void", auth_code: authorization_code))
|
|
132
133
|
false
|
|
133
134
|
end
|
|
134
135
|
end
|
|
@@ -138,7 +139,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
138
139
|
capture_event = store_credit_events.find_by(action: CAPTURE_ACTION, authorization_code:)
|
|
139
140
|
|
|
140
141
|
if currency != order_currency # sanity check to make sure the order currency hasn't changed since the auth
|
|
141
|
-
errors.add(:base, I18n.t(
|
|
142
|
+
errors.add(:base, I18n.t("spree.store_credit.currency_mismatch"))
|
|
142
143
|
false
|
|
143
144
|
elsif capture_event && amount <= capture_event.amount
|
|
144
145
|
action_attributes = {
|
|
@@ -150,7 +151,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
150
151
|
create_credit_record(amount, action_attributes)
|
|
151
152
|
true
|
|
152
153
|
else
|
|
153
|
-
errors.add(:base, I18n.t(
|
|
154
|
+
errors.add(:base, I18n.t("spree.store_credit.unable_to_credit", auth_code: authorization_code))
|
|
154
155
|
false
|
|
155
156
|
end
|
|
156
157
|
end
|
|
@@ -162,10 +163,10 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
162
163
|
def generate_authorization_code
|
|
163
164
|
[
|
|
164
165
|
id,
|
|
165
|
-
|
|
166
|
-
Time.current.utc.strftime(
|
|
166
|
+
"SC",
|
|
167
|
+
Time.current.utc.strftime("%Y%m%d%H%M%S%6N"),
|
|
167
168
|
SecureRandom.uuid
|
|
168
|
-
].join(
|
|
169
|
+
].join("-")
|
|
169
170
|
end
|
|
170
171
|
|
|
171
172
|
def editable?
|
|
@@ -198,7 +199,7 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
198
199
|
self.invalidated_at = Time.current
|
|
199
200
|
save
|
|
200
201
|
else
|
|
201
|
-
errors.add(:invalidated_at, I18n.t(
|
|
202
|
+
errors.add(:invalidated_at, I18n.t("spree.store_credit.errors.cannot_invalidate_uncaptured_authorization"))
|
|
202
203
|
false
|
|
203
204
|
end
|
|
204
205
|
end
|
|
@@ -258,25 +259,25 @@ class Spree::StoreCredit < Spree::PaymentSource
|
|
|
258
259
|
return true if amount_used.nil?
|
|
259
260
|
|
|
260
261
|
if amount_used > amount
|
|
261
|
-
errors.add(:amount_used, I18n.t(
|
|
262
|
+
errors.add(:amount_used, I18n.t("spree.admin.store_credits.errors.amount_used_cannot_be_greater"))
|
|
262
263
|
end
|
|
263
264
|
end
|
|
264
265
|
|
|
265
266
|
def amount_authorized_less_than_or_equal_to_amount
|
|
266
267
|
if (amount_used + amount_authorized) > amount
|
|
267
|
-
errors.add(:amount_authorized, I18n.t(
|
|
268
|
+
errors.add(:amount_authorized, I18n.t("spree.admin.store_credits.errors.amount_authorized_exceeds_total_credit"))
|
|
268
269
|
end
|
|
269
270
|
end
|
|
270
271
|
|
|
271
272
|
def validate_category_unchanged
|
|
272
273
|
if category_id_changed?
|
|
273
|
-
errors.add(:category, I18n.t(
|
|
274
|
+
errors.add(:category, I18n.t("spree.admin.store_credits.errors.cannot_be_modified"))
|
|
274
275
|
end
|
|
275
276
|
end
|
|
276
277
|
|
|
277
278
|
def validate_no_amount_used
|
|
278
279
|
if amount_used > 0
|
|
279
|
-
errors.add(:amount_used,
|
|
280
|
+
errors.add(:amount_used, "is greater than zero. Can not delete store credit")
|
|
280
281
|
throw :abort
|
|
281
282
|
end
|
|
282
283
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Spree::StoreCreditCategory < Spree::Base
|
|
4
|
-
GIFT_CARD =
|
|
5
|
-
REIMBURSEMENT =
|
|
4
|
+
GIFT_CARD = "Gift Card"
|
|
5
|
+
REIMBURSEMENT = "Reimbursement"
|
|
6
6
|
|
|
7
7
|
class_attribute :non_expiring_credit_types
|
|
8
8
|
self.non_expiring_credit_types = [Spree::StoreCreditType::NON_EXPIRING]
|
|
@@ -7,15 +7,15 @@ module Spree
|
|
|
7
7
|
|
|
8
8
|
belongs_to :store_credit, optional: true
|
|
9
9
|
belongs_to :originator, polymorphic: true, optional: true
|
|
10
|
-
belongs_to :store_credit_reason, class_name:
|
|
10
|
+
belongs_to :store_credit_reason, class_name: "Spree::StoreCreditReason", inverse_of: :store_credit_events, optional: true
|
|
11
11
|
|
|
12
|
-
validates :store_credit_reason, presence: {
|
|
12
|
+
validates :store_credit_reason, presence: {if: :action_requires_reason?}
|
|
13
13
|
|
|
14
14
|
NON_EXPOSED_ACTIONS = [Spree::StoreCredit::ELIGIBLE_ACTION, Spree::StoreCredit::AUTHORIZE_ACTION]
|
|
15
15
|
|
|
16
16
|
scope :exposed_events, -> { exposable_actions.not_invalidated }
|
|
17
17
|
scope :exposable_actions, -> { where.not(action: NON_EXPOSED_ACTIONS) }
|
|
18
|
-
scope :not_invalidated, -> { joins(:store_credit).where(spree_store_credits: {
|
|
18
|
+
scope :not_invalidated, -> { joins(:store_credit).where(spree_store_credits: {invalidated_at: nil}) }
|
|
19
19
|
scope :chronological, -> { order(:created_at) }
|
|
20
20
|
scope :reverse_chronological, -> { order(created_at: :desc) }
|
|
21
21
|
|
|
@@ -34,15 +34,15 @@ module Spree
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def display_amount
|
|
37
|
-
Spree::Money.new(amount, {
|
|
37
|
+
Spree::Money.new(amount, {currency:})
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def display_user_total_amount
|
|
41
|
-
Spree::Money.new(user_total_amount, {
|
|
41
|
+
Spree::Money.new(user_total_amount, {currency:})
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def display_remaining_amount
|
|
45
|
-
Spree::Money.new(amount_remaining, {
|
|
45
|
+
Spree::Money.new(amount_remaining, {currency:})
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def display_event_date
|
|
@@ -4,7 +4,7 @@ class Spree::StoreCreditReason < Spree::Base
|
|
|
4
4
|
scope :active, -> { where(active: true) }
|
|
5
5
|
default_scope -> { order(arel_table[:name].lower) }
|
|
6
6
|
|
|
7
|
-
validates :name, presence: true, uniqueness: {
|
|
7
|
+
validates :name, presence: true, uniqueness: {case_sensitive: false, allow_blank: true}
|
|
8
8
|
|
|
9
9
|
has_many :store_credit_events, inverse_of: :store_credit_reason
|
|
10
10
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Spree
|
|
4
4
|
class StoreCreditType < Spree::Base
|
|
5
|
-
EXPIRING =
|
|
6
|
-
NON_EXPIRING =
|
|
5
|
+
EXPIRING = "Expiring"
|
|
6
|
+
NON_EXPIRING = "Non-expiring"
|
|
7
7
|
DEFAULT_TYPE_NAME = EXPIRING
|
|
8
|
-
has_many :store_credits, class_name:
|
|
8
|
+
has_many :store_credits, class_name: "Spree::StoreCredit", foreign_key: "type_id"
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -17,7 +17,7 @@ module Spree
|
|
|
17
17
|
# Chooses the current store based on a request.
|
|
18
18
|
# @return [Spree::Store]
|
|
19
19
|
def store
|
|
20
|
-
server_name = @request.env[
|
|
20
|
+
server_name = @request.env["SERVER_NAME"]
|
|
21
21
|
|
|
22
22
|
# We select a store which either matches our server name, or is default.
|
|
23
23
|
# We sort by `default ASC` so that a store matching SERVER_NAME will come
|
|
@@ -11,15 +11,15 @@ module Spree
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
validates :name, presence: true
|
|
14
|
-
validates :name, uniqueness: {
|
|
14
|
+
validates :name, uniqueness: {case_sensitive: true, unless: :deleted_at}
|
|
15
15
|
|
|
16
16
|
has_many :tax_rate_tax_categories,
|
|
17
|
-
class_name:
|
|
17
|
+
class_name: "Spree::TaxRateTaxCategory",
|
|
18
18
|
dependent: :destroy,
|
|
19
19
|
inverse_of: :tax_category
|
|
20
20
|
has_many :tax_rates,
|
|
21
21
|
through: :tax_rate_tax_categories,
|
|
22
|
-
class_name:
|
|
22
|
+
class_name: "Spree::TaxRate",
|
|
23
23
|
inverse_of: :tax_categories
|
|
24
24
|
|
|
25
25
|
after_save :ensure_one_default
|