spree_cm_commissioner 2.3.2.pre.pre6 → 2.3.2
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/controllers/spree/api/v2/storefront/intercity_taxi/draft_orders_controller.rb +11 -52
- data/app/factory/spree_cm_commissioner/order_telegram_message_factory.rb +0 -12
- data/app/mailers/spree/order_mailer_decorator.rb +6 -8
- data/app/models/concerns/spree_cm_commissioner/line_item_transitable.rb +89 -34
- data/app/models/concerns/spree_cm_commissioner/service_recommendations.rb +2 -2
- data/app/models/spree_cm_commissioner/adjustment_decorator.rb +1 -1
- data/app/models/spree_cm_commissioner/order_decorator.rb +1 -1
- data/app/models/spree_cm_commissioner/place.rb +0 -7
- data/app/models/spree_cm_commissioner/tenant.rb +0 -4
- data/app/models/spree_cm_commissioner/variant_decorator.rb +0 -3
- data/app/models/spree_cm_commissioner/vendor_decorator.rb +0 -1
- data/app/models/spree_cm_commissioner/vendor_place.rb +0 -9
- data/app/queries/spree_cm_commissioner/trip_query.rb +17 -23
- data/app/serializers/spree/v2/storefront/place_serializer.rb +2 -3
- data/app/serializers/spree/v2/tenant/cart_serializer.rb +0 -1
- data/app/serializers/spree/v2/tenant/line_item_serializer.rb +0 -1
- data/app/serializers/spree_cm_commissioner/v2/storefront/intercity_taxi_line_item_serializer.rb +18 -17
- data/app/services/spree_cm_commissioner/intercity_taxi_order/create.rb +23 -20
- data/app/services/spree_cm_commissioner/intercity_taxi_order/update.rb +72 -36
- data/app/views/spree/order_mailer/confirm_email.html.erb +1 -1
- data/app/views/spree_cm_commissioner/order_mailer/_mailer_stylesheets.html.erb +13 -14
- data/app/views/spree_cm_commissioner/order_mailer/tenant/_greeting.html.erb +4 -6
- data/config/routes.rb +1 -11
- data/lib/spree_cm_commissioner/version.rb +1 -1
- data/lib/spree_cm_commissioner.rb +0 -2
- metadata +4 -51
- data/app/controllers/spree/api/v2/storefront/popular_route_places_controller.rb +0 -63
- data/app/controllers/spree/api/v2/storefront/route_places_controller.rb +0 -68
- data/app/controllers/spree/api/v2/tenant/intercity_taxi/draft_orders_controller.rb +0 -81
- data/app/controllers/spree/api/v2/tenant/trip_places_controller.rb +0 -42
- data/app/controllers/spree/api/v2/tenant/trip_search_controller.rb +0 -103
- data/app/controllers/spree/api/v2/tenant/trips_controller.rb +0 -32
- data/app/finders/spree_cm_commissioner/places/find_with_route.rb +0 -43
- data/app/finders/spree_cm_commissioner/routes/find_popular.rb +0 -25
- data/app/models/spree_cm_commissioner/calculators/extra_drop_off_distance.rb +0 -15
- data/app/models/spree_cm_commissioner/calculators/extra_pick_up_distance.rb +0 -15
- data/app/models/spree_cm_commissioner/pricing_action.rb +0 -27
- data/app/models/spree_cm_commissioner/pricing_model.rb +0 -18
- data/app/models/spree_cm_commissioner/pricing_model_variant.rb +0 -6
- data/app/models/spree_cm_commissioner/pricing_rule.rb +0 -15
- data/app/models/spree_cm_commissioner/pricing_rule_group.rb +0 -20
- data/app/models/spree_cm_commissioner/pricing_rules/extra_drop_off_distance.rb +0 -10
- data/app/models/spree_cm_commissioner/pricing_rules/extra_pick_up_distance.rb +0 -12
- data/app/models/spree_cm_commissioner/pricing_rules/nationality.rb +0 -35
- data/app/request_schemas/spree_cm_commissioner/intercity_taxi_draft_order_schema.rb +0 -10
- data/app/request_schemas/spree_cm_commissioner/intercity_taxi_draft_order_update_schema.rb +0 -29
- data/app/request_schemas/spree_cm_commissioner/route_places_request_schema.rb +0 -12
- data/app/serializers/spree/v2/tenant/intercity_taxi_cart_serializer.rb +0 -12
- data/app/serializers/spree/v2/tenant/trip_place_serializer.rb +0 -8
- data/app/serializers/spree/v2/tenant/trip_query_result_serializer.rb +0 -8
- data/app/serializers/spree/v2/tenant/trip_serializer.rb +0 -8
- data/app/serializers/spree_cm_commissioner/v2/storefront/route_serializer.rb +0 -12
- data/app/services/spree_cm_commissioner/pricing_models/apply.rb +0 -51
- data/app/services/spree_cm_commissioner/pricing_rules/build_params.rb +0 -53
- data/app/services/spree_cm_commissioner/pricing_rules/build_template.rb +0 -27
- data/app/services/spree_cm_commissioner/pricing_rules/create.rb +0 -10
- data/app/services/spree_cm_commissioner/pricing_rules/update.rb +0 -11
- data/app/services/spree_cm_commissioner/vendor_places/base.rb +0 -24
- data/app/services/spree_cm_commissioner/vendor_places/bulk_create.rb +0 -70
- data/app/services/spree_cm_commissioner/vendor_places/create_with_google_map_data.rb +0 -85
- data/app/services/spree_cm_commissioner/vendor_places/update.rb +0 -56
- data/db/migrate/20250915075830_create_spree_cm_commissioner_pricing_models.rb +0 -17
- data/db/migrate/20250915080733_create_spree_cm_commissioner_pricing_model_variants.rb +0 -14
- data/db/migrate/20251003082144_create_spree_cm_commissioner_pricing_rule_groups.rb +0 -16
- data/db/migrate/20251003093408_create_spree_cm_commissioner_pricing_rule.rb +0 -19
- data/db/migrate/20251003093643_create_spree_cm_commissioner_pricing_action.rb +0 -14
- data/db/migrate/20251119093000_add_tenant_id_to_cm_vendor_places.rb +0 -8
- data/lib/spree_cm_commissioner/intercity_taxi/distance.rb +0 -38
- data/lib/spree_cm_commissioner/intercity_taxi/map_place.rb +0 -31
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_action_factory.rb +0 -5
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_model_factory.rb +0 -8
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_rule_factory.rb +0 -17
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_rule_group_factory.rb +0 -8
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
module SpreeCmCommissioner
|
|
2
|
-
module PricingRules
|
|
3
|
-
module BuildParams
|
|
4
|
-
module_function
|
|
5
|
-
|
|
6
|
-
def permitted_group_params(params)
|
|
7
|
-
group_params = params[:spree_cm_commissioner_pricing_rule_group] || params
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
name: group_params[:name],
|
|
11
|
-
status: group_params[:status],
|
|
12
|
-
template_key: group_params[:template_key],
|
|
13
|
-
match_type: group_params[:match_type],
|
|
14
|
-
pricing_rules_attributes: build_rules_attributes(params[:pricing_rules]),
|
|
15
|
-
pricing_action_attributes: build_action_attributes(params[:pricing_action])
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def build_rules_attributes(rules_array)
|
|
20
|
-
return [] unless rules_array
|
|
21
|
-
|
|
22
|
-
rules_array.map do |r|
|
|
23
|
-
{
|
|
24
|
-
id: r[:id],
|
|
25
|
-
type: r[:type],
|
|
26
|
-
private_metadata: r[:private_metadata],
|
|
27
|
-
_destroy: r[:_destroy]
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def build_action_attributes(action_data)
|
|
33
|
-
return nil unless action_data&.dig(:calculator)
|
|
34
|
-
|
|
35
|
-
calc_data = action_data[:calculator]
|
|
36
|
-
calculator = calc_data[:type].safe_constantize&.new
|
|
37
|
-
set_preferences(calculator, calc_data[:preferences]) if calculator
|
|
38
|
-
|
|
39
|
-
{ id: action_data[:id], calculator: calculator }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def set_preferences(calculator, preferences)
|
|
43
|
-
return unless preferences && calculator
|
|
44
|
-
|
|
45
|
-
prefs = preferences.respond_to?(:to_unsafe_h) ? preferences.to_unsafe_h : preferences
|
|
46
|
-
prefs.each do |key, value|
|
|
47
|
-
setter = "preferred_#{key}="
|
|
48
|
-
calculator.public_send(setter, value) if calculator.respond_to?(setter)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module SpreeCmCommissioner
|
|
2
|
-
module PricingRules
|
|
3
|
-
class BuildTemplate
|
|
4
|
-
def self.call(pricing_model:, template_key:)
|
|
5
|
-
template = PRICING_RULE_GROUP_TEMPLATES[template_key.to_sym]
|
|
6
|
-
return unless template
|
|
7
|
-
|
|
8
|
-
group = pricing_model.pricing_rule_groups.build
|
|
9
|
-
|
|
10
|
-
template[:rules]&.each do |rule_data|
|
|
11
|
-
group.pricing_rules.where(type: rule_data[:type]).build(
|
|
12
|
-
type: rule_data[:type],
|
|
13
|
-
private_metadata: rule_data[:private_metadata] || {}
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
if template[:action]
|
|
18
|
-
calculator = template[:action][:calculator_type].constantize.new
|
|
19
|
-
BuildParams.set_preferences(calculator, template[:action][:preferences])
|
|
20
|
-
group.build_pricing_action(calculator: calculator)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
group
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module SpreeCmCommissioner
|
|
2
|
-
module VendorPlaces
|
|
3
|
-
class Base
|
|
4
|
-
prepend ::Spree::ServiceModule::Base
|
|
5
|
-
|
|
6
|
-
ALLOWED_PLACE_TYPES = %w[venue stop branch location].freeze
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
def validate_place_type!(place_type)
|
|
11
|
-
return I18n.t('controller.vendor_places.place_type_required', default: 'Place type is required') if place_type.nil?
|
|
12
|
-
|
|
13
|
-
unless ALLOWED_PLACE_TYPES.include?(place_type.to_s)
|
|
14
|
-
return I18n.t(
|
|
15
|
-
'controller.vendor_places.invalid_place_type',
|
|
16
|
-
default: "Place type must be one of: #{ALLOWED_PLACE_TYPES.join(', ')}"
|
|
17
|
-
)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
nil
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Bulk creates vendor places of any valid type (e.g., :stop, :branch, :location) with validation and transaction support.
|
|
2
|
-
#
|
|
3
|
-
# Validates place_ids count and creates vendor places atomically.
|
|
4
|
-
# Rolls back all changes if any creation fails.
|
|
5
|
-
#
|
|
6
|
-
# Usage:
|
|
7
|
-
# result = SpreeCmCommissioner::VendorPlaces::BulkCreate.call(
|
|
8
|
-
# vendor: current_vendor,
|
|
9
|
-
# place_ids: [1, 2, 3],
|
|
10
|
-
# place_type: :location, # or :stop, :branch, etc.
|
|
11
|
-
# description: "Sample description",
|
|
12
|
-
# max_count: 10,
|
|
13
|
-
# location: parent_location # required for :stop and :branch
|
|
14
|
-
# )
|
|
15
|
-
#
|
|
16
|
-
# if result.success?
|
|
17
|
-
# created_vendor_places = result.value
|
|
18
|
-
# else
|
|
19
|
-
# error_message = result.error
|
|
20
|
-
|
|
21
|
-
module SpreeCmCommissioner
|
|
22
|
-
module VendorPlaces
|
|
23
|
-
class BulkCreate < Base
|
|
24
|
-
def call(vendor:, place_ids:, place_type:, description: nil, max_count: 10, location: nil) # rubocop:disable Metrics/ParameterLists
|
|
25
|
-
error_message = validate_inputs!(place_ids: place_ids, place_type: place_type, max_count: max_count, location: location)
|
|
26
|
-
return failure(nil, error_message) if error_message
|
|
27
|
-
|
|
28
|
-
created_vendor_places = []
|
|
29
|
-
|
|
30
|
-
ActiveRecord::Base.transaction do
|
|
31
|
-
place_ids.each do |place_id|
|
|
32
|
-
vendor_place = build_vendor_place(
|
|
33
|
-
vendor: vendor,
|
|
34
|
-
place_id: place_id,
|
|
35
|
-
place_type: place_type,
|
|
36
|
-
description: description,
|
|
37
|
-
location: location
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
vendor_place.save!
|
|
41
|
-
created_vendor_places << vendor_place
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
success(created_vendor_places)
|
|
46
|
-
rescue ActiveRecord::RecordInvalid => e
|
|
47
|
-
failure(nil, e.record.errors.full_messages.to_sentence)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
def validate_inputs!(place_ids:, place_type:, max_count:, location: nil)
|
|
53
|
-
validate_place_type!(place_type) ||
|
|
54
|
-
(place_ids.blank? && I18n.t('controller.vendor_places.place_ids_blank')) ||
|
|
55
|
-
(place_ids.size > max_count && I18n.t('controller.vendor_places.selection_limit', count: max_count)) ||
|
|
56
|
-
(requires_location?(place_type: place_type) && location.blank? && I18n.t('controller.vendor_places.location_required'))
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def build_vendor_place(vendor:, place_id:, place_type:, description:, location: nil)
|
|
60
|
-
attrs = { vendor_id: vendor.id, place_type: place_type.to_sym, place_id: place_id, description: description }
|
|
61
|
-
attrs[:location_id] = location&.id if requires_location?(place_type: place_type)
|
|
62
|
-
SpreeCmCommissioner::VendorPlace.new(attrs)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def requires_location?(place_type:)
|
|
66
|
-
%i[stop branch].include?(place_type.to_sym)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Creates a vendor place from Google Map base64-encoded place data.
|
|
2
|
-
# Processes place data and creates both Place and VendorPlace records atomically.
|
|
3
|
-
#
|
|
4
|
-
# Usage:
|
|
5
|
-
# result = SpreeCmCommissioner::VendorPlaces::CreateWithGoogleMapData.call(
|
|
6
|
-
# vendor: current_vendor,
|
|
7
|
-
# place_type: 'stop',
|
|
8
|
-
# google_place_base_64_content: google_place_base_64_content,
|
|
9
|
-
# description: 'Main Warehouse',
|
|
10
|
-
# location: parent_vendor_location
|
|
11
|
-
# )
|
|
12
|
-
#
|
|
13
|
-
# if result.success?
|
|
14
|
-
# vendor_place = result.value
|
|
15
|
-
# else
|
|
16
|
-
# error_message = result.error
|
|
17
|
-
# end
|
|
18
|
-
|
|
19
|
-
module SpreeCmCommissioner
|
|
20
|
-
module VendorPlaces
|
|
21
|
-
class CreateWithGoogleMapData < Base
|
|
22
|
-
def call(vendor:, place_type:, google_place_base_64_content:, description: nil, location: nil)
|
|
23
|
-
error_message = validate_place_type!(place_type)
|
|
24
|
-
return failure(nil, error_message) if error_message.present?
|
|
25
|
-
|
|
26
|
-
# Only require location for stop and branch types
|
|
27
|
-
return failure(nil, I18n.t('controller.vendor_places.location_required')) if %w[stop branch].include?(place_type) && location.nil?
|
|
28
|
-
|
|
29
|
-
place = process_place(google_place_base_64_content: google_place_base_64_content)
|
|
30
|
-
return failure(nil, place) unless place.is_a?(SpreeCmCommissioner::Place)
|
|
31
|
-
|
|
32
|
-
vendor_place = create_vendor_place(vendor: vendor, place: place, place_type: place_type, description: description, location: location)
|
|
33
|
-
return failure(nil, vendor_place) if vendor_place.nil? || vendor_place.is_a?(String)
|
|
34
|
-
|
|
35
|
-
success(vendor_place)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def process_place(google_place_base_64_content:)
|
|
41
|
-
place = SpreeCmCommissioner::PlaceDecoder.process_place(google_place_base_64_content)
|
|
42
|
-
return I18n.t('controller.vendor_places.process_place_failed', default: 'Failed to process place') if place.nil? || !place.save
|
|
43
|
-
|
|
44
|
-
place
|
|
45
|
-
rescue StandardError => e
|
|
46
|
-
e.message
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def create_vendor_place(vendor:, place:, place_type:, description:, location:)
|
|
50
|
-
error_message = nil
|
|
51
|
-
result = ActiveRecord::Base.transaction do
|
|
52
|
-
vendor_place = build_vendor_place(vendor: vendor, place: place, type: place_type, description: description, location: location)
|
|
53
|
-
unless vendor_place.save
|
|
54
|
-
error_message = vendor_place.errors.full_messages.to_sentence
|
|
55
|
-
raise ActiveRecord::Rollback
|
|
56
|
-
end
|
|
57
|
-
vendor_place
|
|
58
|
-
end
|
|
59
|
-
error_message || result
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def build_vendor_place(vendor:, place:, type:, description: nil, location: nil)
|
|
63
|
-
case type
|
|
64
|
-
when 'stop'
|
|
65
|
-
vendor.stops.new(
|
|
66
|
-
place_id: place.id,
|
|
67
|
-
description: description,
|
|
68
|
-
location_id: location&.id
|
|
69
|
-
)
|
|
70
|
-
when 'branch'
|
|
71
|
-
vendor.branches.new(
|
|
72
|
-
place_id: place.id,
|
|
73
|
-
description: description,
|
|
74
|
-
location_id: location&.id
|
|
75
|
-
)
|
|
76
|
-
when 'location'
|
|
77
|
-
vendor.locations.new(
|
|
78
|
-
place_id: place.id,
|
|
79
|
-
description: description
|
|
80
|
-
)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Updates all vendor places matching the same vendor, place_id, and location_id.
|
|
2
|
-
# Only updates description and location_id. Rolls back if any update fails.
|
|
3
|
-
#
|
|
4
|
-
# Usage:
|
|
5
|
-
# result = SpreeCmCommissioner::VendorPlaces::Update.call(
|
|
6
|
-
# vendor: current_vendor,
|
|
7
|
-
# vendor_place: existing_vendor_place,
|
|
8
|
-
# location_id: new_location_id,
|
|
9
|
-
# description: 'Updated description'
|
|
10
|
-
# )
|
|
11
|
-
#
|
|
12
|
-
# if result.success?
|
|
13
|
-
# updated_place = result.value
|
|
14
|
-
# else
|
|
15
|
-
# error_message = result.error
|
|
16
|
-
# end
|
|
17
|
-
module SpreeCmCommissioner
|
|
18
|
-
module VendorPlaces
|
|
19
|
-
class Update < Base
|
|
20
|
-
def call(vendor:, vendor_place:, description: nil, location_id: nil)
|
|
21
|
-
if vendor_place.blank?
|
|
22
|
-
return failure(
|
|
23
|
-
nil,
|
|
24
|
-
I18n.t('controller.vendor_places.vendor_place_not_found', default: 'Vendor place not found')
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
ActiveRecord::Base.transaction do
|
|
29
|
-
related_places = SpreeCmCommissioner::VendorPlace.where(
|
|
30
|
-
vendor_id: vendor.id,
|
|
31
|
-
place_id: vendor_place.place_id,
|
|
32
|
-
location_id: vendor_place.location_id
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
update_attrs = {}
|
|
36
|
-
update_attrs[:description] = description unless description.nil?
|
|
37
|
-
update_attrs[:location_id] = location_id unless location_id.nil?
|
|
38
|
-
|
|
39
|
-
related_places.each do |vp|
|
|
40
|
-
unless vp.update(update_attrs)
|
|
41
|
-
error_message = vp.errors.full_messages.to_sentence
|
|
42
|
-
raise ActiveRecord::Rollback, error_message
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
vendor_place.reload
|
|
48
|
-
success(vendor_place)
|
|
49
|
-
rescue ActiveRecord::RecordInvalid => e
|
|
50
|
-
failure(nil, e.record.errors.full_messages.to_sentence)
|
|
51
|
-
rescue ActiveRecord::Rollback => e
|
|
52
|
-
failure(nil, e.message)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class CreateSpreeCmCommissionerPricingModels < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :cm_pricing_models, if_not_exists: true do |t|
|
|
4
|
-
t.string :name, null: false
|
|
5
|
-
t.text :description
|
|
6
|
-
t.integer :status, default: 0, null: false
|
|
7
|
-
t.integer :position, null: false, default: 0
|
|
8
|
-
|
|
9
|
-
t.references :vendor, null: false, foreign_key: { to_table: :spree_vendors }
|
|
10
|
-
|
|
11
|
-
t.timestamps
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
add_index :cm_pricing_models, :position unless index_exists?(:cm_pricing_models, :position)
|
|
15
|
-
add_index :cm_pricing_models, :vendor_id unless index_exists?(:cm_pricing_models, :vendor_id)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class CreateSpreeCmCommissionerPricingModelVariants < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :cm_pricing_model_variants, if_not_exists: true do |t|
|
|
4
|
-
t.references :pricing_model, null: false, foreign_key: { to_table: :cm_pricing_models }
|
|
5
|
-
t.references :variant, null: false, foreign_key: { to_table: :spree_variants }
|
|
6
|
-
t.references :product, null: true, foreign_key: { to_table: :spree_products }
|
|
7
|
-
|
|
8
|
-
t.timestamps
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
add_index :cm_pricing_model_variants, [:pricing_model_id, :variant_id], name: 'idx_pm_variants_on_model_variant'
|
|
12
|
-
add_index :cm_pricing_model_variants, [:pricing_model_id, :product_id], name: 'idx_pm_variants_on_model_product'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class CreateSpreeCmCommissionerPricingRuleGroups < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :cm_pricing_rule_groups, if_not_exists: true do |t|
|
|
4
|
-
t.references :pricing_model, null: false, foreign_key: { to_table: :cm_pricing_models }
|
|
5
|
-
t.string :name
|
|
6
|
-
t.integer :position, default: 0
|
|
7
|
-
t.integer :status, default: 0, null: false
|
|
8
|
-
t.jsonb :public_metadata
|
|
9
|
-
t.jsonb :private_metadata
|
|
10
|
-
t.timestamps
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
add_index :cm_pricing_rule_groups, :pricing_model_id, name: 'idx_rule_groups_on_model'
|
|
14
|
-
add_index :cm_pricing_rule_groups, [:pricing_model_id, :position], name: 'idx_rule_groups_on_model_position'
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class CreateSpreeCmCommissionerPricingRule < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :cm_pricing_rules, if_not_exists: true do |t|
|
|
4
|
-
t.references :pricing_rule_group, null: false, foreign_key: { to_table: :cm_pricing_rule_groups }
|
|
5
|
-
t.references :product, null: true, foreign_key: { to_table: :spree_products }
|
|
6
|
-
t.references :variant, null: true, foreign_key: { to_table: :spree_variants }
|
|
7
|
-
t.string :type, null: false
|
|
8
|
-
t.jsonb :public_metadata
|
|
9
|
-
t.jsonb :private_metadata
|
|
10
|
-
t.integer :position, null: false, default: 0
|
|
11
|
-
|
|
12
|
-
t.timestamps
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
add_index :cm_pricing_rules, :position, name: 'idx_pricing_rules_on_position'
|
|
16
|
-
add_index :cm_pricing_rules, [:pricing_rule_group_id, :product_id], name: 'idx_pricing_rules_on_group_product'
|
|
17
|
-
add_index :cm_pricing_rules, [:pricing_rule_group_id, :variant_id], name: 'idx_pricing_rules_on_group_variant'
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class CreateSpreeCmCommissionerPricingAction < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :cm_pricing_actions, if_not_exists: true do |t|
|
|
4
|
-
t.references :pricing_rule_group, null: false, foreign_key: { to_table: :cm_pricing_rule_groups }
|
|
5
|
-
t.references :product, null: true, foreign_key: { to_table: :spree_products }
|
|
6
|
-
t.references :variant, null: true, foreign_key: { to_table: :spree_variants }
|
|
7
|
-
|
|
8
|
-
t.timestamps
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
add_index :cm_pricing_actions, [:pricing_rule_group_id, :product_id], name: 'idx_pricing_actions_on_group_product'
|
|
12
|
-
add_index :cm_pricing_actions, [:pricing_rule_group_id, :variant_id], name: 'idx_pricing_actions_on_group_variant'
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
class AddTenantIdToCmVendorPlaces < ActiveRecord::Migration[7.0]
|
|
2
|
-
def change
|
|
3
|
-
add_column :cm_vendor_places, :tenant_id, :integer, if_not_exists: true
|
|
4
|
-
# Why: VendorPlace#before_save sets tenant_id from vendor; tenant APIs (TripPlacesController) and TripQuery
|
|
5
|
-
# join on vendor_places scoped by tenant, so this speeds tenant-scoped lookups
|
|
6
|
-
add_index :cm_vendor_places, :tenant_id, if_not_exists: true
|
|
7
|
-
end
|
|
8
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module SpreeCmCommissioner
|
|
2
|
-
module IntercityTaxi
|
|
3
|
-
class Distance
|
|
4
|
-
attr_accessor :distance_km, :ordered_points, :estimated_time_minutes, :base_km,
|
|
5
|
-
:detour_pickup_km, :detour_dropoff_km, :extra_pickup_km, :extra_dropoff_km
|
|
6
|
-
|
|
7
|
-
def initialize(options = {})
|
|
8
|
-
options = options.stringify_keys if options.is_a?(Hash)
|
|
9
|
-
|
|
10
|
-
@distance_km = options['distance_km']&.to_f
|
|
11
|
-
@ordered_points = options['ordered_points']
|
|
12
|
-
@estimated_time_minutes = options['estimated_time_minutes']&.to_i
|
|
13
|
-
@base_km = options['base_km']&.to_f
|
|
14
|
-
@detour_pickup_km = options['detour_pickup_km']&.to_f
|
|
15
|
-
@detour_dropoff_km = options['detour_dropoff_km']&.to_f
|
|
16
|
-
@extra_pickup_km = options['extra_pickup_km']&.to_f
|
|
17
|
-
@extra_dropoff_km = options['extra_dropoff_km']&.to_f
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.from_hash(hash)
|
|
21
|
-
new(hash || {})
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def to_h
|
|
25
|
-
{
|
|
26
|
-
'distance_km' => @distance_km,
|
|
27
|
-
'ordered_points' => @ordered_points,
|
|
28
|
-
'estimated_time_minutes' => @estimated_time_minutes,
|
|
29
|
-
'base_km' => @base_km,
|
|
30
|
-
'detour_pickup_km' => @detour_pickup_km,
|
|
31
|
-
'detour_dropoff_km' => @detour_dropoff_km,
|
|
32
|
-
'extra_pickup_km' => @extra_pickup_km,
|
|
33
|
-
'extra_dropoff_km' => @extra_dropoff_km
|
|
34
|
-
}.compact
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module SpreeCmCommissioner
|
|
2
|
-
module IntercityTaxi
|
|
3
|
-
class MapPlace
|
|
4
|
-
attr_accessor :place_name, :lat, :lng, :oob_confirmed
|
|
5
|
-
|
|
6
|
-
def initialize(options = {})
|
|
7
|
-
options = options.stringify_keys if options.is_a?(Hash)
|
|
8
|
-
|
|
9
|
-
@place_name = options['place_name']
|
|
10
|
-
@lat = options['lat']&.to_f
|
|
11
|
-
@lng = options['lng']&.to_f
|
|
12
|
-
|
|
13
|
-
# Normalize truthy/falsey values ("true", "1", 1, etc.) to a real boolean.
|
|
14
|
-
@oob_confirmed = ActiveModel::Type::Boolean.new.cast(options['oob_confirmed'])
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.from_hash(hash)
|
|
18
|
-
new(hash || {})
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def to_h
|
|
22
|
-
{
|
|
23
|
-
'place_name' => @place_name,
|
|
24
|
-
'lat' => @lat,
|
|
25
|
-
'lng' => @lng,
|
|
26
|
-
'oob_confirmed' => @oob_confirmed
|
|
27
|
-
}.compact
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
FactoryBot.define do
|
|
2
|
-
factory :cm_pricing_model, class: "SpreeCmCommissioner::PricingModel" do
|
|
3
|
-
association :vendor, factory: :cm_vendor
|
|
4
|
-
sequence(:name) { |n| "Pricing Model #{n}" }
|
|
5
|
-
description { "Test pricing model description" }
|
|
6
|
-
status { 'active' }
|
|
7
|
-
end
|
|
8
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
FactoryBot.define do
|
|
2
|
-
factory :pricing_rule_nationality, class: 'SpreeCmCommissioner::PricingRules::Nationality' do
|
|
3
|
-
association :pricing_rule_group, factory: :pricing_rule_group
|
|
4
|
-
rule_type { 'must' }
|
|
5
|
-
nationalities { ["Cambodian"] }
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
factory :pricing_rule_extra_pick_up_distance, class: 'SpreeCmCommissioner::PricingRules::ExtraPickUpDistance' do
|
|
9
|
-
association :pricing_rule_group, factory: :pricing_rule_group
|
|
10
|
-
min_distance { 5 }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
factory :pricing_rule_extra_drop_off_distance, class: 'SpreeCmCommissioner::PricingRules::ExtraDropOffDistance' do
|
|
14
|
-
association :pricing_rule_group, factory: :pricing_rule_group
|
|
15
|
-
min_distance { 5 }
|
|
16
|
-
end
|
|
17
|
-
end
|