2021-06-21 14:58:49 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Prepaid-packs of hours for machines/spaces.
|
2021-06-21 17:39:48 +02:00
|
|
|
#
|
|
|
|
# A prepaid-pack is a set a hours that can be bought by a member. After having bought one, a member will be able to book, for free,
|
|
|
|
# as much hours as there is in the pack, until the validity has not expired.
|
|
|
|
#
|
|
|
|
# The number of hours in a pack is stored in minutes.
|
2021-06-21 14:58:49 +02:00
|
|
|
class PrepaidPack < ApplicationRecord
|
|
|
|
belongs_to :priceable, polymorphic: true
|
2023-02-24 17:26:55 +01:00
|
|
|
belongs_to :machine, foreign_key: 'priceable_id', inverse_of: :prepaid_packs
|
|
|
|
belongs_to :space, foreign_key: 'priceable_id', inverse_of: :prepaid_packs
|
2021-06-25 17:24:34 +02:00
|
|
|
|
2021-06-21 14:58:49 +02:00
|
|
|
belongs_to :group
|
|
|
|
|
2022-12-28 17:51:27 +01:00
|
|
|
has_many :statistic_profile_prepaid_packs, dependent: :destroy
|
|
|
|
|
|
|
|
has_many :cart_item_prepaid_packs, class_name: 'CartItem::PrepaidPack', dependent: :destroy
|
2021-06-21 14:58:49 +02:00
|
|
|
|
|
|
|
validates :amount, :group_id, :priceable_id, :priceable_type, :minutes, presence: true
|
|
|
|
|
2021-06-21 17:39:48 +02:00
|
|
|
def validity
|
2022-01-18 17:12:19 +01:00
|
|
|
return nil if validity_interval.nil?
|
|
|
|
|
|
|
|
validity_count&.send(validity_interval)
|
2021-06-21 14:58:49 +02:00
|
|
|
end
|
|
|
|
|
2021-06-21 17:39:48 +02:00
|
|
|
def destroyable?
|
|
|
|
statistic_profile_prepaid_packs.empty?
|
2021-06-21 14:58:49 +02:00
|
|
|
end
|
|
|
|
end
|