spree_cm_commissioner 2.3.2.pre.pre2 → 2.3.2.pre.pre5
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 +36 -36
- data/app/controllers/spree/api/v2/storefront/popular_route_places_controller.rb +63 -0
- data/app/controllers/spree/api/v2/storefront/route_places_controller.rb +68 -0
- data/app/controllers/spree/api/v2/tenant/intercity_taxi/draft_orders_controller.rb +37 -37
- data/app/controllers/spree/api/v2/tenant/trip_places_controller.rb +5 -11
- data/app/controllers/spree/api/v2/tenant/trip_search_controller.rb +1 -1
- data/app/controllers/spree/api/v2/tenant/trips_controller.rb +8 -8
- data/app/factory/spree_cm_commissioner/order_telegram_message_factory.rb +12 -0
- data/app/finders/spree_cm_commissioner/places/find_with_route.rb +43 -0
- data/app/finders/spree_cm_commissioner/routes/find_popular.rb +25 -0
- data/app/mailers/spree/order_mailer_decorator.rb +8 -6
- data/app/models/concerns/spree_cm_commissioner/line_item_transitable.rb +34 -89
- 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/calculators/extra_drop_off_distance.rb +15 -0
- data/app/models/spree_cm_commissioner/calculators/extra_pick_up_distance.rb +15 -0
- data/app/models/spree_cm_commissioner/order_decorator.rb +1 -1
- data/app/models/spree_cm_commissioner/place.rb +7 -0
- data/app/models/spree_cm_commissioner/pricing_action.rb +27 -0
- data/app/models/spree_cm_commissioner/pricing_model.rb +18 -0
- data/app/models/spree_cm_commissioner/pricing_model_variant.rb +6 -0
- data/app/models/spree_cm_commissioner/pricing_rule.rb +15 -0
- data/app/models/spree_cm_commissioner/pricing_rule_group.rb +20 -0
- data/app/models/spree_cm_commissioner/pricing_rules/extra_drop_off_distance.rb +10 -0
- data/app/models/spree_cm_commissioner/pricing_rules/extra_pick_up_distance.rb +12 -0
- data/app/models/spree_cm_commissioner/pricing_rules/nationality.rb +35 -0
- data/app/models/spree_cm_commissioner/tenant.rb +4 -0
- data/app/models/spree_cm_commissioner/variant_decorator.rb +3 -0
- data/app/models/spree_cm_commissioner/vendor_decorator.rb +1 -0
- data/app/request_schemas/spree_cm_commissioner/intercity_taxi_draft_order_update_schema.rb +22 -3
- data/app/request_schemas/spree_cm_commissioner/route_places_request_schema.rb +12 -0
- data/app/serializers/spree/v2/storefront/place_serializer.rb +3 -2
- data/app/serializers/spree/v2/tenant/cart_serializer.rb +1 -0
- data/app/serializers/spree/v2/tenant/intercity_taxi_cart_serializer.rb +12 -0
- data/app/serializers/spree/v2/tenant/line_item_serializer.rb +1 -0
- data/app/serializers/spree/v2/tenant/trip_place_serializer.rb +8 -0
- data/app/serializers/spree/v2/tenant/trip_query_result_serializer.rb +8 -0
- data/app/serializers/spree/v2/tenant/trip_serializer.rb +8 -0
- data/app/serializers/spree_cm_commissioner/v2/storefront/intercity_taxi_line_item_serializer.rb +17 -18
- data/app/serializers/spree_cm_commissioner/v2/storefront/route_serializer.rb +12 -0
- data/app/services/spree_cm_commissioner/intercity_taxi_order/create.rb +11 -22
- data/app/services/spree_cm_commissioner/intercity_taxi_order/update.rb +32 -11
- data/app/services/spree_cm_commissioner/pricing_models/apply.rb +51 -0
- data/app/services/spree_cm_commissioner/pricing_rules/build_params.rb +53 -0
- data/app/services/spree_cm_commissioner/pricing_rules/build_template.rb +27 -0
- data/app/services/spree_cm_commissioner/pricing_rules/create.rb +10 -0
- data/app/services/spree_cm_commissioner/pricing_rules/update.rb +11 -0
- data/app/services/spree_cm_commissioner/vendor_places/base.rb +24 -0
- data/app/services/spree_cm_commissioner/vendor_places/bulk_create.rb +70 -0
- data/app/services/spree_cm_commissioner/vendor_places/create_with_google_map_data.rb +85 -0
- data/app/services/spree_cm_commissioner/vendor_places/update.rb +56 -0
- data/app/views/spree/order_mailer/confirm_email.html.erb +1 -1
- data/app/views/spree_cm_commissioner/order_mailer/_mailer_stylesheets.html.erb +14 -13
- data/app/views/spree_cm_commissioner/order_mailer/tenant/_greeting.html.erb +6 -4
- data/config/routes.rb +4 -10
- data/db/migrate/20250915075830_create_spree_cm_commissioner_pricing_models.rb +17 -0
- data/db/migrate/20250915080733_create_spree_cm_commissioner_pricing_model_variants.rb +14 -0
- data/db/migrate/20251003082144_create_spree_cm_commissioner_pricing_rule_groups.rb +16 -0
- data/db/migrate/20251003093408_create_spree_cm_commissioner_pricing_rule.rb +19 -0
- data/db/migrate/20251003093643_create_spree_cm_commissioner_pricing_action.rb +14 -0
- data/db/migrate/20251119093000_add_tenant_id_to_cm_vendor_places.rb +2 -1
- data/lib/spree_cm_commissioner/intercity_taxi/distance.rb +38 -0
- data/lib/spree_cm_commissioner/intercity_taxi/map_place.rb +31 -0
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_action_factory.rb +5 -0
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_model_factory.rb +8 -0
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_rule_factory.rb +17 -0
- data/lib/spree_cm_commissioner/test_helper/factories/pricing_rule_group_factory.rb +8 -0
- data/lib/spree_cm_commissioner/version.rb +1 -1
- data/lib/spree_cm_commissioner.rb +2 -0
- metadata +42 -2
|
@@ -27,11 +27,6 @@ module SpreeCmCommissioner
|
|
|
27
27
|
validates :boarding_trip_stop_id, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
|
28
28
|
validates :drop_off_trip_stop_id, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
|
29
29
|
|
|
30
|
-
validates :pickup_lat, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }, allow_nil: true
|
|
31
|
-
validates :pickup_lng, numericality: { greater_than_or_equal_to: -180, less_than_or_equal_to: 180 }, allow_nil: true
|
|
32
|
-
validates :drop_off_lat, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }, allow_nil: true
|
|
33
|
-
validates :drop_off_lng, numericality: { greater_than_or_equal_to: -180, less_than_or_equal_to: 180 }, allow_nil: true
|
|
34
|
-
|
|
35
30
|
validates :passenger_count, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
|
36
31
|
|
|
37
32
|
# Groups LineItems by trip fields. Some fields can be null,
|
|
@@ -61,121 +56,71 @@ module SpreeCmCommissioner
|
|
|
61
56
|
def boarding_trip_stop_id = private_metadata['boarding_trip_stop_id']&.to_i
|
|
62
57
|
def drop_off_trip_stop_id = private_metadata['drop_off_trip_stop_id']&.to_i
|
|
63
58
|
|
|
64
|
-
def pickup_place_name = public_metadata['pickup_place_name']
|
|
65
|
-
def drop_off_place_name = public_metadata['drop_off_place_name']
|
|
66
|
-
|
|
67
|
-
def pickup_lat = public_metadata['pickup_lat']&.to_f
|
|
68
|
-
def pickup_lng = public_metadata['pickup_lng']&.to_f
|
|
69
|
-
def drop_off_lat = public_metadata['drop_off_lat']&.to_f
|
|
70
|
-
def drop_off_lng = public_metadata['drop_off_lng']&.to_f
|
|
71
59
|
def passenger_count = public_metadata['passenger_count']&.to_i
|
|
72
|
-
def distance_km = public_metadata['distance_km']&.to_f
|
|
73
|
-
def ordered_points = public_metadata['ordered_points']
|
|
74
|
-
def base_km = public_metadata['base_km']&.to_f
|
|
75
|
-
def detour_pickup_km = public_metadata['detour_pickup_km']&.to_f
|
|
76
|
-
def detour_dropoff_km = public_metadata['detour_dropoff_km']&.to_f
|
|
77
|
-
def extra_pickup_km = public_metadata['extra_pickup_km']&.to_f
|
|
78
|
-
def extra_dropoff_km = public_metadata['extra_dropoff_km']&.to_f
|
|
79
|
-
def extra_pickup_charge_usd = public_metadata['extra_pickup_charge_usd']&.to_f
|
|
80
|
-
def extra_dropoff_charge_usd = public_metadata['extra_dropoff_charge_usd']&.to_f
|
|
81
|
-
def estimated_time_minutes = public_metadata['estimated_time_minutes']&.to_i
|
|
82
|
-
def pickup_oob_confirmed = private_metadata['pickup_oob_confirmed']
|
|
83
|
-
def drop_off_oob_confirmed = private_metadata['drop_off_oob_confirmed']
|
|
84
60
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
def pickup_map_place
|
|
62
|
+
pickup_hash = public_metadata&.dig('pickup_map_place')
|
|
63
|
+
return nil if pickup_hash.blank?
|
|
88
64
|
|
|
89
|
-
|
|
90
|
-
set_private_metadata_value('trip_id', value)
|
|
65
|
+
SpreeCmCommissioner::IntercityTaxi::MapPlace.from_hash(pickup_hash)
|
|
91
66
|
end
|
|
92
67
|
|
|
93
|
-
def
|
|
94
|
-
|
|
95
|
-
|
|
68
|
+
def dropoff_map_place
|
|
69
|
+
dropoff_hash = public_metadata&.dig('dropoff_map_place')
|
|
70
|
+
return nil if dropoff_hash.blank?
|
|
96
71
|
|
|
97
|
-
|
|
98
|
-
set_private_metadata_value('drop_off_trip_stop_id', value)
|
|
72
|
+
SpreeCmCommissioner::IntercityTaxi::MapPlace.from_hash(dropoff_hash)
|
|
99
73
|
end
|
|
100
74
|
|
|
101
|
-
def
|
|
102
|
-
|
|
75
|
+
def distance
|
|
76
|
+
distance_hash = public_metadata&.dig('distance')
|
|
77
|
+
return nil if distance_hash.blank?
|
|
78
|
+
|
|
79
|
+
SpreeCmCommissioner::IntercityTaxi::Distance.from_hash(distance_hash)
|
|
103
80
|
end
|
|
104
81
|
|
|
105
|
-
def
|
|
106
|
-
|
|
82
|
+
def pickup_map_place=(value)
|
|
83
|
+
set_public_metadata_object('pickup_map_place', value)
|
|
107
84
|
end
|
|
108
85
|
|
|
109
|
-
def
|
|
110
|
-
|
|
86
|
+
def dropoff_map_place=(value)
|
|
87
|
+
set_public_metadata_object('dropoff_map_place', value)
|
|
111
88
|
end
|
|
112
89
|
|
|
113
|
-
def
|
|
114
|
-
|
|
90
|
+
def distance=(value)
|
|
91
|
+
set_public_metadata_object('distance', value)
|
|
115
92
|
end
|
|
116
93
|
|
|
117
|
-
def
|
|
118
|
-
|
|
94
|
+
def direction=(value)
|
|
95
|
+
set_private_metadata_value('direction', value)
|
|
119
96
|
end
|
|
120
97
|
|
|
121
|
-
def
|
|
122
|
-
|
|
98
|
+
def trip_id=(value)
|
|
99
|
+
set_private_metadata_value('trip_id', value)
|
|
123
100
|
end
|
|
124
101
|
|
|
125
|
-
def
|
|
126
|
-
|
|
102
|
+
def boarding_trip_stop_id=(value)
|
|
103
|
+
set_private_metadata_value('boarding_trip_stop_id', value)
|
|
127
104
|
end
|
|
128
105
|
|
|
129
|
-
def
|
|
130
|
-
|
|
106
|
+
def drop_off_trip_stop_id=(value)
|
|
107
|
+
set_private_metadata_value('drop_off_trip_stop_id', value)
|
|
131
108
|
end
|
|
132
109
|
|
|
133
110
|
def passenger_count=(value)
|
|
134
111
|
set_public_metadata_value('passenger_count', value)
|
|
135
112
|
end
|
|
136
113
|
|
|
137
|
-
|
|
138
|
-
set_public_metadata_value('distance_km', value)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def ordered_points=(value)
|
|
142
|
-
set_public_metadata_value('ordered_points', value)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def base_km=(value)
|
|
146
|
-
set_public_metadata_value('base_km', value)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def detour_pickup_km=(value)
|
|
150
|
-
set_public_metadata_value('detour_pickup_km', value)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def detour_dropoff_km=(value)
|
|
154
|
-
set_public_metadata_value('detour_dropoff_km', value)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def extra_pickup_km=(value)
|
|
158
|
-
set_public_metadata_value('extra_pickup_km', value)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def extra_dropoff_km=(value)
|
|
162
|
-
set_public_metadata_value('extra_dropoff_km', value)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def extra_pickup_charge_usd=(value)
|
|
166
|
-
set_public_metadata_value('extra_pickup_charge_usd', value)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def extra_dropoff_charge_usd=(value)
|
|
170
|
-
set_public_metadata_value('extra_dropoff_charge_usd', value)
|
|
171
|
-
end
|
|
114
|
+
private
|
|
172
115
|
|
|
173
|
-
def
|
|
174
|
-
|
|
116
|
+
def set_public_metadata_object(key, value)
|
|
117
|
+
if value.nil?
|
|
118
|
+
public_metadata.delete(key)
|
|
119
|
+
else
|
|
120
|
+
public_metadata[key] = value.to_h.stringify_keys
|
|
121
|
+
end
|
|
175
122
|
end
|
|
176
123
|
|
|
177
|
-
private
|
|
178
|
-
|
|
179
124
|
def set_public_metadata_value(key, value)
|
|
180
125
|
if value.nil?
|
|
181
126
|
public_metadata.delete(key)
|
|
@@ -50,9 +50,9 @@ module SpreeCmCommissioner
|
|
|
50
50
|
private
|
|
51
51
|
|
|
52
52
|
def tenant_link_or_default(tenant, default_link)
|
|
53
|
-
return default_link unless tenant.respond_to?(:
|
|
53
|
+
return default_link unless tenant.respond_to?(:formatted_url)
|
|
54
54
|
|
|
55
|
-
site = tenant.
|
|
55
|
+
site = tenant.formatted_url.to_s.strip
|
|
56
56
|
site.presence || default_link
|
|
57
57
|
rescue StandardError
|
|
58
58
|
default_link
|
|
@@ -2,7 +2,7 @@ module SpreeCmCommissioner
|
|
|
2
2
|
module AdjustmentDecorator
|
|
3
3
|
def self.prepended(base)
|
|
4
4
|
base.belongs_to :payable, polymorphic: true, optional: true
|
|
5
|
-
|
|
5
|
+
base.scope :pricing_action, -> { where(source_type: 'SpreeCmCommissioner::PricingAction') }
|
|
6
6
|
base.whitelisted_ransackable_attributes |= %w[payable_id]
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Calculators
|
|
3
|
+
class ExtraDropOffDistance < ExtraPickUpDistance
|
|
4
|
+
preference :base_price, :decimal, default: 0
|
|
5
|
+
preference :amount, :decimal, default: 0
|
|
6
|
+
|
|
7
|
+
def compute(line_item)
|
|
8
|
+
distance_km = line_item.distance.extra_dropoff_km
|
|
9
|
+
return nil if distance_km.nil?
|
|
10
|
+
|
|
11
|
+
preferred_base_price + (distance_km * preferred_amount)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Calculators
|
|
3
|
+
class ExtraPickUpDistance < Spree::Calculator
|
|
4
|
+
preference :base_price, :decimal, default: 0
|
|
5
|
+
preference :amount, :decimal, default: 0
|
|
6
|
+
|
|
7
|
+
def compute(line_item)
|
|
8
|
+
distance_km = line_item.distance.extra_pickup_km
|
|
9
|
+
return nil if distance_km.nil?
|
|
10
|
+
|
|
11
|
+
preferred_base_price + (distance_km * preferred_amount)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -21,6 +21,13 @@ module SpreeCmCommissioner
|
|
|
21
21
|
has_many :taxon_places, class_name: 'SpreeCmCommissioner::TaxonPlace', dependent: :destroy
|
|
22
22
|
has_many :taxons, through: :taxon_places
|
|
23
23
|
|
|
24
|
+
has_many :routes_as_origin, class_name: 'SpreeCmCommissioner::Route', foreign_key: :origin_place_id
|
|
25
|
+
has_many :routes_as_destination, class_name: 'SpreeCmCommissioner::Route', foreign_key: :destination_place_id
|
|
26
|
+
|
|
27
|
+
# Scopes for route-based filtering
|
|
28
|
+
scope :with_routes_as_origin, -> { joins(:routes_as_origin).distinct }
|
|
29
|
+
scope :with_routes_as_destination, -> { joins(:routes_as_destination).distinct }
|
|
30
|
+
|
|
24
31
|
def self.ransackable_attributes(auth_object = nil)
|
|
25
32
|
super & %w[name code]
|
|
26
33
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class PricingAction < Base
|
|
3
|
+
belongs_to :pricing_rule_group, class_name: 'SpreeCmCommissioner::PricingRuleGroup'
|
|
4
|
+
|
|
5
|
+
has_one :calculator, as: :calculable, class_name: 'Spree::Calculator', dependent: :destroy
|
|
6
|
+
accepts_nested_attributes_for :calculator
|
|
7
|
+
|
|
8
|
+
def perform(line_item)
|
|
9
|
+
return if pricing_rule_group.pricing_rules.blank?
|
|
10
|
+
|
|
11
|
+
amount = calculator&.compute(line_item)
|
|
12
|
+
|
|
13
|
+
line_item.adjustments.create!(
|
|
14
|
+
amount: amount,
|
|
15
|
+
source: self,
|
|
16
|
+
adjustable: line_item,
|
|
17
|
+
order: line_item.order,
|
|
18
|
+
label: pricing_rule_group.pricing_model.name,
|
|
19
|
+
mandatory: true
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.available_calculator_types
|
|
24
|
+
SpreeCmCommissioner::Calculators.constants.map(&:to_s)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class PricingModel < Base
|
|
3
|
+
acts_as_list column: :position, scope: :vendor_id
|
|
4
|
+
|
|
5
|
+
belongs_to :vendor, class_name: 'Spree::Vendor'
|
|
6
|
+
|
|
7
|
+
has_many :pricing_model_variants, class_name: 'SpreeCmCommissioner::PricingModelVariant', dependent: :destroy
|
|
8
|
+
has_many :variants, through: :pricing_model_variants, class_name: 'Spree::Variant'
|
|
9
|
+
has_many :pricing_rule_groups, class_name: 'SpreeCmCommissioner::PricingRuleGroup', dependent: :destroy
|
|
10
|
+
has_many :pricing_rules, through: :pricing_rule_groups, class_name: 'SpreeCmCommissioner::PricingRule'
|
|
11
|
+
|
|
12
|
+
accepts_nested_attributes_for :pricing_rule_groups, allow_destroy: true
|
|
13
|
+
|
|
14
|
+
validates :name, presence: true, uniqueness: { scope: :vendor_id }
|
|
15
|
+
|
|
16
|
+
enum status: { draft: 0, active: 1, archived: 2 }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class PricingRule < Base
|
|
3
|
+
acts_as_list column: :position, scope: :pricing_rule_group_id
|
|
4
|
+
|
|
5
|
+
belongs_to :pricing_rule_group, class_name: 'SpreeCmCommissioner::PricingRuleGroup'
|
|
6
|
+
|
|
7
|
+
def eligible?(_line_item)
|
|
8
|
+
raise 'eligible? should be implemented in a sub-class of SpreeCmCommissioner::PricingRule'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.available_rule_types
|
|
12
|
+
SpreeCmCommissioner::PricingRules.constants.map(&:to_s)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class PricingRuleGroup < Base
|
|
3
|
+
MATCH_TYPES = %w[all any none].freeze
|
|
4
|
+
|
|
5
|
+
acts_as_list column: :position, scope: :pricing_model_id
|
|
6
|
+
store_accessor :private_metadata, :template_key
|
|
7
|
+
store_accessor :private_metadata, :match_type
|
|
8
|
+
|
|
9
|
+
belongs_to :pricing_model, class_name: 'SpreeCmCommissioner::PricingModel'
|
|
10
|
+
has_many :pricing_rules, class_name: 'SpreeCmCommissioner::PricingRule', dependent: :destroy
|
|
11
|
+
has_one :pricing_action, class_name: 'SpreeCmCommissioner::PricingAction', dependent: :destroy
|
|
12
|
+
|
|
13
|
+
accepts_nested_attributes_for :pricing_rules, allow_destroy: true
|
|
14
|
+
accepts_nested_attributes_for :pricing_action, allow_destroy: true
|
|
15
|
+
|
|
16
|
+
validates :name, presence: true
|
|
17
|
+
|
|
18
|
+
enum status: { draft: 0, active: 1, archived: 2 }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module PricingRules
|
|
3
|
+
class ExtraPickUpDistance < SpreeCmCommissioner::PricingRule
|
|
4
|
+
store_accessor :private_metadata, :min_distance
|
|
5
|
+
|
|
6
|
+
def eligible?(line_item)
|
|
7
|
+
distance_km = line_item.distance&.extra_pickup_km || 0
|
|
8
|
+
distance_km > min_distance.to_f
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module PricingRules
|
|
3
|
+
class Nationality < SpreeCmCommissioner::PricingRule
|
|
4
|
+
RULE_TYPES = %w[all any none].freeze
|
|
5
|
+
|
|
6
|
+
store_accessor :private_metadata, :rule_type, :nationalities
|
|
7
|
+
|
|
8
|
+
def eligible?(line_item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
9
|
+
return false if nationalities.blank? || line_item.guests.blank?
|
|
10
|
+
|
|
11
|
+
targets = Array.wrap(nationalities).map(&:downcase)
|
|
12
|
+
guest_nationalities = line_item.guests.map { |g| guest_nationality(g) }.compact
|
|
13
|
+
|
|
14
|
+
return false if guest_nationalities.empty?
|
|
15
|
+
|
|
16
|
+
case rule_type
|
|
17
|
+
when 'all'
|
|
18
|
+
guest_nationalities.all? { |n| targets.include?(n) }
|
|
19
|
+
when 'any'
|
|
20
|
+
guest_nationalities.any? { |n| targets.include?(n) }
|
|
21
|
+
when 'none'
|
|
22
|
+
guest_nationalities.none? { |n| targets.include?(n) }
|
|
23
|
+
else
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def guest_nationality(guest)
|
|
31
|
+
guest.nationality&.name.to_s.downcase
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -30,6 +30,9 @@ module SpreeCmCommissioner
|
|
|
30
30
|
|
|
31
31
|
base.has_many :inventory_items, class_name: 'SpreeCmCommissioner::InventoryItem'
|
|
32
32
|
|
|
33
|
+
base.has_many :pricing_model_variants, class_name: 'SpreeCmCommissioner::PricingModelVariant', dependent: :destroy
|
|
34
|
+
base.has_many :pricing_models, through: :pricing_model_variants, class_name: 'SpreeCmCommissioner::PricingModel'
|
|
35
|
+
|
|
33
36
|
base.scope :subscribable, -> { active.joins(:product).where(product: { subscribable: true, status: :active }) }
|
|
34
37
|
base.scope :with_permanent_stock, -> { where(product_type: base::PERMANENT_STOCK_PRODUCT_TYPES) }
|
|
35
38
|
base.scope :with_non_permanent_stock, -> { where.not(product_type: base::PERMANENT_STOCK_PRODUCT_TYPES) }
|
|
@@ -91,6 +91,7 @@ module SpreeCmCommissioner
|
|
|
91
91
|
base.has_many :trip_stops, through: :trips, class_name: 'SpreeCmCommissioner::TripStop'
|
|
92
92
|
base.has_many :boarding_trip_stops, through: :trips, class_name: 'SpreeCmCommissioner::TripStop', source: :boarding_trip_stops
|
|
93
93
|
base.has_many :drop_off_trip_stops, through: :trips, class_name: 'SpreeCmCommissioner::TripStop', source: :drop_off_trip_stops
|
|
94
|
+
base.has_many :pricing_models, class_name: 'SpreeCmCommissioner::PricingModel', foreign_key: :vendor_id, dependent: :destroy
|
|
94
95
|
|
|
95
96
|
base.validates :account_name, :account_number, presence: true, if: lambda {
|
|
96
97
|
payment_qrcode.present? && Spree::Store.default.code.include?('billing')
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
module SpreeCmCommissioner
|
|
2
2
|
class IntercityTaxiDraftOrderUpdateSchema < ApplicationRequestSchema
|
|
3
3
|
params do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
optional(:remark).filled(:string)
|
|
5
|
+
optional(:pickup_map_place_attributes).hash do
|
|
6
|
+
optional(:place_name).filled(:string)
|
|
7
|
+
optional(:lat).filled(:string)
|
|
8
|
+
optional(:lng).filled(:string)
|
|
9
|
+
optional(:oob_confirmed).filled(:bool)
|
|
10
|
+
end
|
|
11
|
+
optional(:dropoff_map_place_attributes).hash do
|
|
12
|
+
optional(:place_name).filled(:string)
|
|
13
|
+
optional(:lat).filled(:string)
|
|
14
|
+
optional(:lng).filled(:string)
|
|
15
|
+
optional(:oob_confirmed).filled(:bool)
|
|
16
|
+
end
|
|
17
|
+
optional(:distance_attributes).hash do
|
|
18
|
+
optional(:distance_km).filled(:float)
|
|
19
|
+
optional(:ordered_points).filled(:array)
|
|
20
|
+
optional(:estimated_time_minutes).filled(:integer)
|
|
21
|
+
optional(:base_km).filled(:float)
|
|
22
|
+
optional(:detour_pickup_km).filled(:float)
|
|
23
|
+
optional(:detour_dropoff_km).filled(:float)
|
|
24
|
+
optional(:extra_pickup_km).filled(:float)
|
|
25
|
+
optional(:extra_dropoff_km).filled(:float)
|
|
7
26
|
end
|
|
8
27
|
end
|
|
9
28
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class RoutePlacesRequestSchema < ApplicationRequestSchema
|
|
3
|
+
params do
|
|
4
|
+
required(:place_type).filled(:string)
|
|
5
|
+
required(:query).filled(:string)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
rule(:place_type) do
|
|
9
|
+
key.failure('Invalid place_type. Use origin or destination') unless %w[origin destination].include?(value)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -4,8 +4,9 @@ module Spree
|
|
|
4
4
|
class PlaceSerializer < BaseSerializer
|
|
5
5
|
set_type :place
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
has_many :
|
|
7
|
+
# Included by default, pass false to exclude
|
|
8
|
+
has_many :vendors, if: proc { |_, params| params.nil? || params[:include_vendors] != false }
|
|
9
|
+
has_many :nearby_places, serializer: :nearby_place, if: proc { |_, params| params.nil? || params[:include_nearby_places] != false }
|
|
9
10
|
|
|
10
11
|
attributes :reference, :name, :vicinity, :lat, :lon, :icon, :url, :rating,
|
|
11
12
|
:formatted_phone_number, :formatted_address, :address_components, :types
|
|
@@ -20,6 +20,7 @@ module Spree
|
|
|
20
20
|
has_many :promotions, object_method_name: :valid_promotions, id_method_name: :valid_promotion_ids,
|
|
21
21
|
serializer: Spree::V2::Storefront::PromotionSerializer
|
|
22
22
|
|
|
23
|
+
has_many :saved_guests, serializer: SpreeCmCommissioner::V2::Storefront::SavedGuestSerializer
|
|
23
24
|
has_many :variants, serializer: Spree::V2::Tenant::VariantSerializer
|
|
24
25
|
has_many :products, serializer: Spree::V2::Tenant::ProductSerializer
|
|
25
26
|
has_many :line_items, serializer: Spree::V2::Tenant::LineItemSerializer
|
|
@@ -20,6 +20,7 @@ module Spree
|
|
|
20
20
|
|
|
21
21
|
has_one :vendor, serializer: Spree::V2::Tenant::VendorSerializer
|
|
22
22
|
has_one :product, serializer: Spree::V2::Storefront::ProductSerializer
|
|
23
|
+
has_many :saved_guests, serializer: SpreeCmCommissioner::V2::Storefront::SavedGuestSerializer
|
|
23
24
|
|
|
24
25
|
belongs_to :variant, serializer: Spree::V2::Tenant::VariantSerializer
|
|
25
26
|
belongs_to :order, serializer: Spree::V2::Tenant::OrderSerializer
|
data/app/serializers/spree_cm_commissioner/v2/storefront/intercity_taxi_line_item_serializer.rb
CHANGED
|
@@ -2,29 +2,28 @@ module SpreeCmCommissioner
|
|
|
2
2
|
module V2
|
|
3
3
|
module Storefront
|
|
4
4
|
class IntercityTaxiLineItemSerializer < BaseSerializer
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:drop_off_lat,
|
|
10
|
-
:drop_off_lng,
|
|
11
|
-
:passenger_count,
|
|
12
|
-
:distance_km,
|
|
13
|
-
:ordered_points,
|
|
14
|
-
:base_km,
|
|
15
|
-
:detour_pickup_km,
|
|
16
|
-
:detour_dropoff_km,
|
|
17
|
-
:extra_pickup_km,
|
|
18
|
-
:extra_dropoff_km,
|
|
19
|
-
:extra_pickup_charge_usd,
|
|
20
|
-
:extra_dropoff_charge_usd,
|
|
21
|
-
:estimated_time_minutes,
|
|
5
|
+
# Nested-only API shape
|
|
6
|
+
attributes :pickup_map_place,
|
|
7
|
+
:dropoff_map_place,
|
|
8
|
+
:distance,
|
|
22
9
|
:from_date,
|
|
23
10
|
:to_date,
|
|
24
|
-
:
|
|
11
|
+
:remark,
|
|
25
12
|
:trip_id
|
|
26
13
|
|
|
27
14
|
cache_options store: nil
|
|
15
|
+
|
|
16
|
+
def pickup_map_place
|
|
17
|
+
object.pickup_map_place&.to_h
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def dropoff_map_place
|
|
21
|
+
object.dropoff_map_place&.to_h
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def distance
|
|
25
|
+
object.distance&.to_h
|
|
26
|
+
end
|
|
28
27
|
end
|
|
29
28
|
end
|
|
30
29
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module V2
|
|
3
|
+
module Storefront
|
|
4
|
+
class RouteSerializer < BaseSerializer
|
|
5
|
+
attributes :route_name
|
|
6
|
+
|
|
7
|
+
has_one :origin_place, serializer: ::Spree::V2::Storefront::PlaceSerializer
|
|
8
|
+
has_one :destination_place, serializer: ::Spree::V2::Storefront::PlaceSerializer
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|