1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/app/models/prepaid_pack.rb

30 lines
910 B
Ruby
Raw Normal View History

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
2021-06-25 17:24:34 +02:00
belongs_to :machine, foreign_type: 'Machine', foreign_key: 'priceable_id'
belongs_to :space, foreign_type: 'Space', foreign_key: 'priceable_id'
2021-06-21 14:58:49 +02:00
belongs_to :group
2021-06-21 17:39:48 +02:00
has_many :statistic_profile_prepaid_packs
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
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