2019-09-10 11:46:14 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Store customized price for various items (Machine, Space), depending on the group and on the plan
|
2020-03-25 10:16:47 +01:00
|
|
|
class Price < ApplicationRecord
|
2016-03-23 18:39:41 +01:00
|
|
|
belongs_to :group
|
|
|
|
belongs_to :plan
|
|
|
|
belongs_to :priceable, polymorphic: true
|
|
|
|
|
|
|
|
validates :priceable, :group_id, :amount, presence: true
|
2021-12-21 17:13:40 +01:00
|
|
|
validates :priceable_id, uniqueness: { scope: %i[priceable_type plan_id group_id duration] }
|
2021-12-28 11:25:10 +01:00
|
|
|
|
|
|
|
def safe_destroy
|
|
|
|
destroy unless duration == 60
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|