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

27 lines
677 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.
# A prepaid-pack is a set a hours that can be bought by a member. The member will be able to book for free as much hours
# as there's in the pack, after having bought one.
# The number of hours in each packs is saved in minutes
class PrepaidPack < ApplicationRecord
belongs_to :priceable, polymorphic: true
belongs_to :group
has_many :user_prepaid_packs
validates :amount, :group_id, :priceable_id, :priceable_type, :minutes, presence: true
def hours
minutes / 60.0
end
def safe_destroy
if user_prepaid_packs.count.zero?
destroy
else
false
end
end
end