2018-04-17 16:11:49 +02:00
|
|
|
class Service < ApplicationRecord
|
|
|
|
has_many :procedures
|
2020-07-20 17:02:26 +02:00
|
|
|
belongs_to :administrateur, optional: false
|
2018-04-17 16:11:49 +02:00
|
|
|
|
2018-04-23 10:42:30 +02:00
|
|
|
scope :ordered, -> { order(nom: :asc) }
|
|
|
|
|
2018-04-17 16:11:49 +02:00
|
|
|
enum type_organisme: {
|
|
|
|
administration_centrale: 'administration_centrale',
|
|
|
|
association: 'association',
|
2019-02-18 16:18:09 +01:00
|
|
|
collectivite_territoriale: 'collectivite_territoriale',
|
2018-04-17 16:11:49 +02:00
|
|
|
etablissement_enseignement: 'etablissement_enseignement',
|
2019-02-18 16:18:09 +01:00
|
|
|
operateur_d_etat: "operateur_d_etat",
|
|
|
|
service_deconcentre_de_l_etat: 'service_deconcentre_de_l_etat',
|
2018-04-17 16:11:49 +02:00
|
|
|
autre: 'autre'
|
|
|
|
}
|
|
|
|
|
|
|
|
validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false
|
|
|
|
validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' }
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2022-07-25 18:17:30 +02:00
|
|
|
validates :siret, siret_format: true
|
2018-04-17 16:11:49 +02:00
|
|
|
validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2019-11-14 18:31:14 +01:00
|
|
|
validates :telephone, phone: { possible: true, allow_blank: true }
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :horaires, presence: { message: 'doivent être renseignés' }, allow_nil: false
|
|
|
|
validates :adresse, presence: { message: 'doit être renseignée' }, allow_nil: false
|
2018-04-17 16:11:49 +02:00
|
|
|
validates :administrateur, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2018-12-19 15:35:07 +01:00
|
|
|
|
2023-09-27 12:09:00 +02:00
|
|
|
def pretty_nom
|
|
|
|
"#{nom}, #{organisme}"
|
|
|
|
end
|
|
|
|
|
2018-12-19 15:35:07 +01:00
|
|
|
def clone_and_assign_to_administrateur(administrateur)
|
|
|
|
service_cloned = self.dup
|
|
|
|
service_cloned.administrateur = administrateur
|
|
|
|
service_cloned
|
|
|
|
end
|
2019-11-20 17:22:01 +01:00
|
|
|
|
|
|
|
def telephone_url
|
|
|
|
if telephone.present?
|
|
|
|
"tel:#{telephone.gsub(/[[:blank:]]/, '')}"
|
|
|
|
end
|
|
|
|
end
|
2022-07-25 17:37:02 +02:00
|
|
|
|
|
|
|
def etablissement_adresse
|
|
|
|
etablissement_infos.fetch("adresse", nil)
|
|
|
|
end
|
|
|
|
|
2022-07-25 18:06:53 +02:00
|
|
|
def etablissement_latlng
|
|
|
|
[etablissement_lat, etablissement_lng]
|
|
|
|
end
|
|
|
|
|
2022-07-25 17:37:02 +02:00
|
|
|
def enqueue_api_entreprise
|
|
|
|
APIEntreprise::ServiceJob.perform_later(self.id)
|
|
|
|
end
|
2018-04-17 16:11:49 +02:00
|
|
|
end
|