Class: TicketGroup

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Includes:
IdentityCache
Defined in:
app/models/ticket_group.rb

Constant Summary collapse

V_LABELS =
{
  hide: 'Hide In Store Page',
  show: 'Show In Store Page',
  vendor: 'Show for Vendors Only',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Attribute Details

#visibilityString

Returns we use this column to toggle visibility of ticket group in our restaurant store page. the valid value is `show` or `hide`.

Returns:

  • (String)

    we use this column to toggle visibility of ticket group in our restaurant store page. the valid value is `show` or `hide`



65
66
67
68
# File 'app/models/ticket_group.rb', line 65

translates :name,
:description,
touch: true,
fallbacks_for_empty_translations: true

Instance Method Details

#force_update_witness_quotaObject

allow admin to update ticket group quantity without checking availability



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/models/ticket_group.rb', line 143

def force_update_witness_quota
  total_orders = TicketBundle.joins(ticket_transaction: :charges).
    where(ticket_transactions: { for_locking_system: false, active: true },
          externals_omise_charges: {
            status: 'successful',
          }).where(ticket_group_id: id).sum(:quantity)
  self.total_orders = total_orders
  if save
    qw = InvQuotaWitness.new
    qw.update_restaurant_ticket_group_list(restaurants)
    qw.delete_keys(id)
    qw.generate_by_quota(id, quota, self)
  else
    APMErrorHandler.report("Failed to update total_orders for TicketGroup #{id}: #{errors.full_messages.join(', ')}")
  end
end

#is_full?Boolean

Parameters:

  • new_transaction_quantity (Integer)

    quantity of new transaction

Returns:

  • (Boolean)


161
162
163
# File 'app/models/ticket_group.rb', line 161

def is_full?
  total_orders.to_i >= quantity.to_i
end

#limit_user_should_be_unchecked_if_show_in_vendors_is_checkedObject



131
132
133
134
135
136
# File 'app/models/ticket_group.rb', line 131

def limit_user_should_be_unchecked_if_show_in_vendors_is_checked
  if visibility == 'vendor' && limit_user
    errors.add(:base,
               "Validation Error: Visibility is 'Show for Vendors Only' so you need to uncheck 'Limit User' option")
  end
end

#quotaObject



138
139
140
# File 'app/models/ticket_group.rb', line 138

def quota
  quantity.to_i - total_orders.to_i
end

#will_oversold?(new_transaction_quantity) ⇒ Boolean

Returns:

  • (Boolean)


165
166
167
# File 'app/models/ticket_group.rb', line 165

def will_oversold?(new_transaction_quantity)
  total_orders.to_i + new_transaction_quantity > quantity.to_i
end