2021-06-21 14:58:49 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Associate a customer with a bought prepaid-packs of hours for machines/spaces.
|
|
|
|
# Also saves the amount of hours used
|
2021-06-21 17:39:48 +02:00
|
|
|
class StatisticProfilePrepaidPack < ApplicationRecord
|
2021-06-21 14:58:49 +02:00
|
|
|
belongs_to :prepaid_pack
|
2021-06-21 17:39:48 +02:00
|
|
|
belongs_to :statistic_profile
|
2021-06-28 18:17:11 +02:00
|
|
|
|
|
|
|
has_many :invoice_items, as: :object, dependent: :destroy
|
|
|
|
has_one :payment_schedule_object, as: :object, dependent: :destroy
|
|
|
|
|
|
|
|
before_create :set_expiration_date
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_expiration_date
|
2022-01-18 17:12:19 +01:00
|
|
|
return unless prepaid_pack.validity
|
|
|
|
|
2021-06-28 18:17:11 +02:00
|
|
|
self.expires_at = DateTime.current + prepaid_pack.validity
|
|
|
|
end
|
2021-06-21 14:58:49 +02:00
|
|
|
end
|