Class: DeliveryChannel

Inherits:
ApplicationRecord show all
Includes:
IdentityCache
Defined in:
app/models/delivery_channel.rb

Overview

typed: ignore

Schema Information

Table name: delivery_channels

id                            :bigint           not null, primary key
available_for_all_restaurants :boolean          default(FALSE), not null
delivery_note                 :text(16777215)
is_default                    :boolean          default(FALSE), not null
is_self_delivery              :boolean          default(FALSE), not null
lib_class                     :string(191)
name                          :string(191)
restaurant_fee_cents          :integer          default(0), not null
restaurant_fee_currency       :string(191)      default("THB")
transaction_fee_in_percent    :integer          not null
created_at                    :datetime         not null
updated_at                    :datetime         not null

Defined Under Namespace

Modules: CourierDriverHelper Classes: CourierBase, DistanceCalculator, Grab, Lalamove, ManualCourier, OrderManager, RestaurantDelivery

Constant Summary collapse

COURIER_PARTNERS =
%w[DeliveryChannel::Grab DeliveryChannel::Lalamove].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.except_courier_partnersObject



62
63
64
# File 'app/models/delivery_channel.rb', line 62

def except_courier_partners
  ::DeliveryChannel.where.not(lib_class: DeliveryChannel::COURIER_PARTNERS)
end

.lalamove_instanceObject



58
59
60
# File 'app/models/delivery_channel.rb', line 58

def lalamove_instance
  ::DeliveryChannel.fetch_by_lib_class('DeliveryChannel::Lalamove') || DeliveryChannel.new
end

Instance Method Details

#available_for?(restaurant) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'app/models/delivery_channel.rb', line 49

def available_for?(restaurant)
  if available_for_all_restaurants?
    true
  else
    restaurants.include?(restaurant)
  end
end

#courierObject



44
45
46
# File 'app/models/delivery_channel.rb', line 44

def courier
  @courier ||= lib_class.constantize.new
end