Class: Externals::Lalamove::Order

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/externals/lalamove/order.rb

Overview

typed: ignore

Schema Information

Table name: externals_lalamove_orders

id             :bigint           not null, primary key
order_ref      :string(191)
price_cents    :integer          default(0), not null
price_currency :string(191)      default("THB")
status         :string(191)
created_at     :datetime         not null
updated_at     :datetime         not null

Indexes

unique_lalamove_order_ref  (order_ref) UNIQUE

Constant Summary collapse

COMPLETED =
'COMPLETED'

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/externals/lalamove/order.rb', line 29

def complete?
  [Driver::DELIVERED.to_s, Driver::LALAMOVE_DELIVERED, COMPLETED].include?(status_as_constant)
end

#status_as_constantObject

Returns String.

Returns:

  • String



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/externals/lalamove/order.rb', line 34

def status_as_constant
  case status
  when Driver::LALAMOVE_FINDING_DRIVER
    'Driver::FINDING_DRIVER'
  when Driver::LALAMOVE_PICKED_UP, 'PICKED_UP'
    'Driver::PICKED_UP'
  when Driver::LALAMOVE_CANCELLED
    'Driver::CANCELLED'
  when Driver::LALAMOVE_ON_THE_WAY_TO_RESTAURANT, 'ON_GOING'
    'Driver::ON_THE_WAY_TO_RESTAURANT'
  when Driver::LALAMOVE_REJECTED
    'Driver::REJECTED'
  when Driver::LALAMOVE_DELIVERED, COMPLETED
    'Driver::DELIVERED'
  when Driver::LALAMOVE_EXPIRED
    'Driver::EXPIRED'
  else
    APMErrorHandler.report('unknown status', order: attributes.to_h, status: status)
    'Driver::FINDING_DRIVER'
  end
end