Module: DeliveryChannel::CourierDriverHelper
- Included in:
- CallDriverWorker, OrderManager, DeliveryChannels::CreateOrderWorker, DeliveryChannels::MaintainOrderWorker, NotificationWorkers::TightTimeCallDriverWorker
- Defined in:
- app/my_lib/delivery_channel/courier_driver_helper.rb
Overview
typed: ignore
Instance Method Summary collapse
- #can_wait_for_driver(reservation, driving_duration) ⇒ Object
-
#valid_time_to_call_driver?(reservation) ⇒ Boolean
true end.
- #valid_to_call_driver?(reservation, courier = 'Lalamove') ⇒ Boolean
Instance Method Details
#can_wait_for_driver(reservation, driving_duration) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'app/my_lib/delivery_channel/courier_driver_helper.rb', line 92 def can_wait_for_driver(reservation, driving_duration) result = driving_duration <= courier_distance_duration_to_restaurant_time_limit unless result formula = 'driving_duration <= courier_distance_duration_to_restaurant_time_limit' BUSINESS_LOGGER.info('delivery: can we wait for driver? => can not', note: "#{formula}. driving_duration = #{driving_duration}. courier distance to restaurant time limit is #{courier_distance_duration_to_restaurant_time_limit}", reservation_id: reservation.id) end result end |
#valid_time_to_call_driver?(reservation) ⇒ Boolean
true end
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/my_lib/delivery_channel/courier_driver_helper.rb', line 57 def valid_time_to_call_driver?(reservation) restaurant = reservation.restaurant now = Time.now_in_tz(restaurant.time_zone) if reservation.is_order_now? if restaurant.order_now.call_driver_before_food_ready.blank? raise(InvalidDriver, 'The order is an order-now order, but call_driver_before_food_ready data is blank') end if now > reservation.reservation_time - restaurant.order_now.call_driver_before_food_ready.to_i.minutes + courier_distance_duration_to_restaurant_time_limit formula = "#{now} > #{reservation.reservation_time} - #{restaurant.order_now.call_driver_before_food_ready.to_i} minutes + courier distance to restaurant time limit #{courier_distance_duration_to_restaurant_time_limit}}" raise(InvalidDriver, "The order is an order-now, but the current time has passed the expected delivery time. formula #{formula}") end else if restaurant.minute_before_delivery_time.blank? raise(InvalidDriver, 'restaurant minute_before_delivery_time is blank') end if now > reservation.call_order_later_driver_at + courier_distance_duration_to_restaurant_time_limit raise(InvalidDriver, "now #{now} > #{reservation.call_order_later_driver_at} + #{courier_distance_duration_to_restaurant_time_limit}") end end true rescue InvalidDriver => e BUSINESS_LOGGER.info('delivery: time is valid to call driver?', reservation_id: reservation.id, note: "not valid, because #{e.}") false end |
#valid_to_call_driver?(reservation, courier = 'Lalamove') ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/my_lib/delivery_channel/courier_driver_helper.rb', line 3 def valid_to_call_driver?(reservation, courier = 'Lalamove') delivery_channel_class = "DeliveryChannel::#{courier}" raise(InvalidDriver, 'Skipped to reorder driver') if reservation.skip_reorder_driver restaurant = reservation.restaurant if reservation.is_past? || !reservation.service_type.delivery? || !(reservation.active? && reservation.ack?) || !restaurant.activate_auto_call_driver? || reservation.is_temporary? || reservation.address.blank? raise(InvalidDriver, 'reservation is past, or not delivery, or not active/ack, or restaurant does not activate to auto call the driver, reservation is temporary, or address is blank') end valid_channel_for_all_restaurants = if courier == 'Grab' grab_channel_for_all_restaurants? else lalamove_channel_for_all_restaurants? end if !valid_channel_for_all_restaurants && !restaurant.delivery_channels.map(&:lib_class).include?(delivery_channel_class) raise InvalidDriver, "restaurant does not support #{delivery_channel_class} delivery" end return true if reservation.driver.present? && reservation.driver.canceled? raise(InvalidDriver, 'we have called the driver for this reservation') if reservation.driver_called? true rescue InvalidDriver => e BUSINESS_LOGGER.info('delivery: check is it valid to call driver?', reservation_id: reservation.id, note: "not valid, because #{e.}") false end |