spree_cm_commissioner 2.0.3.pre.pre3 → 2.0.3.pre.pre4
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/.github/workflows/test_and_build_gem.yml +2 -16
- data/.gitignore +1 -2
- data/Gemfile.lock +1 -28
- data/Rakefile +4 -33
- data/app/assets/stylesheets/spree_cm_commissioner/backend/calendar.scss +11 -8
- data/app/controllers/concerns/spree_cm_commissioner/transit/taxon_bitwise.rb +44 -0
- data/app/controllers/spree/admin/stock_managements_controller.rb +1 -63
- data/app/controllers/spree/api/v2/operator/event_charts_controller.rb +2 -8
- data/app/controllers/spree/api/v2/storefront/accommodations_controller.rb +31 -14
- data/app/controllers/spree/api/v2/storefront/queue_cart/line_items_controller.rb +2 -2
- data/app/finders/spree_cm_commissioner/line_items/find_by_variant_decorator.rb +20 -0
- data/app/jobs/spree_cm_commissioner/application_job.rb +0 -20
- data/app/jobs/spree_cm_commissioner/application_unique_job.rb +0 -20
- data/app/models/concerns/spree_cm_commissioner/line_item_durationable.rb +15 -9
- data/app/models/concerns/spree_cm_commissioner/option_type_attr_type.rb +12 -2
- data/app/models/concerns/spree_cm_commissioner/order_state_machine.rb +0 -39
- data/app/models/concerns/spree_cm_commissioner/product_delegation.rb +3 -1
- data/app/models/concerns/spree_cm_commissioner/product_type.rb +0 -10
- data/app/models/concerns/spree_cm_commissioner/route_type.rb +1 -1
- data/app/models/concerns/spree_cm_commissioner/taxon_kind.rb +1 -1
- data/app/models/spree_cm_commissioner/branch.rb +12 -0
- data/app/models/spree_cm_commissioner/guest.rb +0 -18
- data/app/models/spree_cm_commissioner/line_item_decorator.rb +78 -46
- data/app/models/spree_cm_commissioner/line_item_seat.rb +10 -0
- data/app/models/spree_cm_commissioner/notification_taxon.rb +1 -1
- data/app/models/spree_cm_commissioner/option_type_decorator.rb +11 -1
- data/app/models/spree_cm_commissioner/option_value_vehicle_type.rb +8 -0
- data/app/models/spree_cm_commissioner/order_decorator.rb +1 -30
- data/app/models/spree_cm_commissioner/place.rb +4 -1
- data/app/models/spree_cm_commissioner/product_decorator.rb +6 -10
- data/app/models/spree_cm_commissioner/service_calendar.rb +2 -0
- data/app/models/spree_cm_commissioner/state_decorator.rb +1 -0
- data/app/models/spree_cm_commissioner/stock/availability_checker.rb +25 -26
- data/app/models/spree_cm_commissioner/stock/availability_validator_decorator.rb +1 -2
- data/app/models/spree_cm_commissioner/stock/line_item_availability_checker.rb +3 -3
- data/app/models/spree_cm_commissioner/stock_item_decorator.rb +0 -17
- data/app/models/spree_cm_commissioner/stop.rb +23 -0
- data/app/models/spree_cm_commissioner/taxon_decorator.rb +1 -0
- data/app/models/spree_cm_commissioner/taxonomy_decorator.rb +6 -0
- data/app/models/spree_cm_commissioner/trip.rb +10 -12
- data/app/models/spree_cm_commissioner/trip_connection.rb +5 -5
- data/app/models/spree_cm_commissioner/trip_stop.rb +21 -10
- data/app/models/spree_cm_commissioner/variant_decorator.rb +47 -37
- data/app/models/spree_cm_commissioner/variant_options.rb +23 -0
- data/app/models/spree_cm_commissioner/vehicle.rb +16 -11
- data/app/models/spree_cm_commissioner/vehicle_seat.rb +11 -0
- data/app/models/spree_cm_commissioner/vehicle_type.rb +76 -0
- data/app/models/spree_cm_commissioner/vendor_decorator.rb +14 -11
- data/app/models/spree_cm_commissioner/vendor_place.rb +3 -13
- data/app/models/spree_cm_commissioner/vendor_stop.rb +10 -0
- data/app/queries/spree_cm_commissioner/trip_query.rb +131 -110
- data/app/queries/spree_cm_commissioner/trip_search_query.rb +76 -0
- data/app/queries/spree_cm_commissioner/variant_availability/non_permanent_stock_query.rb +45 -0
- data/app/queries/spree_cm_commissioner/variant_availability/permanent_stock_query.rb +55 -0
- data/app/queries/spree_cm_commissioner/vendor_stop_place_query.rb +54 -0
- data/app/request_schemas/spree_cm_commissioner/accommodation_request_schema.rb +0 -3
- data/app/request_schemas/spree_cm_commissioner/application_request_schema.rb +1 -1
- data/app/serializers/spree/v2/storefront/accommodation_serializer.rb +0 -2
- data/app/serializers/spree/v2/storefront/line_item_serializer_decorator.rb +0 -1
- data/app/services/spree_cm_commissioner/vehicle_option_value_creator.rb +11 -0
- data/app/views/spree/admin/stock_managements/_variant_stock_items.html.erb +2 -7
- data/app/views/spree/admin/stock_managements/index.html.erb +6 -55
- data/config/initializers/spree_permitted_attributes.rb +0 -5
- data/config/routes.rb +2 -24
- data/db/migrate/20240202080634_update_counter_cache_of_vehicle_type.rb +1 -3
- data/docker-compose.yml +1 -1
- data/lib/cm_app_logger.rb +4 -11
- data/lib/generators/spree_cm_commissioner/install/install_generator.rb +11 -14
- data/lib/generators/spree_cm_commissioner/install/templates/app/javascript/{spree_dashboard/spree_cm_commissioner → spree_cm_commissioner}/utilities.js +0 -4
- data/lib/spree_cm_commissioner/calendar_event.rb +1 -11
- data/lib/spree_cm_commissioner/test_helper/factories/branch_factory.rb +12 -0
- data/lib/spree_cm_commissioner/test_helper/factories/departure_time_option_type_factory.rb +8 -0
- data/lib/spree_cm_commissioner/test_helper/factories/duration_option_type_factory.rb +8 -0
- data/lib/spree_cm_commissioner/test_helper/factories/guest_factory.rb +0 -10
- data/lib/spree_cm_commissioner/test_helper/factories/homepage_section_relatable_factory.rb +1 -1
- data/lib/spree_cm_commissioner/test_helper/factories/line_item_factory.rb +1 -1
- data/lib/spree_cm_commissioner/test_helper/factories/line_item_seat_factory.rb +7 -0
- data/lib/spree_cm_commissioner/test_helper/factories/option_type_factory.rb +30 -6
- data/lib/spree_cm_commissioner/test_helper/factories/order_factory.rb +36 -0
- data/lib/spree_cm_commissioner/test_helper/factories/product_factory.rb +34 -18
- data/lib/spree_cm_commissioner/test_helper/factories/stock_location_factory.rb +2 -2
- data/lib/spree_cm_commissioner/test_helper/factories/stop_factory.rb +14 -0
- data/lib/spree_cm_commissioner/test_helper/factories/transit_place_factory.rb +8 -0
- data/lib/spree_cm_commissioner/test_helper/factories/trip_factory.rb +3 -11
- data/lib/spree_cm_commissioner/test_helper/factories/variant_factory.rb +19 -41
- data/lib/spree_cm_commissioner/test_helper/factories/vehicle_factory.rb +1 -1
- data/lib/spree_cm_commissioner/test_helper/factories/vehicle_option_type_factory.rb +8 -0
- data/lib/spree_cm_commissioner/test_helper/factories/vehicle_type_factory.rb +96 -0
- data/lib/spree_cm_commissioner/test_helper/factories/vendor_factory.rb +1 -6
- data/lib/spree_cm_commissioner/test_helper/factories/vendor_place_factory.rb +1 -13
- data/lib/spree_cm_commissioner/trip_query_result.rb +0 -16
- data/lib/spree_cm_commissioner/trip_result.rb +10 -12
- data/lib/spree_cm_commissioner/trip_seat_layout_result.rb +11 -0
- data/lib/spree_cm_commissioner/version.rb +1 -1
- data/lib/spree_cm_commissioner.rb +1 -35
- data/spree_cm_commissioner.gemspec +0 -7
- metadata +26 -154
- data/app/controllers/spree/admin/inventory_items_controller.rb +0 -83
- data/app/controllers/spree/api/v2/storefront/accommodations/variants_controller.rb +0 -42
- data/app/controllers/spree/api/v2/storefront/trip_search_controller.rb +0 -60
- data/app/finders/spree_cm_commissioner/accommodations/find.rb +0 -37
- data/app/finders/spree_cm_commissioner/accommodations/find_variant.rb +0 -32
- data/app/interactors/spree_cm_commissioner/ensure_correct_product_type.rb +0 -40
- data/app/interactors/spree_cm_commissioner/inventory_item_syncer.rb +0 -25
- data/app/interactors/spree_cm_commissioner/stock/inventory_item_resetter.rb +0 -44
- data/app/interactors/spree_cm_commissioner/stock/inventory_items_adjuster.rb +0 -13
- data/app/interactors/spree_cm_commissioner/stock/inventory_items_generator.rb +0 -15
- data/app/interactors/spree_cm_commissioner/stock/permanent_inventory_items_generator.rb +0 -75
- data/app/interactors/spree_cm_commissioner/stock/stock_movement_creator.rb +0 -32
- data/app/interactors/spree_cm_commissioner/taxi_trip_creator.rb +0 -66
- data/app/interactors/spree_cm_commissioner/variant_block_updater.rb +0 -62
- data/app/interactors/spree_cm_commissioner/vehicle_updater.rb +0 -41
- data/app/jobs/spree_cm_commissioner/ensure_correct_product_type_job.rb +0 -7
- data/app/jobs/spree_cm_commissioner/inventory_item_syncer_job.rb +0 -7
- data/app/jobs/spree_cm_commissioner/stock/inventory_items_adjuster_job.rb +0 -11
- data/app/jobs/spree_cm_commissioner/stock/inventory_items_generator_job.rb +0 -11
- data/app/jobs/spree_cm_commissioner/stock/permanent_inventory_items_generator_job.rb +0 -9
- data/app/models/concerns/spree_cm_commissioner/order_seatable.rb +0 -44
- data/app/models/concerns/spree_cm_commissioner/vehicle_type.rb +0 -11
- data/app/models/spree_cm_commissioner/block.rb +0 -43
- data/app/models/spree_cm_commissioner/inventory.rb +0 -11
- data/app/models/spree_cm_commissioner/inventory_item.rb +0 -69
- data/app/models/spree_cm_commissioner/price_decorator.rb +0 -9
- data/app/models/spree_cm_commissioner/redis_stock/cached_inventory_items_builder.rb +0 -41
- data/app/models/spree_cm_commissioner/redis_stock/inventory_updater.rb +0 -126
- data/app/models/spree_cm_commissioner/redis_stock/line_items_cached_inventory_items_builder.rb +0 -36
- data/app/models/spree_cm_commissioner/redis_stock/variant_cached_inventory_items_builder.rb +0 -25
- data/app/models/spree_cm_commissioner/reserved_block.rb +0 -30
- data/app/models/spree_cm_commissioner/seat_layout.rb +0 -20
- data/app/models/spree_cm_commissioner/seat_section.rb +0 -16
- data/app/models/spree_cm_commissioner/seats/blocks_canceler.rb +0 -30
- data/app/models/spree_cm_commissioner/seats/blocks_holder.rb +0 -53
- data/app/models/spree_cm_commissioner/seats/blocks_reserver.rb +0 -49
- data/app/models/spree_cm_commissioner/seats/errors/blocks_are_on_hold_by_other_guest.rb +0 -4
- data/app/models/spree_cm_commissioner/seats/errors/blocks_are_reserved_by_other_guest.rb +0 -4
- data/app/models/spree_cm_commissioner/seats/errors/blocks_are_reserved_by_same_guest.rb +0 -4
- data/app/models/spree_cm_commissioner/seats/errors/unable_to_save_reserved_block_record.rb +0 -4
- data/app/models/spree_cm_commissioner/stock/order_availability_checker.rb +0 -44
- data/app/models/spree_cm_commissioner/variant_block.rb +0 -9
- data/app/request_schemas/spree_cm_commissioner/trip_search_request_schema.rb +0 -20
- data/app/request_schemas/spree_cm_commissioner/variant_request_schema.rb +0 -19
- data/app/serializers/spree/v2/storefront/amenity_serializer.rb +0 -15
- data/app/serializers/spree/v2/storefront/trip_query_result_serializer.rb +0 -14
- data/app/serializers/spree/v2/storefront/trip_result_serializer.rb +0 -16
- data/app/serializers/spree/v2/storefront/trip_vehicle_serializer.rb +0 -11
- data/app/serializers/spree/v2/storefront/trip_vendor_serializer.rb +0 -13
- data/app/views/spree/admin/inventory_items/show.html.erb +0 -72
- data/app/views/spree/admin/stock_managements/calendar.html.erb +0 -56
- data/config/initializers/paper_trail.rb +0 -1
- data/db/migrate/20250122000000_move_route_type_from_vehicles_to_trips.rb +0 -7
- data/db/migrate/20250304293518_create_cm_inventory_items.rb +0 -21
- data/db/migrate/20250429094228_add_lock_version_to_cm_inventory_items.rb +0 -5
- data/db/migrate/20250502025848_add_index_to_spree_products.rb +0 -5
- data/db/migrate/20250502030001_add_product_type_to_spree_variants.rb +0 -5
- data/db/migrate/20250502030002_add_product_type_to_spree_line_items.rb +0 -5
- data/db/migrate/20250603035256_add_inventory_item_to_spree_prices.rb +0 -7
- data/db/migrate/20250619073724_drop_table_cm_line_item_seats.rb +0 -5
- data/db/migrate/20250619073812_drop_table_cm_vehicle_seats.rb +0 -5
- data/db/migrate/20250619073844_drop_table_cm_vehicle_types.rb +0 -9
- data/db/migrate/20250619073957_drop_table_cm_option_value_vehicle_types.rb +0 -5
- data/db/migrate/20250619082354_remove_unnecessary_fields_from_cm_places.rb +0 -9
- data/db/migrate/20250619082736_remove_route_type_from_spree_products.rb +0 -5
- data/db/migrate/20250619083055_remove_unnecessary_fields_from_spree_taxons.rb +0 -5
- data/db/migrate/20250620083055_remove_variant_id_from_cm_trips.rb +0 -5
- data/db/migrate/20250620090000_update_cm_trip_connections_to_use_cm_trips.rb +0 -6
- data/db/migrate/20250620090001_create_cm_seat_layouts.rb +0 -17
- data/db/migrate/20250620090002_create_cm_seat_sections.rb +0 -18
- data/db/migrate/20250620090003_create_cm_blocks.rb +0 -18
- data/db/migrate/20250624091005_create_cm_reserved_blocks.rb +0 -29
- data/db/migrate/20250626083642_create_cm_variant_blocks.rb +0 -24
- data/db/migrate/20250627023314_add_block_id_to_cm_guests.rb +0 -13
- data/db/migrate/20250716022821_add_location_reference_to_cm_vendor_places.rb +0 -5
- data/db/migrate/20250716031743_drop_table_cm_vendor_stops.rb +0 -5
- data/db/migrate/20250717023824_add_vendor_reference_to_cm_trips.rb +0 -5
- data/db/migrate/20250717041414_add_location_place_reference_to_cm_trip_stops.rb +0 -5
- data/db/migrate/20250717042539_rename_cm_trip_stops_stop_id_column_to_stop_place_id.rb +0 -7
- data/db/migrate/20250717042707_rename_cm_trips_origin_and_destination_to_origin_place_and_destination_place.rb +0 -11
- data/db/migrate/20250721080738_add_vehicle_type_to_cm_vehicles.rb +0 -7
- data/db/migrate/20250725092713_add_block_type_to_cm_blocks.rb +0 -5
- data/db/migrate/20250731062816_add_departure_time_and_arrival_time_to_trip_stop.rb +0 -6
- data/lib/spree_cm_commissioner/cached_inventory_item.rb +0 -23
- data/lib/spree_cm_commissioner/test_helper/factories/block_factory.rb +0 -16
- data/lib/spree_cm_commissioner/test_helper/factories/inventory_item_factory.rb +0 -9
- data/lib/spree_cm_commissioner/test_helper/factories/reserved_block_factory.rb +0 -27
- data/lib/spree_cm_commissioner/test_helper/factories/seat_layout_factory.rb +0 -11
- data/lib/spree_cm_commissioner/test_helper/factories/seat_section_factory.rb +0 -16
- data/lib/spree_cm_commissioner/test_helper/factories/trip_connection_factory.rb +0 -6
- data/lib/spree_cm_commissioner/test_helper/factories/trip_stop_factory.rb +0 -10
- data/lib/spree_cm_commissioner/test_helper/factories/variant_block_factory.rb +0 -7
- data/lib/tasks/create_default_non_permanent_inventory_items.rake +0 -16
- data/lib/tasks/ensure_correct_product_type.rake +0 -7
- data/lib/tasks/generate_inventory_items.rake +0 -7
@@ -1,42 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V2
|
4
|
-
module Storefront
|
5
|
-
class Accommodations::VariantsController < ::Spree::Api::V2::ResourceController
|
6
|
-
private
|
7
|
-
|
8
|
-
# override
|
9
|
-
def collection
|
10
|
-
@collection ||= SpreeCmCommissioner::Accommodations::FindVariant.new(
|
11
|
-
from_date: params[:from_date]&.to_date,
|
12
|
-
to_date: params[:to_date]&.to_date,
|
13
|
-
vendor_id: params[:accommodation_id],
|
14
|
-
number_of_adults: params[:adult].to_i,
|
15
|
-
number_of_kids: params[:children].to_i
|
16
|
-
).execute
|
17
|
-
end
|
18
|
-
|
19
|
-
# override
|
20
|
-
def resource
|
21
|
-
@resource ||= collection.find(params[:id])
|
22
|
-
end
|
23
|
-
|
24
|
-
# override
|
25
|
-
def resource_serializer
|
26
|
-
Spree::V2::Storefront::VariantSerializer
|
27
|
-
end
|
28
|
-
|
29
|
-
# override
|
30
|
-
def collection_serializer
|
31
|
-
Spree::V2::Storefront::VariantSerializer
|
32
|
-
end
|
33
|
-
|
34
|
-
# override
|
35
|
-
def required_schema
|
36
|
-
SpreeCmCommissioner::VariantRequestSchema
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V2
|
4
|
-
module Storefront
|
5
|
-
class TripSearchController < ::Spree::Api::V2::ResourceController
|
6
|
-
def index
|
7
|
-
trips = SpreeCmCommissioner::TripQuery.new(
|
8
|
-
origin_id: params[:origin_id],
|
9
|
-
destination_id: params[:destination_id],
|
10
|
-
date: params[:date],
|
11
|
-
params: params
|
12
|
-
).call
|
13
|
-
|
14
|
-
render_serialized_payload { serialize_collection(trips) }
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
# override
|
20
|
-
def default_resource_includes
|
21
|
-
[
|
22
|
-
'trips.vendor',
|
23
|
-
'trips.vendor.logo',
|
24
|
-
'trips.vehicle',
|
25
|
-
'trips.amenities'
|
26
|
-
]
|
27
|
-
end
|
28
|
-
|
29
|
-
def serialize_collection(collection)
|
30
|
-
serialized_data = Spree::V2::Storefront::TripQueryResultSerializer.new(
|
31
|
-
collection,
|
32
|
-
include: default_resource_includes,
|
33
|
-
params: serializer_params
|
34
|
-
).serializable_hash
|
35
|
-
serialized_data[:meta] = {
|
36
|
-
count: collection.size,
|
37
|
-
total_count: collection.respond_to?(:total_count) ? collection.total_count : collection.size,
|
38
|
-
current_page: collection.respond_to?(:current_page) ? collection.current_page : 1,
|
39
|
-
per_page: collection.respond_to?(:limit_value) ? collection.limit_value : collection.size,
|
40
|
-
pages: collection.respond_to?(:total_pages) ? collection.total_pages : 1,
|
41
|
-
next_page: collection.respond_to?(:next_page) ? collection.next_page : nil,
|
42
|
-
prev_page: collection.respond_to?(:prev_page) ? collection.prev_page : nil
|
43
|
-
}
|
44
|
-
serialized_data
|
45
|
-
end
|
46
|
-
|
47
|
-
# override
|
48
|
-
def serializer_params
|
49
|
-
params.permit(:include).to_hash
|
50
|
-
end
|
51
|
-
|
52
|
-
# override
|
53
|
-
def required_schema
|
54
|
-
SpreeCmCommissioner::TripSearchRequestSchema
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Accommodations
|
3
|
-
class Find
|
4
|
-
attr_reader :from_date, :to_date, :state_id, :number_of_guests
|
5
|
-
|
6
|
-
def initialize(from_date:, to_date:, state_id:, number_of_adults:, number_of_kids:)
|
7
|
-
@from_date = from_date
|
8
|
-
@to_date = to_date
|
9
|
-
@state_id = state_id
|
10
|
-
@number_of_guests = number_of_adults.to_i + number_of_kids.to_i
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute
|
14
|
-
scope
|
15
|
-
.where(default_state_id: state_id)
|
16
|
-
.where(inventory_items: { inventory_date: stay_dates })
|
17
|
-
.where('CAST(spree_variants.public_metadata->\'cm_options\'->>\'number-of-adults\' AS INTEGER) +
|
18
|
-
CAST(spree_variants.public_metadata->\'cm_options\'->>\'number-of-kids\' AS INTEGER) >= ?', number_of_guests
|
19
|
-
)
|
20
|
-
.where('inventory_items.quantity_available > 0')
|
21
|
-
.distinct
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def scope
|
27
|
-
Spree::Vendor
|
28
|
-
.joins(variants: :inventory_items)
|
29
|
-
.where(primary_product_type: :accommodation, state: :active)
|
30
|
-
end
|
31
|
-
|
32
|
-
def stay_dates
|
33
|
-
from_date..to_date
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Accommodations
|
3
|
-
class FindVariant
|
4
|
-
attr_reader :vendor_id, :from_date, :to_date, :number_of_guests
|
5
|
-
|
6
|
-
def initialize(vendor_id:, from_date:, to_date:, number_of_adults:, number_of_kids:)
|
7
|
-
@vendor_id = vendor_id
|
8
|
-
@from_date = from_date
|
9
|
-
@to_date = to_date
|
10
|
-
@number_of_guests = number_of_adults.to_i + number_of_kids.to_i
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute
|
14
|
-
Spree::Variant
|
15
|
-
.joins(:inventory_items)
|
16
|
-
.where(vendor_id: vendor_id)
|
17
|
-
.where(inventory_items: { inventory_date: stay_dates })
|
18
|
-
.where('CAST(public_metadata->\'cm_options\'->>\'number-of-adults\' AS INTEGER) +
|
19
|
-
CAST(public_metadata->\'cm_options\'->>\'number-of-kids\' AS INTEGER) >= ?', number_of_guests
|
20
|
-
)
|
21
|
-
.where('inventory_items.quantity_available > 0')
|
22
|
-
.distinct
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def stay_dates
|
28
|
-
from_date..to_date
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class EnsureCorrectProductType < BaseInteractor
|
3
|
-
def call
|
4
|
-
Spree::Product
|
5
|
-
.left_joins(variants_including_master: %i[inventory_items line_items])
|
6
|
-
.where(
|
7
|
-
'spree_variants.product_type IS NULL OR
|
8
|
-
spree_variants.product_type != spree_products.product_type OR
|
9
|
-
|
10
|
-
cm_inventory_items.product_type IS NULL OR
|
11
|
-
cm_inventory_items.product_type != spree_products.product_type OR
|
12
|
-
|
13
|
-
spree_line_items.product_type IS NULL OR
|
14
|
-
spree_line_items.product_type != spree_products.product_type OR
|
15
|
-
|
16
|
-
spree_products.product_type IS NOT NULL
|
17
|
-
'
|
18
|
-
)
|
19
|
-
.distinct.find_each do |product|
|
20
|
-
sync_product_type_for(product)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def sync_product_type_for(product)
|
25
|
-
product_type = Spree::Variant.product_types[product.product_type]
|
26
|
-
|
27
|
-
product.variants_including_master
|
28
|
-
.where('spree_variants.product_type IS NULL OR spree_variants.product_type != ?', product_type)
|
29
|
-
.update_all(product_type: product_type) # rubocop:disable Rails/SkipsModelValidations
|
30
|
-
|
31
|
-
product.line_items
|
32
|
-
.where('spree_line_items.product_type IS NULL OR spree_line_items.product_type != ?', product_type)
|
33
|
-
.update_all(product_type: product_type) # rubocop:disable Rails/SkipsModelValidations
|
34
|
-
|
35
|
-
product.inventory_items
|
36
|
-
.where('cm_inventory_items.product_type IS NULL OR cm_inventory_items.product_type != ?', product_type)
|
37
|
-
.update_all(product_type: product_type) # rubocop:disable Rails/SkipsModelValidations
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class InventoryItemSyncer < BaseInteractor
|
3
|
-
# inventory_id_and_quantities = [{ inventory_id: inventory_item1.id, quantity: 5 } ]
|
4
|
-
delegate :inventory_id_and_quantities, to: :context
|
5
|
-
|
6
|
-
def call
|
7
|
-
ActiveRecord::Base.transaction do
|
8
|
-
inventory_items.each do |inventory_item|
|
9
|
-
quantity = inventory_id_and_quantities.find { |item| item[:inventory_id] == inventory_item.id }&.dig(:quantity) || 0
|
10
|
-
adjust_quantity_available(inventory_item, quantity)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def adjust_quantity_available(inventory_item, quantity)
|
18
|
-
inventory_item.update!(quantity_available: inventory_item.quantity_available + quantity)
|
19
|
-
end
|
20
|
-
|
21
|
-
def inventory_items
|
22
|
-
@inventory_items ||= InventoryItem.where(id: inventory_id_and_quantities.pluck(:inventory_id))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class InventoryItemResetter < BaseInteractor
|
4
|
-
delegate :inventory_item, to: :context
|
5
|
-
|
6
|
-
def call
|
7
|
-
max_capacity = variant_total_inventory
|
8
|
-
total_purchases = variant_total_purchases
|
9
|
-
quantity_available = [max_capacity - total_purchases, 0].max
|
10
|
-
|
11
|
-
updated = inventory_item.update(max_capacity: max_capacity, quantity_available: quantity_available)
|
12
|
-
return context.fail!(message: 'Failed to update inventory item', errors: inventory_item.errors.full_messages) unless updated
|
13
|
-
|
14
|
-
clear_inventory_cache
|
15
|
-
end
|
16
|
-
|
17
|
-
def variant_total_inventory
|
18
|
-
# for shipment, total_on_hand is not orignal stock. shipment does subtract the stock.
|
19
|
-
# to get desire result, we need to add to total_purchase.
|
20
|
-
if inventory_item.variant.delivery_required?
|
21
|
-
inventory_item.variant.total_on_hand.to_i + variant_total_purchases
|
22
|
-
else
|
23
|
-
inventory_item.variant.total_on_hand.to_i
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def variant_total_purchases
|
28
|
-
scope = inventory_item.variant.complete_line_items
|
29
|
-
|
30
|
-
if inventory_item.permanent_stock?
|
31
|
-
scope.where('? BETWEEN from_date AND to_date', inventory_item.inventory_date).sum(:quantity).to_i
|
32
|
-
else
|
33
|
-
scope.sum(:quantity).to_i
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear_inventory_cache
|
38
|
-
SpreeCmCommissioner.redis_pool.with do |redis|
|
39
|
-
redis.del(inventory_item.redis_key)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class InventoryItemsAdjuster < BaseInteractor
|
4
|
-
delegate :variant, :quantity, to: :context
|
5
|
-
|
6
|
-
def call
|
7
|
-
variant.inventory_items.active.find_each do |inventory_item|
|
8
|
-
inventory_item.adjust_quantity!(quantity)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class InventoryItemsGenerator < BaseInteractor
|
4
|
-
delegate :variant, to: :context
|
5
|
-
|
6
|
-
def call
|
7
|
-
if variant.permanent_stock?
|
8
|
-
SpreeCmCommissioner::Stock::PermanentInventoryItemsGenerator.call(variant_ids: [variant.id])
|
9
|
-
else
|
10
|
-
variant.create_default_non_permanent_inventory_item! unless variant.default_inventory_item_exist?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class PermanentInventoryItemsGenerator < BaseInteractor
|
4
|
-
delegate :variant_ids, to: :context
|
5
|
-
|
6
|
-
def variants_per_batch = 1000
|
7
|
-
|
8
|
-
def pre_inventory_days_for(variant)
|
9
|
-
context.pre_inventory_days || variant.pre_inventory_days
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
variants.in_batches(of: variants_per_batch) do |batch|
|
14
|
-
generate_inventory_items_for_batch(batch)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def generate_inventory_items_for_batch(batch)
|
21
|
-
total_on_hand_by_variant = total_on_hand_for(batch)
|
22
|
-
batch.each do |variant|
|
23
|
-
count_on_hand = total_on_hand_by_variant[variant.id] || 0
|
24
|
-
generate_inventory_items_for_variant(variant, count_on_hand)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def generate_inventory_items_for_variant(variant, count_on_hand)
|
29
|
-
inventory_dates_for(variant).each do |inventory_date|
|
30
|
-
next if inventory_exist?(variant, inventory_date)
|
31
|
-
|
32
|
-
create_inventory_item(variant, inventory_date, count_on_hand)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def inventory_dates_for(variant)
|
37
|
-
start_date = Time.zone.tomorrow
|
38
|
-
end_date = Time.zone.today + pre_inventory_days_for(variant)
|
39
|
-
|
40
|
-
(start_date..end_date)
|
41
|
-
end
|
42
|
-
|
43
|
-
def inventory_exist?(variant, inventory_date)
|
44
|
-
variant.inventory_items.exists?(inventory_date: inventory_date)
|
45
|
-
end
|
46
|
-
|
47
|
-
def create_inventory_item(variant, inventory_date, count_on_hand)
|
48
|
-
variant.inventory_items.create!(
|
49
|
-
inventory_date: inventory_date,
|
50
|
-
quantity_available: count_on_hand,
|
51
|
-
max_capacity: count_on_hand,
|
52
|
-
product_type: variant.product_type
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Returns a hash: { variant_id => total_on_hand, ... }
|
57
|
-
def total_on_hand_for(variants)
|
58
|
-
variant_ids = variants.pluck(:id)
|
59
|
-
|
60
|
-
Spree::StockItem
|
61
|
-
.joins(:stock_location)
|
62
|
-
.where(deleted_at: nil, variant_id: variant_ids)
|
63
|
-
.where(spree_stock_locations: { active: true })
|
64
|
-
.group(:variant_id)
|
65
|
-
.sum(:count_on_hand)
|
66
|
-
end
|
67
|
-
|
68
|
-
def variants
|
69
|
-
scope = Spree::Variant.active.with_permanent_stock.where(is_master: false)
|
70
|
-
scope = scope.where(id: variant_ids) if variant_ids.present?
|
71
|
-
scope
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class StockMovementCreator < BaseInteractor
|
4
|
-
delegate :variant_id, :stock_location_id, :current_store, :stock_movement_params, to: :context
|
5
|
-
|
6
|
-
def call
|
7
|
-
variant = current_store.variants.find(variant_id)
|
8
|
-
|
9
|
-
return context.fail!(message: Spree.t(:doesnt_track_inventory)) unless variant.track_inventory?
|
10
|
-
|
11
|
-
stock_location = Spree::StockLocation.find(stock_location_id)
|
12
|
-
stock_movement = stock_location.stock_movements.build(stock_movement_params)
|
13
|
-
stock_movement.stock_item = stock_location.set_up_stock_item(variant)
|
14
|
-
|
15
|
-
if stock_movement.save
|
16
|
-
adjust_inventory_items_async(variant_id, stock_movement.quantity)
|
17
|
-
context.stock_movement = stock_movement
|
18
|
-
else
|
19
|
-
context.fail!(message: stock_movement.errors.full_messages.join(', '))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def adjust_inventory_items_async(variant_id, quantity)
|
26
|
-
CmAppLogger.log(label: "#{self.class.name}#adjust_inventory_items_async", data: { variant_id: variant_id, quantity: quantity }) do
|
27
|
-
SpreeCmCommissioner::Stock::InventoryItemsAdjusterJob.perform_later(variant_id: variant_id, quantity: quantity)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class TaxiTripCreator < BaseInteractor
|
3
|
-
delegate :trip_params, to: :context
|
4
|
-
|
5
|
-
def call
|
6
|
-
ActiveRecord::Base.transaction do
|
7
|
-
create_trip_with_product
|
8
|
-
create_variant
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def create_trip_with_product
|
15
|
-
trip = SpreeCmCommissioner::Trip.new(trip_params)
|
16
|
-
|
17
|
-
if trip.save
|
18
|
-
context.trip = trip
|
19
|
-
context.product = trip.product
|
20
|
-
assign_option_type_to_product
|
21
|
-
context.product.save
|
22
|
-
else
|
23
|
-
context.fail!(error: "Failed to create taxi trip: #{trip.errors.full_messages.join(', ')}")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_variant
|
28
|
-
variant = context.product.variants.new(
|
29
|
-
price: trip_params['product_attributes']['price'],
|
30
|
-
sku: "TRIP-#{context.formatted_name}-#{Time.current.to_i}",
|
31
|
-
option_value_ids: option_value_ids
|
32
|
-
)
|
33
|
-
|
34
|
-
if variant.save
|
35
|
-
context.variant = variant
|
36
|
-
create_stock_item_for_variant(variant)
|
37
|
-
else
|
38
|
-
context.fail!(error: "Failed to create taxi trip variant: #{variant.errors.full_messages.join(', ')}")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def create_stock_item_for_variant(variant)
|
43
|
-
stock_location = context.product.vendor.stock_location
|
44
|
-
if stock_location.present?
|
45
|
-
Spree::StockItem.find_or_create_by!(variant: variant, stock_location: stock_location) do |item|
|
46
|
-
item.count_on_hand = 1
|
47
|
-
end
|
48
|
-
else
|
49
|
-
context.fail!(error: 'Vendor does not have an active stock location.')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def assign_option_type_to_product
|
54
|
-
option_type = Spree::OptionType.find_by(name: 'intercity-taxi')
|
55
|
-
return unless option_type
|
56
|
-
|
57
|
-
context.product.option_types << option_type
|
58
|
-
end
|
59
|
-
|
60
|
-
def option_value_ids
|
61
|
-
context.product.option_types.flat_map do |option_type|
|
62
|
-
option_type.option_values.pluck(:id)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class VariantBlockUpdater < BaseInteractor
|
3
|
-
delegate :variant, :data, :stock_location, :current_store, to: :context
|
4
|
-
|
5
|
-
def call
|
6
|
-
block_ids = data[:block_ids] || []
|
7
|
-
|
8
|
-
ActiveRecord::Base.transaction do
|
9
|
-
update_variant_block!(block_ids, variant)
|
10
|
-
update_stock_item!(variant)
|
11
|
-
end
|
12
|
-
|
13
|
-
context.message = 'Update variant blocks successfully'
|
14
|
-
rescue StandardError => e
|
15
|
-
context.fail!(message: "Update variant blocks Failed: #{e.message}")
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def update_variant_block!(block_ids, variant)
|
21
|
-
variant.variant_blocks.where.not(block_id: block_ids).destroy_all
|
22
|
-
|
23
|
-
block_ids.each do |block_id|
|
24
|
-
next unless SpreeCmCommissioner::Block.exists?(id: block_id) # Skip invalid block_ids
|
25
|
-
|
26
|
-
block = SpreeCmCommissioner::VariantBlock.find_by(
|
27
|
-
block_id: block_id,
|
28
|
-
trip_id: variant.product.trip.id,
|
29
|
-
variant_id: variant.id
|
30
|
-
)
|
31
|
-
|
32
|
-
next unless block.nil?
|
33
|
-
|
34
|
-
SpreeCmCommissioner::VariantBlock.create!(
|
35
|
-
block_id: block_id,
|
36
|
-
trip_id: variant.product.trip.id,
|
37
|
-
variant_id: variant.id
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def update_stock_item!(variant)
|
43
|
-
stock_items = variant.stock_items
|
44
|
-
|
45
|
-
context.fail!(message: 'Variant has more than one stock item. Please report to admin.') if stock_items.count > 1
|
46
|
-
|
47
|
-
stock_item = stock_items.first || variant.stock_items.create!(stock_location: stock_location)
|
48
|
-
quantity_difference = variant.variant_blocks.count - stock_item.count_on_hand
|
49
|
-
|
50
|
-
resource = SpreeCmCommissioner::Stock::StockMovementCreator.call(
|
51
|
-
variant_id: variant.id,
|
52
|
-
stock_location_id: stock_location.id,
|
53
|
-
current_store: current_store,
|
54
|
-
stock_movement_params: { quantity: quantity_difference }
|
55
|
-
)
|
56
|
-
|
57
|
-
return if resource.success?
|
58
|
-
|
59
|
-
context.fail!(message: "Stock update failed: #{resource.errors}")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class VehicleUpdater < BaseInteractor
|
3
|
-
def call
|
4
|
-
vehicle = context.vehicle
|
5
|
-
data = context.data
|
6
|
-
|
7
|
-
option_value_ids = data[:option_value_ids] || []
|
8
|
-
option_type_ids = data[:option_type_ids] || []
|
9
|
-
|
10
|
-
ActiveRecord::Base.transaction do
|
11
|
-
update_vehicle!(vehicle, data[:vehicle_attributes])
|
12
|
-
update_amenities!(vehicle, option_value_ids, option_type_ids)
|
13
|
-
end
|
14
|
-
|
15
|
-
context.message = I18n.t('views.transit.vehicles.update_success')
|
16
|
-
rescue StandardError => e
|
17
|
-
context.fail!(message: "Failed to update vehicle: #{e.message}")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def update_vehicle!(vehicle, attributes)
|
23
|
-
return if vehicle.update(attributes.slice(:code, :license_plate, :allow_seat_selection, :vehicle_type, :number_of_seats))
|
24
|
-
|
25
|
-
raise vehicle.errors.full_messages.to_sentence
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_amenities!(vehicle, option_value_ids, option_type_ids)
|
29
|
-
vehicle.option_value_vehicles.where.not(option_value_id: option_value_ids).destroy_all
|
30
|
-
vehicle.vehicle_option_types.where.not(option_type_id: option_type_ids).destroy_all
|
31
|
-
|
32
|
-
option_value_ids.each do |option_value_id|
|
33
|
-
vehicle.option_value_vehicles.find_or_create_by(option_value_id: option_value_id)
|
34
|
-
end
|
35
|
-
|
36
|
-
option_type_ids.each do |option_type_id|
|
37
|
-
vehicle.vehicle_option_types.find_or_create_by(option_type_id: option_type_id)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class InventoryItemsAdjusterJob < ApplicationUniqueJob
|
4
|
-
def perform(variant_id:, quantity:)
|
5
|
-
variant = Spree::Variant.find(variant_id)
|
6
|
-
|
7
|
-
SpreeCmCommissioner::Stock::InventoryItemsAdjuster.call(variant: variant, quantity: quantity)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module Stock
|
3
|
-
class InventoryItemsGeneratorJob < ApplicationUniqueJob
|
4
|
-
def perform(variant_id:)
|
5
|
-
variant = Spree::Variant.find(variant_id)
|
6
|
-
|
7
|
-
SpreeCmCommissioner::Stock::InventoryItemsGenerator.call(variant: variant)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|