2015-08-10 11:05:06 +02:00
|
|
|
class Dossier < ActiveRecord::Base
|
|
|
|
has_one :etablissement
|
|
|
|
has_one :entreprise
|
2015-08-18 13:52:00 +02:00
|
|
|
has_one :cerfa
|
2015-08-13 15:55:19 +02:00
|
|
|
has_many :pieces_jointes
|
2015-08-14 14:05:09 +02:00
|
|
|
belongs_to :formulaire
|
2015-08-10 11:05:06 +02:00
|
|
|
has_many :commentaires
|
2015-08-12 10:09:52 +02:00
|
|
|
|
2015-08-13 15:55:19 +02:00
|
|
|
delegate :siren, to: :entreprise
|
|
|
|
delegate :siret, to: :etablissement
|
2015-08-14 15:02:11 +02:00
|
|
|
delegate :types_piece_jointe, to: :formulaire
|
2015-08-13 15:55:19 +02:00
|
|
|
|
2015-08-18 14:22:16 +02:00
|
|
|
before_create :build_default_cerfa
|
|
|
|
|
2015-08-24 15:23:07 +02:00
|
|
|
after_save :build_default_pieces_jointes, if: Proc.new { formulaire_id_changed? }
|
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
validates :mail_contact, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/ }, unless: 'mail_contact.nil?'
|
2015-08-25 10:19:39 +02:00
|
|
|
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
|
|
|
|
validates :description, presence: true, allow_blank: false, allow_nil: true
|
|
|
|
validates :montant_projet, presence: true, allow_blank: false, allow_nil: true
|
|
|
|
validates :montant_aide_demande, presence: true, allow_blank: false, allow_nil: true
|
|
|
|
validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? }
|
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
|
2015-08-20 16:45:20 +02:00
|
|
|
def retrieve_piece_jointe_by_type(type)
|
2015-08-20 15:15:20 +02:00
|
|
|
pieces_jointes.where(type_piece_jointe_id: type).last
|
2015-08-14 12:06:26 +02:00
|
|
|
end
|
2015-08-18 14:22:16 +02:00
|
|
|
|
2015-08-18 15:15:34 +02:00
|
|
|
def build_default_pieces_jointes
|
|
|
|
formulaire.types_piece_jointe.each do |type_piece_jointe|
|
|
|
|
PieceJointe.create(type_piece_jointe_id: type_piece_jointe.id, dossier_id: id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-18 14:22:16 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def build_default_cerfa
|
|
|
|
build_cerfa
|
|
|
|
true
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|