2018-05-30 11:36:48 +02:00
|
|
|
class DeletedDossier < ApplicationRecord
|
|
|
|
belongs_to :procedure
|
2019-02-13 16:13:37 +01:00
|
|
|
|
2020-03-31 14:33:54 +02:00
|
|
|
validates :dossier_id, uniqueness: true
|
|
|
|
|
2020-03-19 11:51:47 +01:00
|
|
|
enum reason: {
|
2020-03-26 09:08:52 +01:00
|
|
|
user_request: 'user_request',
|
|
|
|
manager_request: 'manager_request',
|
|
|
|
user_removed: 'user_removed',
|
|
|
|
procedure_removed: 'procedure_removed',
|
|
|
|
expired: 'expired'
|
2020-03-19 11:51:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def self.create_from_dossier(dossier, reason)
|
|
|
|
create!(
|
|
|
|
reason: reasons.fetch(reason),
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
procedure: dossier.procedure,
|
|
|
|
state: dossier.state,
|
|
|
|
deleted_at: Time.zone.now
|
|
|
|
)
|
2019-02-13 16:13:37 +01:00
|
|
|
end
|
2020-03-26 17:35:50 +01:00
|
|
|
|
|
|
|
def procedure_removed?
|
|
|
|
reason == self.class.reasons.fetch(:procedure_removed)
|
|
|
|
end
|
2018-05-30 11:36:48 +02:00
|
|
|
end
|