Module: SubjModels::OrderModule

Constant Summary

Constants included from TypesSupport::PaymentTypes

TypesSupport::PaymentTypes::BANK_TRANSFER, TypesSupport::PaymentTypes::CARD, TypesSupport::PaymentTypes::CASH_IN_SUBJ_CENTER, TypesSupport::PaymentTypes::CASH_ON_COURIER_DELIVERY, TypesSupport::PaymentTypes::PAYMENT_TYPES

Constants included from TypesSupport::DeliveryTypes

TypesSupport::DeliveryTypes::DELIVERY_TYPES, TypesSupport::DeliveryTypes::NOVAYA_POCHTA_BY_COURIER, TypesSupport::DeliveryTypes::NOVAYA_POCHTA_FROM_STORAGE, TypesSupport::DeliveryTypes::PICKUP, TypesSupport::DeliveryTypes::PRIVAT_BANK_PICK_POINT, TypesSupport::DeliveryTypes::SUBJ_COURIER

Constants included from TypesSupport::OrderStatuses

TypesSupport::OrderStatuses::DELIVERED, TypesSupport::OrderStatuses::EN_ROUTE_EXTERNAL_COURIER, TypesSupport::OrderStatuses::EN_ROUTE_INTERNAL_COURIER, TypesSupport::OrderStatuses::ORDER_STATUSES, TypesSupport::OrderStatuses::PROCESSED, TypesSupport::OrderStatuses::RECEIVED

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValuesChecker

#check_string_for_int

Class Method Details

.included(including_class) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/subj_models/order.rb', line 14

def self.included(including_class)

  including_class.class_eval do

    before_create :generate_number

    include SubjModels::ComprisingExternalId

    enum order_status: ORDER_STATUSES
    enum delivery_type: DELIVERY_TYPES
    enum payment_type: PAYMENT_TYPES

    belongs_to :user
    belongs_to :user_delivery_address

    has_one :order_delivery_courier
    has_one :order_delivery_pickup
    has_one :order_delivery_privatbank
    has_one :order_delivery_subj_courier
    has_one :order_delivery_nova_poshta_warhouse
    has_many :order_items, dependent: :destroy
    has_many :event_bookings

    validates :order_status, inclusion: { in: order_statuses.keys }, on: :update
    validates :delivery_type, inclusion: { in: delivery_types.keys }, on: :update
    validates :payment_type, inclusion: { in: payment_types.keys }, on: :update
    validates :total_amount, :order_date, presence: true, on: :update

    scope :user_id, ->  user  { where(user_id: user) }

    scope :with_status, -> (status) do
      where(order_status: Order.order_statuses[status] || status)
    end

    scope :last_order, -> (user_id) do
      Order.joins(:user, :order_items)
      .where("users.id" => user_id)
      .where(order_items: {item_type: 1})
      .last
    end

    scope :has_items, -> { joins(:order_items).where.not(order_items: {order_id: nil}).uniq }

  end

end

Instance Method Details

#delivery_type=(value) ⇒ Object



81
82
83
# File 'lib/subj_models/order.rb', line 81

def delivery_type=(value)
  super(check_string_for_int(value))
end

#delivery_type_valueObject



65
66
67
# File 'lib/subj_models/order.rb', line 65

def delivery_type_value
  self[:delivery_type]
end

#order_status=(value) ⇒ Object



77
78
79
# File 'lib/subj_models/order.rb', line 77

def order_status=(value)
  super(check_string_for_int(value))
end

#order_status_valueObject



61
62
63
# File 'lib/subj_models/order.rb', line 61

def order_status_value
  self[:order_status]
end

#payment_type=(value) ⇒ Object



85
86
87
# File 'lib/subj_models/order.rb', line 85

def payment_type=(value)
  super(check_string_for_int(value))
end

#payment_type_valueObject



69
70
71
# File 'lib/subj_models/order.rb', line 69

def payment_type_value
  self[:payment_type]
end

#to_sObject



73
74
75
# File 'lib/subj_models/order.rb', line 73

def to_s
  id.to_s # TODO
end