spree_cm_commissioner 2.13.7 → 2.14.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/Gemfile.lock +1 -1
- data/app/assets/javascripts/spree_cm_commissioner/backend.js +0 -1
- data/app/assets/stylesheets/spree_cm_commissioner/backend/calendar.scss +0 -39
- data/app/controllers/concerns/spree/admin/rates_availability_cells.rb +16 -0
- data/app/controllers/concerns/spree/api/v2/product_list_includes_decorator.rb +1 -0
- data/app/controllers/spree/admin/guests_controller.rb +2 -1
- data/app/controllers/spree/admin/integrations_controller.rb +16 -7
- data/app/controllers/spree/admin/inventory_items_controller.rb +33 -62
- data/app/controllers/spree/admin/product_option_types_controller.rb +88 -0
- data/app/controllers/spree/admin/rate_plans_controller.rb +125 -0
- data/app/controllers/spree/admin/rates_availabilities_controller.rb +142 -0
- data/app/controllers/spree/admin/stock_managements_controller.rb +1 -53
- data/app/controllers/spree/api/switch_cm/base_controller.rb +109 -0
- data/app/controllers/spree/api/switch_cm/tokens_controller.rb +68 -0
- data/app/controllers/spree/api/switch_cm/xml/availabilities_controller.rb +39 -0
- data/app/controllers/spree/api/switch_cm/xml/base_controller.rb +37 -0
- data/app/controllers/spree/api/switch_cm/xml/reservation_summaries_controller.rb +28 -0
- data/app/controllers/spree/api/switch_cm/xml/reservations_controller.rb +57 -0
- data/app/controllers/spree/api/switch_cm/xml/room_rate_availabilities_controller.rb +56 -0
- data/app/controllers/spree/api/switch_cm/xml/room_rates_controller.rb +45 -0
- data/app/controllers/spree/api/v2/operator/guests_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/accommodations/variants_controller.rb +31 -5
- data/app/controllers/spree/api/v2/storefront/inventory_items_controller.rb +2 -2
- data/app/controllers/spree/api/v2/tenant/intercity_taxi/draft_orders_controller.rb +0 -1
- data/app/factory/spree_cm_commissioner/order_telegram_message_factory.rb +1 -1
- data/app/finders/spree_cm_commissioner/accommodations/find.rb +10 -8
- data/app/finders/spree_cm_commissioner/accommodations/find_variant.rb +5 -11
- data/app/finders/spree_cm_commissioner/rates_availabilities/find_bookings.rb +116 -0
- data/app/helpers/spree_cm_commissioner/admin/inventory_items_helper.rb +36 -0
- data/app/helpers/spree_cm_commissioner/admin/rates_availabilities_helper.rb +247 -0
- data/app/interactors/spree_cm_commissioner/intercity_taxi_order_creator.rb +0 -1
- data/app/jobs/spree_cm_commissioner/option_type_variants_public_metadata_updater_job.rb +1 -0
- data/app/jobs/spree_cm_commissioner/option_value_variants_public_metadata_updater_job.rb +1 -0
- data/app/jobs/spree_cm_commissioner/product_variants_public_metadata_updater_job.rb +12 -0
- data/app/models/concerns/spree_cm_commissioner/kyc_bitwise.rb +4 -0
- data/app/models/concerns/spree_cm_commissioner/line_item_durationable.rb +1 -10
- data/app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb +33 -3
- data/app/models/concerns/spree_cm_commissioner/line_item_rate_plannable.rb +55 -0
- data/app/models/concerns/spree_cm_commissioner/line_item_transitable.rb +0 -16
- data/app/models/concerns/spree_cm_commissioner/option_type_attr_type.rb +22 -4
- data/app/models/concerns/spree_cm_commissioner/rate_plan_options_concern.rb +62 -0
- data/app/models/concerns/spree_cm_commissioner/variant_options_concern.rb +12 -0
- data/app/models/concerns/spree_cm_commissioner/variant_rate_plannable.rb +81 -0
- data/app/models/spree_cm_commissioner/address_decorator.rb +2 -0
- data/app/models/spree_cm_commissioner/configuration.rb +0 -6
- data/app/models/spree_cm_commissioner/exports/import_order_guests_csv.rb +2 -1
- data/app/models/spree_cm_commissioner/exports/operator_guest_json_gzip.rb +8 -2
- data/app/models/spree_cm_commissioner/guest.rb +1 -1
- data/app/models/spree_cm_commissioner/integration.rb +15 -0
- data/app/models/spree_cm_commissioner/integrations/switch_cm.rb +96 -0
- data/app/models/spree_cm_commissioner/inventory_item.rb +32 -3
- data/app/models/spree_cm_commissioner/line_item_decorator.rb +7 -7
- data/app/models/spree_cm_commissioner/maintenance_tasks/cache_invalidation.rb +20 -4
- data/app/models/spree_cm_commissioner/maintenance_tasks/event.rb +3 -2
- data/app/models/spree_cm_commissioner/option_type_decorator.rb +2 -1
- data/app/models/spree_cm_commissioner/option_value_decorator.rb +3 -0
- data/app/models/spree_cm_commissioner/option_value_rate_plan.rb +12 -0
- data/app/models/spree_cm_commissioner/order_decorator.rb +1 -0
- data/app/models/spree_cm_commissioner/price_decorator.rb +13 -0
- data/app/models/spree_cm_commissioner/product_decorator.rb +18 -2
- data/app/models/spree_cm_commissioner/product_option_type_decorator.rb +42 -0
- data/app/models/spree_cm_commissioner/rate_plan.rb +139 -0
- data/app/models/spree_cm_commissioner/rate_plan_options.rb +36 -0
- data/app/models/spree_cm_commissioner/rate_restriction.rb +45 -0
- data/app/models/spree_cm_commissioner/taxon_decorator.rb +5 -2
- data/app/models/spree_cm_commissioner/variant_decorator.rb +36 -5
- data/app/models/spree_cm_commissioner/variant_options.rb +3 -2
- data/app/models/spree_cm_commissioner/vendor_decorator.rb +1 -0
- data/app/overrides/spree/admin/option_types/_form/checkbox.html.erb.deface +0 -8
- data/app/overrides/spree/admin/option_types/_form/name.html.erb.deface +1 -1
- data/app/overrides/spree/admin/products/_filters/vendor_filter.html.erb.deface +6 -0
- data/app/overrides/spree/admin/shared/_product_tabs/rates_availabilities.html.erb.deface +8 -0
- data/app/overrides/spree/admin/shared/_product_tabs/stock_managements.html.erb.deface +1 -1
- data/app/overrides/spree/admin/variants/index/discontinued_badge.html.erb.deface +13 -0
- data/app/overrides/spree/admin/variants/index/option_types_empty_state_link.html.erb.deface +3 -0
- data/app/overrides/spree/admin/variants/index/option_types_summary.html.erb.deface +24 -0
- data/app/presenters/spree/variants/visible_options_presenter.rb +34 -1
- data/app/queries/spree_cm_commissioner/multi_leg_trips_query.rb +40 -22
- data/app/queries/spree_cm_commissioner/single_leg_trips_query.rb +28 -14
- data/app/request_schemas/spree_cm_commissioner/intercity_taxi_draft_order_update_schema.rb +0 -1
- data/app/serializers/spree/v2/storefront/line_item_serializer_decorator.rb +2 -0
- data/app/serializers/spree/v2/storefront/option_type_serializer_decorator.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_option_type_serializer.rb +15 -0
- data/app/serializers/spree/v2/storefront/product_serializer_decorator.rb +15 -0
- data/app/serializers/spree/v2/tenant/line_item_serializer.rb +1 -1
- data/app/serializers/spree/v2/tenant/option_type_serializer.rb +1 -1
- data/app/serializers/spree_cm_commissioner/v2/operator/dynamic_field_option_serializer.rb +9 -0
- data/app/serializers/spree_cm_commissioner/v2/operator/dynamic_field_serializer.rb +11 -0
- data/app/serializers/spree_cm_commissioner/v2/operator/guest_dynamic_field_serializer.rb +14 -0
- data/app/serializers/spree_cm_commissioner/v2/operator/guest_serializer.rb +1 -0
- data/app/serializers/spree_cm_commissioner/v2/storefront/accommodation_variant_serializer.rb +44 -0
- data/app/serializers/spree_cm_commissioner/v2/storefront/inventory_item_serializer.rb +4 -4
- data/app/serializers/spree_cm_commissioner/v2/storefront/rate_plan_serializer.rb +16 -0
- data/app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_item_availability.rb +1 -1
- data/app/services/spree_cm_commissioner/integrations/larryta/polling/sync_item_availability.rb +1 -1
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/accept_push.rb +111 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/accommodation_lock.rb +43 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/apply_updates.rb +133 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/availability_snapshot.rb +127 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/inventory_update.rb +35 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/pushed_nights.rb +82 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/unseen_room_nights.rb +49 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/inventory/validate_updates.rb +153 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/reservations/feed.rb +209 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/reservations/mark_seen.rb +62 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/reservations/reservation.rb +171 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/room_catalog.rb +88 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/sync_manager.rb +16 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/sync_strategies/full_sync_strategy.rb +39 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/sync_strategies/incremental_sync_strategy.rb +51 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/xml/availability_parser.rb +103 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/xml/push_response.rb +45 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/xml/reservation_serializer.rb +83 -0
- data/app/services/spree_cm_commissioner/integrations/switch_cm/xml/response_builder.rb +19 -0
- data/app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_item_availability.rb +1 -1
- data/app/services/spree_cm_commissioner/intercity_taxi_order/update.rb +1 -3
- data/app/services/spree_cm_commissioner/inventory_items/bulk_adjust_quantities_by_variant.rb +4 -0
- data/app/services/spree_cm_commissioner/inventory_items/reset.rb +4 -0
- data/app/services/spree_cm_commissioner/rate_plans/save.rb +65 -0
- data/app/services/spree_cm_commissioner/rates_availabilities/bulk_update.rb +225 -0
- data/app/services/spree_cm_commissioner/reschedule_requests/split_line_item.rb +5 -0
- data/app/services/spree_cm_commissioner/room_types/create.rb +87 -0
- data/app/services/spree_cm_commissioner/room_types/update_properties.rb +32 -0
- data/app/services/spree_cm_commissioner/room_types.rb +40 -0
- data/app/services/spree_cm_commissioner/route_prices/update_price_range.rb +3 -1
- data/app/services/spree_cm_commissioner/trips/search.rb +14 -7
- data/app/services/spree_cm_commissioner/trips/update_single_leg.rb +5 -1
- data/app/views/spree/admin/guests/_check_in_status.html.erb +28 -22
- data/app/views/spree/admin/guests/edit.html.erb +29 -26
- data/app/views/spree/admin/integrations/_form.html.erb +4 -0
- data/app/views/spree/admin/integrations/_switch_cm_fields.html.erb +53 -0
- data/app/views/spree/admin/inventory_items/_details.html.erb +56 -0
- data/app/views/spree/admin/product_option_types/index.html.erb +79 -0
- data/app/views/spree/admin/rate_plans/_form.html.erb +134 -0
- data/app/views/spree/admin/rate_plans/_order_form.html.erb +37 -0
- data/app/views/spree/admin/rates_availabilities/_block.html.erb +34 -0
- data/app/views/spree/admin/rates_availabilities/_bookings.html.erb +52 -0
- data/app/views/spree/admin/rates_availabilities/_filters.html.erb +48 -0
- data/app/views/spree/admin/rates_availabilities/_legend.html.erb +27 -0
- data/app/views/spree/admin/rates_availabilities/_list_pages.html.erb +14 -0
- data/app/views/spree/admin/rates_availabilities/_modal_header.html.erb +11 -0
- data/app/views/spree/admin/rates_availabilities/_names.html.erb +62 -0
- data/app/views/spree/admin/rates_availabilities/_script.html.erb +676 -0
- data/app/views/spree/admin/rates_availabilities/_styles.html.erb +159 -0
- data/app/views/spree/admin/rates_availabilities/index.html.erb +112 -0
- data/app/views/spree/admin/shared/sub_menu/_homepage.html.erb +0 -1
- data/app/views/spree/admin/stock_managements/_header.html.erb +0 -14
- data/app/views/spree/admin/stock_managements/_inventory_item_stats.html.erb +28 -0
- data/app/views/spree/admin/stock_managements/index.html.erb +1 -56
- data/config/initializers/spree_permitted_attributes.rb +1 -0
- data/config/locales/en.yml +241 -3
- data/config/locales/km.yml +241 -4
- data/config/routes.rb +36 -17
- data/db/migrate/20260928000000_add_oauth_application_id_to_cm_integrations.rb +5 -0
- data/db/migrate/20260929000000_create_cm_rate_plans.rb +22 -0
- data/db/migrate/20260929000001_add_rate_plan_to_spree_prices.rb +24 -0
- data/db/migrate/20260929000002_add_rate_plan_to_spree_line_items.rb +7 -0
- data/db/migrate/20260929000003_create_cm_option_value_rate_plans.rb +16 -0
- data/db/migrate/20261009000000_create_cm_rate_restrictions.rb +29 -0
- data/db/migrate/20261013000001_add_hidden_and_presentation_to_spree_product_option_types.rb +6 -0
- data/db/migrate/20261013000002_move_hidden_from_spree_option_types_to_product_option_types.rb +36 -0
- data/db/migrate/20261016000001_add_index_to_spree_line_items_number.rb +8 -0
- data/lib/spree_cm_commissioner/booking_dates.rb +43 -0
- data/lib/spree_cm_commissioner/calendar_event.rb +0 -25
- data/lib/spree_cm_commissioner/rate.rb +74 -0
- data/lib/spree_cm_commissioner/rate_closings.rb +48 -0
- data/lib/spree_cm_commissioner/rates_availability_grid.rb +113 -0
- data/lib/spree_cm_commissioner/stay_price.rb +30 -0
- data/lib/spree_cm_commissioner/stay_prices.rb +58 -0
- data/lib/spree_cm_commissioner/test_helper/factories/integration_factory.rb +6 -0
- data/lib/spree_cm_commissioner/test_helper/factories/option_type_factory.rb +6 -0
- data/lib/spree_cm_commissioner/test_helper/factories/option_value_rate_plan_factory.rb +6 -0
- data/lib/spree_cm_commissioner/test_helper/factories/rate_plan_factory.rb +14 -0
- data/lib/spree_cm_commissioner/test_helper/factories/variant_factory.rb +9 -0
- data/lib/spree_cm_commissioner/version.rb +1 -1
- data/lib/spree_cm_commissioner.rb +6 -0
- metadata +94 -32
- data/app/assets/javascripts/spree_cm_commissioner/calendar.js +0 -59
- data/app/controllers/spree/admin/calendars/base_controller.rb +0 -27
- data/app/controllers/spree/admin/calendars/orders_controller.rb +0 -27
- data/app/controllers/spree/admin/homepage_feed_controller.rb +0 -36
- data/app/controllers/spree/admin/metafields_controller.rb +0 -69
- data/app/models/concerns/spree_cm_commissioner/metafield.rb +0 -15
- data/app/models/spree_cm_commissioner/homepage_feed.rb +0 -4
- data/app/overrides/spree/admin/shared/_main_menu/sidebar_calendars.html.erb.deface +0 -5
- data/app/overrides/spree/admin/shared/_product_tabs/metafields.html.erb.deface +0 -15
- data/app/serializers/spree_cm_commissioner/v2/storefront/taxon_include_product_serializer.rb +0 -13
- data/app/serializers/spree_cm_commissioner/v2/storefront/vendor_include_product_serializer.rb +0 -14
- data/app/services/spree_cm_commissioner/feed/taxon_include_product.rb +0 -20
- data/app/services/spree_cm_commissioner/feed/taxon_product.rb +0 -54
- data/app/services/spree_cm_commissioner/feed/vendor_include_product.rb +0 -20
- data/app/services/spree_cm_commissioner/feed/vendor_product.rb +0 -52
- data/app/services/spree_cm_commissioner/homepage_data_loader.rb +0 -112
- data/app/services/spree_cm_commissioner/metafields/product_metadata_service.rb +0 -32
- data/app/views/shared/_calendar.html.erb +0 -27
- data/app/views/shared/calendar/_order_popover.html.erb +0 -18
- data/app/views/shared/calendar/_orders_sidebar.html.erb +0 -41
- data/app/views/spree/admin/calendars/orders/index.html.erb +0 -22
- data/app/views/spree/admin/homepage_feed/_form.html.erb +0 -24
- data/app/views/spree/admin/homepage_feed/edit.html.erb +0 -17
- data/app/views/spree/admin/inventory_items/prices.html.erb +0 -43
- data/app/views/spree/admin/inventory_items/stocks.html.erb +0 -34
- data/app/views/spree/admin/metafields/_private_metafields_form.html.erb +0 -71
- data/app/views/spree/admin/metafields/_public_metafields_form.html.erb +0 -64
- data/app/views/spree/admin/metafields/edit.html.erb +0 -27
- data/app/views/spree/admin/shared/sub_menu/_calendar.html.erb +0 -3
- data/app/views/spree/admin/stock_managements/calendar.html.erb +0 -310
|
@@ -6,13 +6,14 @@ module SpreeCmCommissioner
|
|
|
6
6
|
base.include SpreeCmCommissioner::ParameterizeName
|
|
7
7
|
base.include SpreeCmCommissioner::OptionTypeAttrType
|
|
8
8
|
|
|
9
|
-
base.enum kind: %i[variant product vendor vehicle]
|
|
9
|
+
base.enum kind: %i[variant product vendor vehicle rate_plan]
|
|
10
10
|
|
|
11
11
|
base.validates :name, presence: true
|
|
12
12
|
|
|
13
13
|
base.validate :kind_has_updated, on: :update, if: :kind_changed?
|
|
14
14
|
|
|
15
15
|
base.has_many :variants, through: :products
|
|
16
|
+
base.has_many :rate_plans, -> { distinct }, through: :option_values, class_name: 'SpreeCmCommissioner::RatePlan'
|
|
16
17
|
|
|
17
18
|
base.has_many :vehicle_type_option_types,
|
|
18
19
|
class_name: 'SpreeCmCommissioner::VehicleTypeOptionType',
|
|
@@ -7,6 +7,9 @@ module SpreeCmCommissioner
|
|
|
7
7
|
foreign_key: :option_value_id,
|
|
8
8
|
dependent: :destroy
|
|
9
9
|
|
|
10
|
+
base.has_many :option_value_rate_plans, class_name: 'SpreeCmCommissioner::OptionValueRatePlan', dependent: :destroy
|
|
11
|
+
base.has_many :rate_plans, through: :option_value_rate_plans, class_name: 'SpreeCmCommissioner::RatePlan'
|
|
12
|
+
|
|
10
13
|
base.validates :name, presence: true, uniqueness: { scope: :option_type_id, case_sensitive: -> { name_case_sensitive? } }
|
|
11
14
|
|
|
12
15
|
# Ticket types: case-SENSITIVE matching (preserve external API casing)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class OptionValueRatePlan < SpreeCmCommissioner::Base
|
|
3
|
+
belongs_to :rate_plan, class_name: 'SpreeCmCommissioner::RatePlan', inverse_of: :option_value_rate_plans
|
|
4
|
+
belongs_to :option_value, class_name: 'Spree::OptionValue'
|
|
5
|
+
|
|
6
|
+
validates :option_value_id, uniqueness: { scope: :rate_plan_id }
|
|
7
|
+
|
|
8
|
+
# Adding or removing a value on a saved rate plan doesn't save the rate plan, so refresh its cache here.
|
|
9
|
+
# Skipped when the rate plan itself is being destroyed.
|
|
10
|
+
after_commit -> { rate_plan&.cache_options! }, unless: :destroyed_by_association
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -12,6 +12,7 @@ module SpreeCmCommissioner
|
|
|
12
12
|
base.include SpreeCmCommissioner::TicketTransferable
|
|
13
13
|
base.include SpreeCmCommissioner::OrderQrCodeable
|
|
14
14
|
base.include SpreeCmCommissioner::OrderPrepaidPayment
|
|
15
|
+
base.include SpreeCmCommissioner::Integrations::IntegrationMappable
|
|
15
16
|
|
|
16
17
|
base.before_create :link_by_phone_number
|
|
17
18
|
base.before_create :associate_customer
|
|
@@ -2,6 +2,12 @@ module SpreeCmCommissioner
|
|
|
2
2
|
module PriceDecorator
|
|
3
3
|
def self.prepended(base)
|
|
4
4
|
base.belongs_to :inventory_item, class_name: 'SpreeCmCommissioner::InventoryItem', inverse_of: :prices, optional: true
|
|
5
|
+
base.belongs_to :rate_plan, class_name: 'SpreeCmCommissioner::RatePlan', inverse_of: :prices, optional: true
|
|
6
|
+
|
|
7
|
+
# The variant's own rows (base and per-date), leaving out rate plans' rows.
|
|
8
|
+
base.scope :without_rate_plan, -> { where(rate_plan_id: nil) }
|
|
9
|
+
|
|
10
|
+
base.validate :validate_rate_plan, if: :rate_plan
|
|
5
11
|
base.after_commit :trigger_event_price_range_refresh, if: :should_trigger_event_price_range_refresh?
|
|
6
12
|
end
|
|
7
13
|
|
|
@@ -9,6 +15,13 @@ module SpreeCmCommissioner
|
|
|
9
15
|
(saved_change_to_amount? || saved_change_to_currency?) && event_id.present?
|
|
10
16
|
end
|
|
11
17
|
|
|
18
|
+
# A derived rate plan is calculated from the variant's price, so it takes only date rows, each overriding
|
|
19
|
+
# that date's calculated price. A base row would override every date, which is what an independent one is for.
|
|
20
|
+
def validate_rate_plan
|
|
21
|
+
errors.add(:rate_plan, :invalid) if rate_plan.variant_id != variant_id
|
|
22
|
+
errors.add(:rate_plan, :invalid) if rate_plan.kind_derived? && inventory_item_id.nil?
|
|
23
|
+
end
|
|
24
|
+
|
|
12
25
|
def event_id
|
|
13
26
|
variant&.product&.event_id
|
|
14
27
|
end
|
|
@@ -4,7 +4,6 @@ module SpreeCmCommissioner
|
|
|
4
4
|
def self.prepended(base)
|
|
5
5
|
base.include SpreeCmCommissioner::ProductType
|
|
6
6
|
base.include SpreeCmCommissioner::KycBitwise
|
|
7
|
-
base.include SpreeCmCommissioner::Metafield
|
|
8
7
|
base.include SpreeCmCommissioner::TenantUpdatable
|
|
9
8
|
base.include SpreeCmCommissioner::ServiceType
|
|
10
9
|
base.include SpreeCmCommissioner::ServiceRecommendations
|
|
@@ -26,6 +25,9 @@ module SpreeCmCommissioner
|
|
|
26
25
|
base.has_many :promoted_option_types, -> { where(promoted: true).order(:position) },
|
|
27
26
|
through: :product_option_types, source: :option_type
|
|
28
27
|
|
|
28
|
+
base.has_many :variant_kind_product_option_types, -> { joins(:option_type).where(spree_option_types: { kind: :variant }) },
|
|
29
|
+
class_name: 'Spree::ProductOptionType', inverse_of: :product
|
|
30
|
+
|
|
29
31
|
base.has_many :option_values, through: :option_types
|
|
30
32
|
base.has_many :prices_including_master, lambda {
|
|
31
33
|
order('spree_variants.position, spree_variants.id, currency')
|
|
@@ -135,7 +137,7 @@ module SpreeCmCommissioner
|
|
|
135
137
|
base.validate :product_type_unchanged, on: :update
|
|
136
138
|
base.validates :commission_rate, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }, allow_nil: true
|
|
137
139
|
|
|
138
|
-
base.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status vendor_id short_name]
|
|
140
|
+
base.whitelisted_ransackable_attributes = %w[description name slug discontinue_on status vendor_id short_name event_id]
|
|
139
141
|
|
|
140
142
|
base.store_public_metadata :open_dated_validity_days, :integer, default: 90
|
|
141
143
|
base.store_public_metadata :enable_inventory_hold, :boolean, default: false
|
|
@@ -185,6 +187,20 @@ module SpreeCmCommissioner
|
|
|
185
187
|
"#{Spree::Store.default.formatted_url}/tickets/#{slug}"
|
|
186
188
|
end
|
|
187
189
|
|
|
190
|
+
# Same default stay as Vendor#hotel_url so the dashboard's room preview opens on bookable dates.
|
|
191
|
+
def room_url
|
|
192
|
+
checkin_date = Date.tomorrow
|
|
193
|
+
query = {
|
|
194
|
+
roomQty: 1,
|
|
195
|
+
numberOfAdults: 2,
|
|
196
|
+
numberOfChildren: 0,
|
|
197
|
+
checkinDate: checkin_date.iso8601,
|
|
198
|
+
checkoutDate: (checkin_date + 2.days).iso8601
|
|
199
|
+
}.to_query
|
|
200
|
+
|
|
201
|
+
"#{Spree::Store.default.formatted_url}/rooms/#{slug}?#{query}"
|
|
202
|
+
end
|
|
203
|
+
|
|
188
204
|
def action_button
|
|
189
205
|
return :request_to_book if need_confirmation?
|
|
190
206
|
return :reserve if free?
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module ProductOptionTypeDecorator
|
|
3
|
+
def self.prepended(base)
|
|
4
|
+
base.delegate :event, to: :product, allow_nil: true
|
|
5
|
+
|
|
6
|
+
base.before_validation :normalize_presentation
|
|
7
|
+
base.validates :presentation, length: { maximum: 100 }
|
|
8
|
+
|
|
9
|
+
# options_text is cached on each variant's public_metadata, so per-product display changes must re-cache it.
|
|
10
|
+
# One declaration: Rails keeps only the last after_commit registered for the same method name.
|
|
11
|
+
base.after_commit :refresh_variants_options_text, on: %i[update destroy], if: :refresh_variants_options_text?
|
|
12
|
+
|
|
13
|
+
# Create maintaining task to purge product related caches
|
|
14
|
+
base.after_commit { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: product) }
|
|
15
|
+
|
|
16
|
+
# App opens the event page, not the ticket/product page, so the event's cache must be purged too.
|
|
17
|
+
base.after_commit { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: event) if event.present? }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def display_presentation
|
|
21
|
+
presentation.presence || option_type&.presentation
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def normalize_presentation
|
|
27
|
+
self.presentation = presentation.to_s.strip.presence
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def refresh_variants_options_text?
|
|
31
|
+
destroyed? || saved_change_to_hidden? || saved_change_to_presentation? || saved_change_to_position?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def refresh_variants_options_text
|
|
35
|
+
SpreeCmCommissioner::ProductVariantsPublicMetadataUpdaterJob.perform_later(product_id: product_id)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
unless Spree::ProductOptionType.included_modules.include?(SpreeCmCommissioner::ProductOptionTypeDecorator)
|
|
41
|
+
Spree::ProductOptionType.prepend(SpreeCmCommissioner::ProductOptionTypeDecorator)
|
|
42
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
# One way of selling a variant's shared stock on different terms, e.g. a hotel room as room only,
|
|
3
|
+
# breakfast included or non-refundable. Holds count by variant, so every rate plan shares its stock.
|
|
4
|
+
#
|
|
5
|
+
# The variant's own prices (`rate_plan_id` NULL) are the base rate, and a line item without a rate
|
|
6
|
+
# plan sells at them. A derived rate plan adjusts them; an independent one has its own price rows and
|
|
7
|
+
# never falls back to the variant's, so a missing rate price can't silently sell at the variant price.
|
|
8
|
+
class RatePlan < SpreeCmCommissioner::Base
|
|
9
|
+
include Spree::Metadata
|
|
10
|
+
include SpreeCmCommissioner::RatePlanOptionsConcern
|
|
11
|
+
|
|
12
|
+
enum kind: { derived: 0, independent: 1 }, _prefix: true
|
|
13
|
+
enum adjustment_type: { percent: 0, amount: 1 }, _prefix: :adjustment
|
|
14
|
+
enum status: { active: 0, archived: 1 }
|
|
15
|
+
|
|
16
|
+
acts_as_list scope: :variant
|
|
17
|
+
|
|
18
|
+
# Touches the variant like Spree::Price does, so API responses cached by variant updated_at pick up rate plan changes.
|
|
19
|
+
belongs_to :variant, class_name: 'Spree::Variant', inverse_of: :rate_plans, optional: false, touch: true
|
|
20
|
+
|
|
21
|
+
has_many :prices, class_name: 'Spree::Price', inverse_of: :rate_plan
|
|
22
|
+
has_many :line_items, class_name: 'Spree::LineItem', inverse_of: :rate_plan, dependent: :restrict_with_error
|
|
23
|
+
has_many :rate_restrictions, class_name: 'SpreeCmCommissioner::RateRestriction', inverse_of: :rate_plan, dependent: :delete_all
|
|
24
|
+
|
|
25
|
+
before_validation -> { self.currency = currency&.upcase }
|
|
26
|
+
# Optional: guests see the terms, so a name is only for what they can't say, e.g. Early bird.
|
|
27
|
+
before_validation -> { self.name = name.presence&.strip }
|
|
28
|
+
before_validation -> { self.code = self.class.next_code(variant) }, on: :create, if: -> { code.blank? && variant }
|
|
29
|
+
|
|
30
|
+
# Spree::Price soft deletes, so `dependent: :destroy` would keep the rows and their foreign key would refuse
|
|
31
|
+
# the delete. Includes rows already soft deleted. After the line items check, so a sold rate plan keeps its.
|
|
32
|
+
before_destroy -> { Spree::Price.with_deleted.where(rate_plan_id: id).delete_all }
|
|
33
|
+
|
|
34
|
+
validates :code, presence: true
|
|
35
|
+
validates :code, uniqueness: { scope: :variant_id }
|
|
36
|
+
validates :kind, presence: true
|
|
37
|
+
validate :code_is_not_the_variant_id
|
|
38
|
+
|
|
39
|
+
validates :adjustment_type, :adjustment_value, presence: true, if: :kind_derived?
|
|
40
|
+
validates :adjustment_type, :adjustment_value, absence: true, unless: :kind_derived?
|
|
41
|
+
validate :adjustment_keeps_price_positive, if: :kind_derived?
|
|
42
|
+
|
|
43
|
+
# The currency of a fixed amount adjustment, so +8 USD isn't applied as +8 KHR. Not a selling
|
|
44
|
+
# currency: percent and independent rate plans sell in any currency they have a price for.
|
|
45
|
+
validates :currency, presence: true, if: -> { kind_derived? && adjustment_amount? }
|
|
46
|
+
validates :currency, absence: true, unless: -> { kind_derived? && adjustment_amount? }
|
|
47
|
+
|
|
48
|
+
# Admins only name a rate plan, as on Booking.com, and get RP1, RP2, … numbered across the hotel, like
|
|
49
|
+
# Booking.com's rate ids: channel manager staff type these, so short beats readable. The hotel is the vendor,
|
|
50
|
+
# or the product when it has none; deleted variants count, so a code is never reused. Not numeric, so never a
|
|
51
|
+
# variant id. Callers creating at once on the same hotel must serialize, as RatePlans::Save does.
|
|
52
|
+
def self.next_code(variant)
|
|
53
|
+
products = Spree::Product.with_deleted
|
|
54
|
+
products = variant.product.vendor_id ? products.where(vendor_id: variant.product.vendor_id) : products.where(id: variant.product_id)
|
|
55
|
+
last = where(variant_id: Spree::Variant.with_deleted.where(product_id: products.select(:id)).select(:id))
|
|
56
|
+
.where("code ~ '^RP[0-9]+$'")
|
|
57
|
+
.maximum(Arel.sql('substring(code from 3)::int'))
|
|
58
|
+
"RP#{last.to_i + 1}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# The admin's name, else its terms ("Breakfast included · Free cancellation"), else its code, as the name is
|
|
62
|
+
# optional. Expects option values with their option types preloaded.
|
|
63
|
+
def display_name
|
|
64
|
+
name.presence ||
|
|
65
|
+
terms.map(&:presentation).join(' · ').presence ||
|
|
66
|
+
I18n.t('rates_availabilities.unnamed_rate_plan', code: code)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Option values (meal plan, cancellation, admin-defined ones) in option type order. Sorted in Ruby so preloaded
|
|
70
|
+
# option values aren't queried again.
|
|
71
|
+
def terms
|
|
72
|
+
option_values.sort_by { |option_value| option_value.option_type.position }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Price for one unit on `date` (nil for products without dates), or nil when none is set.
|
|
76
|
+
def price_for_date(date:, currency:)
|
|
77
|
+
price_amounts(dates: [date], currency: currency).first
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Total for the given dates, or nil when any of them has no price. Variant#rates passes its StayPrices so
|
|
81
|
+
# every rate plan of a room, or of every room on the page, reads one batch of prices.
|
|
82
|
+
def price_for_dates(dates:, currency:, stay_prices: nil)
|
|
83
|
+
amounts = price_amounts(dates: dates, currency: currency, stay_prices: stay_prices)
|
|
84
|
+
amounts.sum unless amounts.any?(&:nil?)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# One price per date, nil where there's none. An independent rate plan reads its own rows; a derived one
|
|
88
|
+
# adjusts the variant's, except on a date it has its own price for.
|
|
89
|
+
def price_amounts(dates:, currency:, stay_prices: nil)
|
|
90
|
+
currency = currency&.upcase
|
|
91
|
+
stay_prices ||= StayPrices.new(variants: kind_independent? ? [] : [variant], rate_plans: [self], dates: dates, currency: currency)
|
|
92
|
+
own = stay_prices.for_rate_plan(self)
|
|
93
|
+
return own.amounts if kind_independent?
|
|
94
|
+
|
|
95
|
+
stay_prices.for_variant(variant).amounts.zip(own.amounts, dates).map do |variant_amount, own_amount, date|
|
|
96
|
+
own.date_price?(date) ? own_amount : adjust(variant_amount, currency)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# One per date: the compare-at on the rate plan's own row for that date, else nil. A derived rate plan only
|
|
101
|
+
# has one on a date it has its own price for. Rate#compare_at_price falls back to the variant's price.
|
|
102
|
+
def compare_at_amounts(dates:, currency:, stay_prices: nil)
|
|
103
|
+
stay_prices ||= StayPrices.new(variants: [], rate_plans: [self], dates: dates, currency: currency)
|
|
104
|
+
own = stay_prices.for_rate_plan(self)
|
|
105
|
+
return own.compare_at_amounts if kind_independent?
|
|
106
|
+
|
|
107
|
+
own.compare_at_amounts.zip(dates).map { |compare_at, date| compare_at if own.date_price?(date) }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
# nil when an amount adjustment is in another currency, so the rate plan isn't sellable in it.
|
|
113
|
+
def adjust(variant_price, price_currency)
|
|
114
|
+
return nil if variant_price.nil?
|
|
115
|
+
return nil if adjustment_amount? && price_currency != currency
|
|
116
|
+
|
|
117
|
+
adjusted = if adjustment_percent?
|
|
118
|
+
variant_price * (100 + adjustment_value) / 100
|
|
119
|
+
else
|
|
120
|
+
variant_price + adjustment_value
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
[adjusted, 0].max.round(2)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# The channel-manager connectivity API sends the variant id as the rate code of the base rate (the
|
|
127
|
+
# variant's own prices), so no rate plan may claim it.
|
|
128
|
+
def code_is_not_the_variant_id
|
|
129
|
+
errors.add(:code, :taken) if variant_id.present? && code == variant_id.to_s
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def adjustment_keeps_price_positive
|
|
133
|
+
return unless adjustment_percent? && adjustment_value.present?
|
|
134
|
+
return if adjustment_value > -100
|
|
135
|
+
|
|
136
|
+
errors.add(:adjustment_value, :greater_than, count: -100)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
# A rate plan's cached `options` column ({option_type_name => option_value_name}) with typed readers for the
|
|
3
|
+
# system option types in OptionTypeAttrType::RATE_PLAN_RESERVED_OPTIONS.
|
|
4
|
+
class RatePlanOptions
|
|
5
|
+
def self.from_hash(hash)
|
|
6
|
+
new(hash.is_a?(String) ? JSON.parse(hash) : hash)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(hash = {})
|
|
10
|
+
@hash = (hash || {}).to_h.stringify_keys
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def meal_plan
|
|
14
|
+
self['meal-plan']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Refundable unless a hotel marks it otherwise.
|
|
18
|
+
def refundable?
|
|
19
|
+
value = self['refundable']
|
|
20
|
+
value.nil? || value == '1'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def free_cancellation_days
|
|
24
|
+
self['free-cancellation-days']&.to_i
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Any option type's value, including admin-defined ones.
|
|
28
|
+
def [](option_type_name)
|
|
29
|
+
@hash[option_type_name.to_s]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_h
|
|
33
|
+
@hash
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
# What limits one rate on one date, beyond its price: a rate plan's, or the base rate's (the variant's own
|
|
3
|
+
# prices) when `rate_plan_id` is NULL. Keyed like a date price row, by the room-night's inventory item.
|
|
4
|
+
#
|
|
5
|
+
# Rate-level only. Closing the room-night itself, for every rate, stays InventoryItem#closed, which every
|
|
6
|
+
# availability check already reads; Booking.com keeps the same two levels (a close with or without a
|
|
7
|
+
# RatePlanCode). RateClosings reads both together.
|
|
8
|
+
#
|
|
9
|
+
# A row exists only while something is set, so reopening deletes it. Min/max stay and closed to
|
|
10
|
+
# arrival/departure are columns to add here, as Booking.com sends them in the same rate × date message.
|
|
11
|
+
class RateRestriction < SpreeCmCommissioner::Base
|
|
12
|
+
belongs_to :inventory_item, class_name: 'SpreeCmCommissioner::InventoryItem',
|
|
13
|
+
inverse_of: :rate_restrictions
|
|
14
|
+
|
|
15
|
+
belongs_to :rate_plan, class_name: 'SpreeCmCommissioner::RatePlan',
|
|
16
|
+
inverse_of: :rate_restrictions, optional: true
|
|
17
|
+
|
|
18
|
+
validate :rate_plan_of_the_inventory_items_variant, if: -> { rate_plan.present? }
|
|
19
|
+
|
|
20
|
+
# Closes or reopens one rate (`rate_plan` nil for the base rate) on these room-nights, in one statement, and
|
|
21
|
+
# touches their variants once so cached room responses, keyed by variant updated_at, refresh.
|
|
22
|
+
def self.set_closed!(inventory_items, rate_plan:, closed:)
|
|
23
|
+
return if inventory_items.empty?
|
|
24
|
+
|
|
25
|
+
ids = inventory_items.map(&:id)
|
|
26
|
+
|
|
27
|
+
if closed
|
|
28
|
+
now = Time.current
|
|
29
|
+
rows = ids.map { |id| { inventory_item_id: id, rate_plan_id: rate_plan&.id, closed: true, created_at: now, updated_at: now } }
|
|
30
|
+
index = rate_plan ? 'index_cm_rate_restrictions_on_rate_plan' : 'index_cm_rate_restrictions_on_base_rate'
|
|
31
|
+
upsert_all(rows, unique_by: index, update_only: %i[closed]) # rubocop:disable Rails/SkipsModelValidations
|
|
32
|
+
else
|
|
33
|
+
where(inventory_item_id: ids, rate_plan_id: rate_plan&.id).delete_all
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Spree::Variant.where(id: inventory_items.map(&:variant_id).uniq).find_each(&:touch)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def rate_plan_of_the_inventory_items_variant
|
|
42
|
+
errors.add(:rate_plan, :invalid) if rate_plan.variant_id != inventory_item&.variant_id
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -129,8 +129,11 @@ module SpreeCmCommissioner
|
|
|
129
129
|
end
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
# Create maintaining task to purge taxon related caches
|
|
133
|
-
|
|
132
|
+
# Create maintaining task to purge taxon related caches. Skips no-op saves (e.g. an event's
|
|
133
|
+
# price-range refresh after each order) so they don't send paid CloudFront invalidations.
|
|
134
|
+
base.after_save(if: -> { saved_changes.except('updated_at').any? }) do
|
|
135
|
+
SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: self)
|
|
136
|
+
end
|
|
134
137
|
|
|
135
138
|
def base.active_homepage_events
|
|
136
139
|
joins(:homepage_section_relatables)
|
|
@@ -7,6 +7,7 @@ module SpreeCmCommissioner
|
|
|
7
7
|
base.include SpreeCmCommissioner::KycBitwise
|
|
8
8
|
base.include SpreeCmCommissioner::Integrations::IntegrationMappable
|
|
9
9
|
base.include SpreeCmCommissioner::VariantMetadata
|
|
10
|
+
base.include SpreeCmCommissioner::VariantRatePlannable
|
|
10
11
|
|
|
11
12
|
base.after_commit :update_vendor_price
|
|
12
13
|
base.validate :validate_option_types
|
|
@@ -35,6 +36,13 @@ module SpreeCmCommissioner
|
|
|
35
36
|
|
|
36
37
|
base.has_many :inventory_items, class_name: 'SpreeCmCommissioner::InventoryItem'
|
|
37
38
|
|
|
39
|
+
# override Spree::DefaultPrice: the core scope matches any row in the store currency, so it could
|
|
40
|
+
# pick a per-date or rate plan row instead of the variant's base price.
|
|
41
|
+
base.has_one :default_price,
|
|
42
|
+
-> { with_deleted.where(currency: Spree::Store.default.default_currency, inventory_item_id: nil, rate_plan_id: nil) },
|
|
43
|
+
class_name: 'Spree::Price',
|
|
44
|
+
dependent: :destroy
|
|
45
|
+
|
|
38
46
|
base.has_many :pricing_model_variants, class_name: 'SpreeCmCommissioner::PricingModelVariant', dependent: :destroy
|
|
39
47
|
base.has_many :pricing_models, through: :pricing_model_variants, class_name: 'SpreeCmCommissioner::PricingModel'
|
|
40
48
|
|
|
@@ -42,14 +50,22 @@ module SpreeCmCommissioner
|
|
|
42
50
|
base.scope :with_permanent_stock, -> { where(product_type: base::PERMANENT_STOCK_PRODUCT_TYPES) }
|
|
43
51
|
base.scope :with_non_permanent_stock, -> { where.not(product_type: base::PERMANENT_STOCK_PRODUCT_TYPES) }
|
|
44
52
|
|
|
53
|
+
# Variants bookable on every one of `dates`. The correlated COUNT only reads each candidate variant's
|
|
54
|
+
# rows through the (variant_id, inventory_date) unique index, rather than aggregating every product's
|
|
55
|
+
# inventory for those dates; one row per date, so the count equals the number of bookable dates.
|
|
56
|
+
base.scope :bookable_on_every_date, lambda { |dates|
|
|
57
|
+
bookable_dates = SpreeCmCommissioner::InventoryItem.bookable_on(dates)
|
|
58
|
+
.where('cm_inventory_items.variant_id = spree_variants.id')
|
|
59
|
+
.select('COUNT(*)')
|
|
60
|
+
where('(?) = ?', bookable_dates, dates.size)
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
base.accepts_nested_attributes_for :option_values
|
|
46
64
|
|
|
47
65
|
base.before_validation -> { self.product_type = product.product_type }, if: -> { product_type.nil? }
|
|
48
66
|
|
|
49
67
|
# Create maintaining task to purge product related caches
|
|
50
68
|
base.after_commit { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: product) }
|
|
51
|
-
|
|
52
|
-
# App opens the event page, not the ticket/product page, so the event's cache must be purged too.
|
|
53
69
|
base.after_commit { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: event) if event.present? }
|
|
54
70
|
|
|
55
71
|
# A discarded variant can no longer be priced, so the event's range must be recomputed.
|
|
@@ -88,6 +104,10 @@ module SpreeCmCommissioner
|
|
|
88
104
|
delivery_option == 'delivery'
|
|
89
105
|
end
|
|
90
106
|
|
|
107
|
+
def inventory_external_wins?
|
|
108
|
+
vendor&.integration&.inventory_external_wins?(self) || false
|
|
109
|
+
end
|
|
110
|
+
|
|
91
111
|
def non_digital_ecommerce?
|
|
92
112
|
!digital? && ecommerce?
|
|
93
113
|
end
|
|
@@ -132,24 +152,29 @@ module SpreeCmCommissioner
|
|
|
132
152
|
SpreeCmCommissioner::Stock::AvailabilityChecker.new(self, options).can_supply?(include_locked: true)
|
|
133
153
|
end
|
|
134
154
|
|
|
155
|
+
# The variant's own price for one date. Rate plan rows are excluded; RatePlan#price_for_date reads them.
|
|
135
156
|
def price_for_date(currency:, date:)
|
|
136
157
|
currency = currency.upcase
|
|
137
158
|
|
|
138
159
|
prices.joins(:inventory_item)
|
|
139
160
|
.find_by(
|
|
140
161
|
currency: currency,
|
|
162
|
+
rate_plan_id: nil,
|
|
141
163
|
inventory_item: { inventory_date: date }
|
|
142
164
|
)
|
|
143
165
|
end
|
|
144
166
|
|
|
145
|
-
# override
|
|
167
|
+
# override: the variant's base price, never a per-date or rate plan row.
|
|
146
168
|
def price_in(currency)
|
|
147
169
|
currency = currency&.upcase
|
|
170
|
+
return default_price if preloaded_default_price_in?(currency)
|
|
171
|
+
|
|
148
172
|
find_or_build_price = lambda do
|
|
149
173
|
if prices.loaded?
|
|
150
|
-
prices.detect { |price| price.currency == currency
|
|
174
|
+
prices.detect { |price| price.currency == currency && price.inventory_item_id.nil? && price.rate_plan_id.nil? } ||
|
|
175
|
+
prices.build(currency: currency)
|
|
151
176
|
else
|
|
152
|
-
prices.find_or_initialize_by(currency: currency)
|
|
177
|
+
prices.find_or_initialize_by(currency: currency, inventory_item_id: nil, rate_plan_id: nil)
|
|
153
178
|
end
|
|
154
179
|
end
|
|
155
180
|
|
|
@@ -160,6 +185,12 @@ module SpreeCmCommissioner
|
|
|
160
185
|
|
|
161
186
|
private
|
|
162
187
|
|
|
188
|
+
# A preloaded default_price is the base row in the store currency, so lists that preload it read no price per
|
|
189
|
+
# variant. Its scope includes deleted rows, which price_in never returns.
|
|
190
|
+
def preloaded_default_price_in?(currency)
|
|
191
|
+
association(:default_price).loaded? && default_price&.currency == currency && default_price.deleted_at.nil?
|
|
192
|
+
end
|
|
193
|
+
|
|
163
194
|
def update_vendor_price
|
|
164
195
|
return unless vendor.present? && product_type == vendor&.primary_product_type
|
|
165
196
|
return if price.blank?
|
|
@@ -146,9 +146,10 @@ module SpreeCmCommissioner
|
|
|
146
146
|
@vote_package_amount ||= option_value_name_for(option_type_name: 'vote-package')&.to_i
|
|
147
147
|
end
|
|
148
148
|
|
|
149
|
-
# can consider as customers.
|
|
149
|
+
# can consider as customers. An explicit number-of-guests wins, for variants sold by
|
|
150
|
+
# headcount with no adult/kid split; Spree::Variant.with_guest_capacity mirrors this in SQL.
|
|
150
151
|
def number_of_guests
|
|
151
|
-
number_of_adults + number_of_kids
|
|
152
|
+
@number_of_guests ||= option_value_name_for(option_type_name: 'number-of-guests')&.to_i || (number_of_adults + number_of_kids)
|
|
152
153
|
end
|
|
153
154
|
end
|
|
154
155
|
end
|
|
@@ -128,6 +128,7 @@ module SpreeCmCommissioner
|
|
|
128
128
|
|
|
129
129
|
base.has_many :merchandise_products, -> { where(product_type: :ecommerce, event_id: nil) }, class_name: 'Spree::Product'
|
|
130
130
|
base.has_many :vote_packages, -> { where(product_type: :vote_package) }, class_name: 'SpreeCmCommissioner::ShowEpisode', foreign_key: :vendor_id
|
|
131
|
+
base.has_many :room_types, -> { where(product_type: :accommodation) }, class_name: 'Spree::Product'
|
|
131
132
|
|
|
132
133
|
# Create maintaining task to purge vendor related caches
|
|
133
134
|
base.after_save { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: self) }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- replace "erb[loud]:contains('field_container :name')" closing_selector "erb[silent]:contains('end')" -->
|
|
2
2
|
|
|
3
3
|
<%= f.field_container :name do %>
|
|
4
|
-
<span class="mr-1" type="button" data-toggle="popover" data-placement="left" data-title="System options" data-html="true" data-content="‣ <%= f.object.class::RESERVED_OPTIONS.keys.join("<br>‣ ") %>">
|
|
4
|
+
<span class="mr-1" type="button" data-toggle="popover" data-placement="left" data-title="System options" data-html="true" data-content="‣ <%= (f.object.class::RESERVED_OPTIONS.keys + f.object.class::RATE_PLAN_RESERVED_OPTIONS.keys).join("<br>‣ ") %>">
|
|
5
5
|
<%= svg_icon name: "info-circle-fill.svg", width: '14', height: '14' %>
|
|
6
6
|
</span>
|
|
7
7
|
<%= f.label :name, raw(Spree.t(:name) + required_span_tag) %>
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
<%= f.select :vendor_id_eq, Spree::Vendor.all.map { |v| [v.name, v.id] }, { include_blank: true }, { class: 'form-control js-filterable select2', size: 15 } %>
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
|
22
|
+
<div class="col-12 col-lg-6">
|
|
23
|
+
<div class="form-group">
|
|
24
|
+
<%= f.label :event_id_eq, 'Event' %>
|
|
25
|
+
<%= f.select :event_id_eq, Spree::Taxon.events.pluck(:name, :id), { include_blank: true }, { class: 'form-control js-filterable select2' } %>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
22
28
|
<div class="col-12">
|
|
23
29
|
<%= f.field_container :deleted_at_null do %>
|
|
24
30
|
<div class="custom-control custom-checkbox">
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<!-- insert_after "erb[loud]:contains('current == :stock')" -->
|
|
2
|
+
|
|
3
|
+
<%= content_tag :li, class: 'nav-item' do %>
|
|
4
|
+
<%= link_to_with_icon 'calendar.svg',
|
|
5
|
+
t('rates_availabilities.title'),
|
|
6
|
+
admin_product_rates_availabilities_path(@product),
|
|
7
|
+
class: "nav-link #{'active' if current == :rates_availabilities}" %>
|
|
8
|
+
<% end if can?(:index, Spree::StockItem) && !@product.deleted? %>
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
<%= link_to_with_icon 'box-seam.svg',
|
|
4
4
|
Spree.t(:stock_managements),
|
|
5
|
-
|
|
5
|
+
admin_product_stock_managements_url(@product),
|
|
6
6
|
class: "nav-link #{'active' if current == :stock_managements}" %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- insert_after "erb[loud]:contains('variant.options_text')" -->
|
|
2
|
+
|
|
3
|
+
<% if variant.discontinue_on.present? %>
|
|
4
|
+
<% if variant.discontinue_on <= Time.current %>
|
|
5
|
+
<span class="badge badge-danger ml-1" data-toggle="tooltip" data-placement="top" title="<%= t('spree.admin.variants.index.discontinued_hint') %>">
|
|
6
|
+
<%= Spree.t(:discontinued) %>
|
|
7
|
+
</span>
|
|
8
|
+
<% else %>
|
|
9
|
+
<span class="badge badge-warning ml-1" data-toggle="tooltip" data-placement="top" title="<%= t('spree.admin.variants.index.discontinues_on_hint') %>">
|
|
10
|
+
<%= t('spree.admin.variants.index.discontinues_on', date: pretty_time(variant.discontinue_on)) %>
|
|
11
|
+
</span>
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!-- insert_before "#new_variant" -->
|
|
2
|
+
|
|
3
|
+
<% product_option_types = @product.product_option_types.includes(:option_type).order(:position) %>
|
|
4
|
+
<div class="d-flex flex-wrap align-items-center small mb-2">
|
|
5
|
+
<span class="text-muted mr-2"><%= t('spree.admin.product_option_types.summary.title') %></span>
|
|
6
|
+
<% if product_option_types.any? %>
|
|
7
|
+
<% product_option_types.each_with_index do |product_option_type, index| %>
|
|
8
|
+
<% if index.positive? %><span class="text-muted mx-2">→</span><% end %>
|
|
9
|
+
<span class="<%= 'text-muted' if product_option_type.hidden? %>"
|
|
10
|
+
title="<%= product_option_type.option_type.presentation %> (<%= product_option_type.option_type.name %>)">
|
|
11
|
+
<%= product_option_type.display_presentation %>
|
|
12
|
+
<% if product_option_type.hidden? %>
|
|
13
|
+
<span title="<%= t('spree.admin.product_option_types.summary.hidden') %>"><%= svg_icon name: 'eye-slash.svg', width: '12', height: '12', classes: 'ml-1' %></span>
|
|
14
|
+
<% end %>
|
|
15
|
+
</span>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% else %>
|
|
18
|
+
<span class="text-muted"><%= t('spree.admin.product_option_types.summary.empty') %></span>
|
|
19
|
+
<% end %>
|
|
20
|
+
<% if can?(:modify, Spree::ProductOptionType) %>
|
|
21
|
+
<span class="text-muted mx-2">·</span>
|
|
22
|
+
<%= link_to t('spree.admin.product_option_types.summary.edit'), spree.admin_product_product_option_types_url(@product) %>
|
|
23
|
+
<% end %>
|
|
24
|
+
</div>
|