diff --git a/app/assets/stylesheets/utils.scss b/app/assets/stylesheets/utils.scss index 72c8b8e4e..f0cd725c9 100644 --- a/app/assets/stylesheets/utils.scss +++ b/app/assets/stylesheets/utils.scss @@ -50,7 +50,9 @@ color: $black; } - +.text-sm { + font-size: 14px; +} .mt-1 { margin-top: $default-spacer; diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 73a253752..67531416b 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -57,8 +57,8 @@ class StatsController < ApplicationController "procedures.libelle", "users.id", "dossiers.state", - "dossiers.en_construction_at - dossiers.created_at", - "dossiers.en_instruction_at - dossiers.en_construction_at", + "dossiers.depose_at - dossiers.created_at", + "dossiers.en_instruction_at - dossiers.depose_at", "dossiers.processed_at - dossiers.en_instruction_at" ) end @@ -121,7 +121,7 @@ class StatsController < ApplicationController end_date = monthly_report[:end_date].to_time.localtime replies_count = monthly_report[:replies_sent] - dossiers_count = Dossier.where(en_construction_at: start_date..end_date).count + dossiers_count = Dossier.where(depose_at: start_date..end_date).count monthly_contact_percentage = replies_count.fdiv(dossiers_count || 1) * 100 [I18n.l(start_date, format: '%b %y'), monthly_contact_percentage.round(1)] diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index b783a5945..1b599ab86 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -43,6 +43,7 @@ class API::V2::Schema < GraphQL::Schema Types::Champs::CarteChampType, Types::Champs::CheckboxChampType, Types::Champs::CiviliteChampType, + Types::Champs::CommuneChampType, Types::Champs::DateChampType, Types::Champs::DatetimeChampType, Types::Champs::DecimalNumberChampType, diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 24e02e2d3..3208c71fd 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -233,6 +233,30 @@ type CiviliteChamp implements Champ { value: Civilite } +type Commune { + """ + Le code INSEE + """ + code: String! + name: String! +} + +type CommuneChamp implements Champ { + commune: Commune + departement: Departement + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + La valeur du champ sous forme texte. + """ + stringValue: String +} + """ GeoJSON coordinates """ @@ -649,6 +673,11 @@ enum DemarcheState { publiee } +type Departement { + code: String! + name: String! +} + """ Represents direct upload credentials """ @@ -688,23 +717,28 @@ type Dossier { avis(id: ID): [Avis!]! champs(id: ID): [Champ!]! + """ + Date de dépôt. + """ + dateDepot: ISO8601DateTime! + """ Date de la dernière modification. """ dateDerniereModification: ISO8601DateTime! """ - Date de dépôt. + Date du dernier passage en construction. """ datePassageEnConstruction: ISO8601DateTime! """ - Date de passage en instruction. + Date du dernier passage en instruction. """ datePassageEnInstruction: ISO8601DateTime """ - Date de traitement. + Date du dernier traitement. """ dateTraitement: ISO8601DateTime demandeur: Demandeur! diff --git a/app/graphql/types/champ_type.rb b/app/graphql/types/champ_type.rb index 4cb5bf989..e9e8900c0 100644 --- a/app/graphql/types/champ_type.rb +++ b/app/graphql/types/champ_type.rb @@ -25,6 +25,12 @@ module Types else Types::Champs::DateChampType end + when ::Champs::CommuneChamp + if context.has_fragment?(:CommuneChamp) + Types::Champs::CommuneChampType + else + Types::Champs::TextChampType + end when ::Champs::DossierLinkChamp Types::Champs::DossierLinkChampType when ::Champs::PieceJustificativeChamp diff --git a/app/graphql/types/champs/commune_champ_type.rb b/app/graphql/types/champs/commune_champ_type.rb new file mode 100644 index 000000000..a26403f18 --- /dev/null +++ b/app/graphql/types/champs/commune_champ_type.rb @@ -0,0 +1,36 @@ +module Types::Champs + class CommuneChampType < Types::BaseObject + implements Types::ChampType + + class CommuneType < Types::BaseObject + field :name, String, null: false + field :code, String, "Le code INSEE", null: false + end + + class DepartementType < Types::BaseObject + field :name, String, null: false + field :code, String, null: false + end + + field :commune, CommuneType, null: true + field :departement, DepartementType, null: true + + def commune + if object.code? + { + name: object.to_s, + code: object.code + } + end + end + + def departement + if object.departement? + { + name: object.name_departement, + code: object.code_departement + } + end + end + end +end diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb index 16e08aff1..db83acae2 100644 --- a/app/graphql/types/dossier_type.rb +++ b/app/graphql/types/dossier_type.rb @@ -14,9 +14,10 @@ module Types field :demarche, Types::DemarcheDescriptorType, null: false, method: :procedure - field :date_passage_en_construction, GraphQL::Types::ISO8601DateTime, "Date de dépôt.", null: false, method: :en_construction_at - field :date_passage_en_instruction, GraphQL::Types::ISO8601DateTime, "Date de passage en instruction.", null: true, method: :en_instruction_at - field :date_traitement, GraphQL::Types::ISO8601DateTime, "Date de traitement.", null: true, method: :processed_at + field :date_depot, GraphQL::Types::ISO8601DateTime, "Date de dépôt.", null: false, method: :depose_at + field :date_passage_en_construction, GraphQL::Types::ISO8601DateTime, "Date du dernier passage en construction.", null: false, method: :en_construction_at + field :date_passage_en_instruction, GraphQL::Types::ISO8601DateTime, "Date du dernier passage en instruction.", null: true, method: :en_instruction_at + field :date_traitement, GraphQL::Types::ISO8601DateTime, "Date du dernier traitement.", null: true, method: :processed_at field :date_derniere_modification, GraphQL::Types::ISO8601DateTime, "Date de la dernière modification.", null: false, method: :updated_at field :archived, Boolean, null: false diff --git a/app/javascript/components/ComboCommunesSearch.jsx b/app/javascript/components/ComboCommunesSearch.jsx index 16a2815fe..c9dac0a21 100644 --- a/app/javascript/components/ComboCommunesSearch.jsx +++ b/app/javascript/components/ComboCommunesSearch.jsx @@ -93,10 +93,10 @@ function ComboCommunesSearch(params) { placeholder={placeholderDepartement} addForeignDepartement={false} required={params.mandatory} - onChange={(value, result) => { + onChange={(_, result) => { setDepartementCode(result?.code); if (hiddenDepartementField && hiddenCodeDepartementField) { - hiddenDepartementField.setAttribute('value', value); + hiddenDepartementField.setAttribute('value', result?.nom); hiddenCodeDepartementField.setAttribute('value', result?.code); } }} diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index 5f3ccdc05..526814c52 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -25,4 +25,25 @@ class Champs::CommuneChamp < Champs::TextChamp def for_export [value, external_id] end + + def name_departement + # FIXME we originaly saved already formatted departement with the code in the name + departement&.gsub(/^(.[0-9])\s-\s/, '') + end + + def departement_code_and_name + "#{code_departement} - #{name_departement}" + end + + def departement? + departement.present? + end + + def code? + code.present? + end + + def code + external_id + end end diff --git a/app/models/concerns/procedure_stats_concern.rb b/app/models/concerns/procedure_stats_concern.rb index 16a86e9f6..63960833c 100644 --- a/app/models/concerns/procedure_stats_concern.rb +++ b/app/models/concerns/procedure_stats_concern.rb @@ -67,14 +67,14 @@ module ProcedureStatsConcern def traitement_times(date_range) Traitement.for_traitement_time_stats(self) .where(processed_at: date_range) - .pluck('dossiers.en_construction_at', :processed_at) - .map { |en_construction_at, processed_at| { en_construction_at: en_construction_at, processed_at: processed_at } } + .pluck('dossiers.depose_at', :processed_at) + .map { |depose_at, processed_at| { depose_at: depose_at, processed_at: processed_at } } end def usual_traitement_time_by_month_in_days traitement_times(first_processed_at..last_considered_processed_at) .group_by { |t| t[:processed_at].beginning_of_month } - .transform_values { |month| month.map { |h| h[:processed_at] - h[:en_construction_at] } } + .transform_values { |month| month.map { |h| h[:processed_at] - h[:depose_at] } } .transform_values { |traitement_times_for_month| traitement_times_for_month.percentile(USUAL_TRAITEMENT_TIME_PERCENTILE).ceil } .transform_values { |seconds| seconds == 0 ? nil : seconds } .transform_values { |seconds| convert_seconds_in_days(seconds) } @@ -85,7 +85,7 @@ module ProcedureStatsConcern now = Time.zone.now traitement_time = traitement_times((now - nb_days.days)..now) - .map { |times| times[:processed_at] - times[:en_construction_at] } + .map { |times| times[:processed_at] - times[:depose_at] } .percentile(USUAL_TRAITEMENT_TIME_PERCENTILE) .ceil diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 57aae021c..a59add323 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -13,8 +13,8 @@ module TagsSubstitutionConcern }, { libelle: 'date de dépôt', - description: 'Date du passage en construction du dossier par l’usager', - lambda: -> (d) { format_date(d.en_construction_at) }, + description: 'Date de dépôt du dossier par l’usager', + lambda: -> (d) { format_date(d.depose_at) }, available_for_states: Dossier::SOUMIS }, { diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9dbf715e3..d687c4011 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -208,9 +208,9 @@ class Dossier < ApplicationRecord scope :not_hidden_by_user, -> { where(hidden_by_user_at: nil) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :order_by_created_at, -> (order = :asc) { order(en_construction_at: order, created_at: order, id: order) } + scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) } scope :updated_since, -> (since) { where('dossiers.updated_at >= ?', since) } - scope :created_since, -> (since) { where('dossiers.en_construction_at >= ?', since) } + scope :created_since, -> (since) { where('dossiers.depose_at >= ?', since) } scope :with_type_de_champ, -> (stable_id) { joins('INNER JOIN champs ON champs.dossier_id = dossiers.id INNER JOIN types_de_champ ON types_de_champ.id = champs.type_de_champ_id') @@ -249,7 +249,7 @@ class Dossier < ApplicationRecord ], avis: [:claimant, :expert], etablissement: :champ - ).order(en_construction_at: 'asc') + ).order(depose_at: 'asc') } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } @@ -459,11 +459,6 @@ class Dossier < ApplicationRecord traitement&.motivation || read_attribute(:motivation) end - def processed_at - return nil if !termine? - traitement&.processed_at || read_attribute(:processed_at) - end - def update_search_terms self.search_terms = [ user&.email, @@ -636,7 +631,7 @@ class Dossier < ApplicationRecord else parts = [ "Dossier déposé le ", - en_construction_at.strftime("%d/%m/%Y"), + depose_at.strftime("%d/%m/%Y"), " sur la démarche ", procedure.libelle, " gérée par l'organisme ", @@ -1040,7 +1035,7 @@ class Dossier < ApplicationRecord ['Archivé', :archived], ['État du dossier', Dossier.human_attribute_name("state.#{state}")], ['Dernière mise à jour le', :updated_at], - ['Déposé le', :en_construction_at], + ['Déposé le', :depose_at], ['Passé en instruction le', :en_instruction_at], ['Traité le', :processed_at], ['Motivation de la décision', :motivation], diff --git a/app/models/dossier_operation_log.rb b/app/models/dossier_operation_log.rb index 9ecd29d3b..316b54647 100644 --- a/app/models/dossier_operation_log.rb +++ b/app/models/dossier_operation_log.rb @@ -111,9 +111,9 @@ class DossierOperationLog < ApplicationRecord nil elsif operation == operations.fetch(:supprimer) { - date_de_depot: subject.en_construction_at, + date_de_depot: subject.depose_at, date_de_mise_en_instruction: subject.en_instruction_at, - date_de_decision: subject.termine? ? subject.traitements.last.processed_at : nil + date_de_decision: subject.processed_at }.as_json else case subject diff --git a/app/models/export.rb b/app/models/export.rb index f25117859..7c3990499 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -99,7 +99,7 @@ class Export < ApplicationRecord def io(since: nil) dossiers = Dossier.where(groupe_instructeur: groupe_instructeurs) if since.present? - dossiers = dossiers.where('dossiers.en_construction_at > ?', since) + dossiers = dossiers.where('dossiers.depose_at > ?', since) end service = ProcedureExportService.new(procedure, dossiers) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7d4397392..29a924ddf 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -105,7 +105,7 @@ class Procedure < ApplicationRecord if brouillon? TypeDeChamp.fillable .joins(:revision_types_de_champ) - .where(revision_types_de_champ: { revision: draft_revision }) + .where(revision_types_de_champ: { revision: draft_revision, parent_id: nil }) .order(:private, :position) else # fetch all type_de_champ.stable_id for all the revisions expect draft @@ -114,12 +114,14 @@ class Procedure < ApplicationRecord .joins(:revisions) .where(procedure_revisions: { procedure_id: id }) .where.not(procedure_revisions: { id: draft_revision_id }) + .where(revision_types_de_champ: { parent_id: nil }) .group(:stable_id) .select('MAX(types_de_champ.id)') # fetch the more recent procedure_revision_types_de_champ # which includes recents_ids recents_prtdc = ProcedureRevisionTypeDeChamp + .root .where(type_de_champ_id: recent_ids) .where.not(revision_id: draft_revision_id) .group(:type_de_champ_id) @@ -139,7 +141,10 @@ class Procedure < ApplicationRecord TypeDeChamp.root .public_only .fillable - .where(revision: revisions - [draft_revision]) + .joins(:revisions) + .where(procedure_revisions: { procedure_id: id }) + .where.not(procedure_revisions: { id: draft_revision_id }) + .where(revision_types_de_champ: { parent_id: nil }) .order(:created_at) .uniq end @@ -152,7 +157,10 @@ class Procedure < ApplicationRecord TypeDeChamp.root .private_only .fillable - .where(revision: revisions - [draft_revision]) + .joins(:revisions) + .where(procedure_revisions: { procedure_id: id }) + .where.not(procedure_revisions: { id: draft_revision_id }) + .where(revision_types_de_champ: { parent_id: nil }) .order(:created_at) .uniq end @@ -471,7 +479,9 @@ class Procedure < ApplicationRecord procedure.save procedure.draft_types_de_champ.update_all(revision_id: procedure.draft_revision.id) procedure.draft_types_de_champ_private.update_all(revision_id: procedure.draft_revision.id) - TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition + procedure.draft_types_de_champ_private.repetition).update_all(revision_id: procedure.draft_revision.id) + types_de_champ_in_repetition = TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition + procedure.draft_types_de_champ_private.repetition) + types_de_champ_in_repetition.update_all(revision_id: procedure.draft_revision.id) + types_de_champ_in_repetition.each(&:migrate_parent!) if is_different_admin || from_library procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) } diff --git a/app/models/procedure_overview.rb b/app/models/procedure_overview.rb index 057cce2c3..16076eda8 100644 --- a/app/models/procedure_overview.rb +++ b/app/models/procedure_overview.rb @@ -20,7 +20,7 @@ class ProcedureOverview @dossiers_en_construction_count = dossiers.state_en_construction.count @old_dossiers_en_construction = dossiers .state_en_construction - .where('en_construction_at < ?', 1.week.ago) + .where('depose_at < ?', 1.week.ago) @created_dossiers_count = dossiers .where(created_at: start_date..Time.zone.now) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index b5204ea2d..ef3ea6528 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -38,6 +38,7 @@ class ProcedurePresentation < ApplicationRecord fields = [ field_hash('Créé le', 'self', 'created_at'), field_hash('En construction le', 'self', 'en_construction_at'), + field_hash('Déposé le', 'self', 'depose_at'), field_hash('Mis à jour le', 'self', 'updated_at'), field_hash('Demandeur', 'user', 'email'), field_hash('Email instructeur', 'followers_instructeurs', 'email'), diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 25865fc96..fbef56bdb 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -14,8 +14,8 @@ class ProcedureRevision < ApplicationRecord has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id - has_many :revision_types_de_champ, -> { public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision - has_many :revision_types_de_champ_private, -> { private_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision + has_many :revision_types_de_champ, -> { root.public_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision + has_many :revision_types_de_champ_private, -> { root.private_only.ordered }, class_name: 'ProcedureRevisionTypeDeChamp', foreign_key: :revision_id, dependent: :destroy, inverse_of: :revision has_many :types_de_champ, through: :revision_types_de_champ, source: :type_de_champ has_many :types_de_champ_private, through: :revision_types_de_champ_private, source: :type_de_champ @@ -23,6 +23,8 @@ class ProcedureRevision < ApplicationRecord has_one :draft_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :draft_revision_id, dependent: :nullify, inverse_of: :draft_revision has_one :published_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :published_revision_id, dependent: :nullify, inverse_of: :published_revision + scope :ordered, -> { order(:created_at) } + def build_champs types_de_champ.map(&:build_champ) end @@ -39,7 +41,7 @@ class ProcedureRevision < ApplicationRecord .types_de_champ .tap do |types_de_champ| params[:order_place] = types_de_champ.present? ? types_de_champ.last.order_place + 1 : 0 - end.create(params) + end.create(params).migrate_parent! elsif params[:private] types_de_champ_private.create(params) else @@ -66,7 +68,9 @@ class ProcedureRevision < ApplicationRecord repetition_type_de_champ = find_or_clone_type_de_champ(id).parent move_type_de_champ_hash(repetition_type_de_champ.types_de_champ.to_a, type_de_champ, position).each do |(id, position)| - repetition_type_de_champ.types_de_champ.find(id).update!(order_place: position) + type_de_champ = repetition_type_de_champ.types_de_champ.find(id) + type_de_champ.update!(order_place: position) + type_de_champ.revision_type_de_champ&.update!(position: position) end elsif type_de_champ.private? move_type_de_champ_hash(types_de_champ_private.to_a, type_de_champ, position).each do |(id, position)| @@ -294,6 +298,7 @@ class ProcedureRevision < ApplicationRecord end cloned_type_de_champ.revision = self association.update!(type_de_champ: cloned_type_de_champ) + cloned_type_de_champ.types_de_champ.each(&:migrate_parent!) cloned_type_de_champ end diff --git a/app/models/procedure_revision_type_de_champ.rb b/app/models/procedure_revision_type_de_champ.rb index 6859d1884..ab26a544d 100644 --- a/app/models/procedure_revision_type_de_champ.rb +++ b/app/models/procedure_revision_type_de_champ.rb @@ -6,6 +6,7 @@ # position :integer not null # created_at :datetime not null # updated_at :datetime not null +# parent_id :bigint # revision_id :bigint not null # type_de_champ_id :bigint not null # @@ -13,7 +14,11 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord belongs_to :revision, class_name: 'ProcedureRevision' belongs_to :type_de_champ + belongs_to :parent, class_name: 'ProcedureRevisionTypeDeChamp', optional: true + has_many :revision_types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: :parent, dependent: :destroy + scope :root, -> { where(parent: nil) } scope :ordered, -> { order(:position) } + scope :revision_ordered, -> { order(:revision_id) } scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) } scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) } diff --git a/app/models/stat.rb b/app/models/stat.rb index dfc893caf..37e1c131e 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -31,11 +31,11 @@ class Stat < ApplicationRecord dossiers_not_brouillon: states['not_brouillon'], dossiers_termines: states['termines'], dossiers_cumulative: cumulative_hash([ - [Dossier.state_not_brouillon, :en_construction_at], + [Dossier.state_not_brouillon, :depose_at], [DeletedDossier.where.not(state: :brouillon), :deleted_at] ]), dossiers_in_the_last_4_months: last_four_months_hash([ - [Dossier.state_not_brouillon, :en_construction_at], + [Dossier.state_not_brouillon, :depose_at], [DeletedDossier.where.not(state: :brouillon), :deleted_at] ]), administrations_partenaires: AdministrateursProcedure.joins(:procedure).merge(Procedure.publiees_ou_closes).select('distinct administrateur_id').count @@ -48,8 +48,8 @@ class Stat < ApplicationRecord sanitize_and_exec(Dossier, <<-EOF SELECT COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon", - COUNT(*) FILTER ( WHERE state != 'brouillon' and en_construction_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours", - COUNT(*) FILTER ( WHERE state != 'brouillon' and en_construction_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours", + COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours", + COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours", COUNT(*) FILTER ( WHERE state = 'brouillon' ) AS "brouillon", COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction", COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction", diff --git a/app/models/traitement.rb b/app/models/traitement.rb index 86d7fd79b..a407842d6 100644 --- a/app/models/traitement.rb +++ b/app/models/traitement.rb @@ -22,7 +22,7 @@ class Traitement < ApplicationRecord includes(:dossier) .termine .where(dossier: procedure.dossiers) - .where.not('dossiers.en_construction_at' => nil, :processed_at => nil) + .where.not('dossiers.depose_at' => nil, processed_at: nil) .order(:processed_at) end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 46ee9f2b2..930fabff9 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -2,19 +2,20 @@ # # Table name: types_de_champ # -# id :integer not null, primary key -# description :text -# libelle :string -# mandatory :boolean default(FALSE) -# options :jsonb -# order_place :integer -# private :boolean default(FALSE), not null -# type_champ :string -# created_at :datetime -# updated_at :datetime -# parent_id :bigint -# revision_id :bigint -# stable_id :bigint +# id :integer not null, primary key +# description :text +# libelle :string +# mandatory :boolean default(FALSE) +# migrated_parent :boolean +# options :jsonb +# order_place :integer +# private :boolean default(FALSE), not null +# type_champ :string +# created_at :datetime +# updated_at :datetime +# parent_id :bigint +# revision_id :bigint +# stable_id :bigint # class TypeDeChamp < ApplicationRecord enum type_champs: { @@ -59,8 +60,9 @@ class TypeDeChamp < ApplicationRecord has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description, :drop_down_other - has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ - has_many :revisions, through: :revision_types_de_champ + has_many :revision_types_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ + has_one :revision_type_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: false + has_many :revisions, -> { ordered }, through: :revision_types_de_champ delegate :tags_for_template, :libelle_for_export, to: :dynamic_type @@ -373,6 +375,17 @@ class TypeDeChamp < ApplicationRecord end end + def migrate_parent! + if parent_id.present? && migrated_parent.nil? + ProcedureRevisionTypeDeChamp.create(parent: parent.revision_type_de_champ, + type_de_champ: self, + revision_id: parent.revision_type_de_champ.revision_id, + position: order_place) + update_column(:migrated_parent, true) + end + self + end + private def parse_drop_down_list_value(value) diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index 9fdebb9f0..a791a6eeb 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -87,7 +87,7 @@ class DossierSerializer < ActiveModel::Serializer end def initiated_at - object.en_construction_at&.in_time_zone('UTC') + object.depose_at&.in_time_zone('UTC') end def received_at diff --git a/app/serializers/dossiers_serializer.rb b/app/serializers/dossiers_serializer.rb index 784236b96..d94e1ba6e 100644 --- a/app/serializers/dossiers_serializer.rb +++ b/app/serializers/dossiers_serializer.rb @@ -11,7 +11,7 @@ class DossiersSerializer < ActiveModel::Serializer end def initiated_at - object.en_construction_at&.in_time_zone('UTC') + object.depose_at&.in_time_zone('UTC') end def state diff --git a/app/views/commencer/show.html.haml b/app/views/commencer/show.html.haml index 28d78643a..6f30fb5f3 100644 --- a/app/views/commencer/show.html.haml +++ b/app/views/commencer/show.html.haml @@ -30,7 +30,7 @@ - dossier = not_drafts.first %h2.huge-title= t('views.commencer.show.already_not_draft') %p - = t('views.commencer.show.already_not_draft_detail_html', time_ago: time_ago_in_words(dossier.en_construction_at), procedure: dossier.procedure.libelle) + = t('views.commencer.show.already_not_draft_detail_html', time_ago: time_ago_in_words(dossier.depose_at), procedure: dossier.procedure.libelle) = link_to t('views.commencer.show.show_my_submitted_file'), dossier_path(dossier), class: ['button large expand primary'] = link_to t('views.commencer.show.start_new_file'), url_for_new_dossier(@revision), class: ['button large expand'] diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index 087502214..b3b86eba6 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -193,8 +193,8 @@ def add_etat_dossier(pdf, dossier) end def add_etats_dossier(pdf, dossier) - if dossier.en_construction_at.present? - format_in_2_columns(pdf, "Déposé le", try_format_date(dossier.en_construction_at)) + if dossier.depose_at.present? + format_in_2_columns(pdf, "Déposé le", try_format_date(dossier.depose_at)) end if dossier.en_instruction_at.present? format_in_2_columns(pdf, "En instruction le", try_format_date(dossier.en_instruction_at)) diff --git a/app/views/shared/champs/communes/_show.html.haml b/app/views/shared/champs/communes/_show.html.haml index 4a901ea30..a162917b4 100644 --- a/app/views/shared/champs/communes/_show.html.haml +++ b/app/views/shared/champs/communes/_show.html.haml @@ -1,4 +1,9 @@ = format_text_value(champ.to_s) -- if champ.external_id.present? - Code INSEE : - = champ.external_id +- if champ.code? + %p.text-sm + Code INSEE : + = champ.code + - if champ.departement? + %br + Departement : + = champ.departement_code_and_name diff --git a/app/views/shared/dossiers/_demande.html.haml b/app/views/shared/dossiers/_demande.html.haml index 5fe7c7077..f63474584 100644 --- a/app/views/shared/dossiers/_demande.html.haml +++ b/app/views/shared/dossiers/_demande.html.haml @@ -1,5 +1,5 @@ .container - - if dossier.en_construction_at.present? + - if dossier.depose_at.present? .card = render partial: "shared/dossiers/infos_generales", locals: { dossier: dossier } diff --git a/app/views/shared/dossiers/_infos_generales.html.haml b/app/views/shared/dossiers/_infos_generales.html.haml index e4b139f72..b20eb3502 100644 --- a/app/views/shared/dossiers/_infos_generales.html.haml +++ b/app/views/shared/dossiers/_infos_generales.html.haml @@ -2,7 +2,7 @@ %tbody %tr %th.libelle Déposé le : - %td= l(dossier.en_construction_at, format: '%d %B %Y') + %td= l(dossier.depose_at, format: '%d %B %Y') - if dossier.justificatif_motivation.attached? %tr %th.libelle Justificatif : diff --git a/app/views/users/dossiers/_transfered_dossiers_list.html.haml b/app/views/users/dossiers/_transfered_dossiers_list.html.haml index 9e6503bf3..ebaf51b1e 100644 --- a/app/views/users/dossiers/_transfered_dossiers_list.html.haml +++ b/app/views/users/dossiers/_transfered_dossiers_list.html.haml @@ -19,7 +19,7 @@ = dossier.id %td= dossier.procedure.libelle %td= status_badge(dossier.state) - %td{ style: 'padding: 18px;' }= (dossier.en_construction_at || dossier.created_at).strftime('%d/%m/%Y') + %td{ style: 'padding: 18px;' }= (dossier.depose_at || dossier.created_at).strftime('%d/%m/%Y') .transfer-actions.mt-4 = link_to "Accepter", transfer_path(transfer), class: "button primary", method: :put diff --git a/app/views/users/dossiers/show/_header.html.haml b/app/views/users/dossiers/show/_header.html.haml index 1a4caf516..59a78453e 100644 --- a/app/views/users/dossiers/show/_header.html.haml +++ b/app/views/users/dossiers/show/_header.html.haml @@ -7,8 +7,8 @@ %h1= dossier.procedure.libelle %h2 = t('views.users.dossiers.show.header.dossier_number', dossier_id: dossier.id) - - if dossier.en_construction_at.present? - = t('views.users.dossiers.show.header.submit_date', date_du_dossier: I18n.l(dossier.en_construction_at)) + - if dossier.depose_at.present? + = t('views.users.dossiers.show.header.submit_date', date_du_dossier: I18n.l(dossier.depose_at)) = render(partial: 'users/dossiers/expiration_banner', locals: {dossier: dossier}) diff --git a/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb b/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb new file mode 100644 index 000000000..66851c8da --- /dev/null +++ b/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb @@ -0,0 +1,5 @@ +class AddParentIdToProcedureRevisionTypeDeChamp < ActiveRecord::Migration[6.1] + def change + add_belongs_to :procedure_revision_types_de_champ, :parent, index: true, foreign_key: { to_table: :procedure_revision_types_de_champ } + end +end diff --git a/db/migrate/20211124134220_add_migrated_parent_to_types_de_champ.rb b/db/migrate/20211124134220_add_migrated_parent_to_types_de_champ.rb new file mode 100644 index 000000000..3c2e2b50b --- /dev/null +++ b/db/migrate/20211124134220_add_migrated_parent_to_types_de_champ.rb @@ -0,0 +1,5 @@ +class AddMigratedParentToTypesDeChamp < ActiveRecord::Migration[6.1] + def change + add_column :types_de_champ, :migrated_parent, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ea7addb4..75c1a7327 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_12_01_135804) do +ActiveRecord::Schema.define(version: 2021_12_02_135804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -581,6 +581,8 @@ ActiveRecord::Schema.define(version: 2021_12_01_135804) do t.integer "position", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "parent_id" + t.index ["parent_id"], name: "index_procedure_revision_types_de_champ_on_parent_id" t.index ["revision_id"], name: "index_procedure_revision_types_de_champ_on_revision_id" t.index ["type_de_champ_id"], name: "index_procedure_revision_types_de_champ_on_type_de_champ_id" end @@ -766,6 +768,7 @@ ActiveRecord::Schema.define(version: 2021_12_01_135804) do t.bigint "stable_id" t.bigint "parent_id" t.bigint "revision_id" + t.boolean "migrated_parent" t.index ["parent_id"], name: "index_types_de_champ_on_parent_id" t.index ["private"], name: "index_types_de_champ_on_private" t.index ["revision_id"], name: "index_types_de_champ_on_revision_id" @@ -865,6 +868,7 @@ ActiveRecord::Schema.define(version: 2021_12_01_135804) do add_foreign_key "initiated_mails", "procedures" add_foreign_key "merge_logs", "users" add_foreign_key "procedure_presentations", "assign_tos" + add_foreign_key "procedure_revision_types_de_champ", "procedure_revision_types_de_champ", column: "parent_id" add_foreign_key "procedure_revision_types_de_champ", "procedure_revisions", column: "revision_id" add_foreign_key "procedure_revision_types_de_champ", "types_de_champ" add_foreign_key "procedure_revisions", "procedures" diff --git a/lib/tasks/deployment/20210630101910_migrate_type_de_champ_parent.rake b/lib/tasks/deployment/20210630101910_migrate_type_de_champ_parent.rake new file mode 100644 index 000000000..2433bda73 --- /dev/null +++ b/lib/tasks/deployment/20210630101910_migrate_type_de_champ_parent.rake @@ -0,0 +1,23 @@ +namespace :after_party do + desc 'Deployment task: migrate_type_de_champ_parent' + task migrate_type_de_champ_parent: :environment do + puts "Running deploy task 'migrate_type_de_champ_parent'" + + types_de_champ = TypeDeChamp + .where.not(parent_id: nil) + .where(migrated_parent: nil) + .includes(:revisions, parent: :revision_type_de_champ) + + progress = ProgressReport.new(types_de_champ.count) + types_de_champ.find_each do |type_de_champ| + type_de_champ.migrate_parent! + progress.inc + end + progress.finish + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index e88feeac8..79b8d0444 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -319,6 +319,7 @@ describe API::V2::GraphqlController do datePassageEnConstruction datePassageEnInstruction dateTraitement + dateDepot motivation motivationAttachment { url @@ -396,6 +397,7 @@ describe API::V2::GraphqlController do state: 'en_construction', dateDerniereModification: dossier.updated_at.iso8601, datePassageEnConstruction: dossier.en_construction_at.iso8601, + dateDepot: dossier.depose_at.iso8601, datePassageEnInstruction: nil, dateTraitement: nil, motivation: nil, diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 48ef7ced9..17c270ffa 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -108,6 +108,7 @@ FactoryBot.define do dossier.state = Dossier.states.fetch(:en_construction) dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.depose_at ||= dossier.en_construction_at dossier.save! end end @@ -117,6 +118,7 @@ FactoryBot.define do dossier.state = Dossier.states.fetch(:en_instruction) dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.depose_at ||= dossier.en_construction_at dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute dossier.save! end @@ -125,23 +127,22 @@ FactoryBot.define do trait :accepte do transient do motivation { nil } - processed_at { nil } end after(:create) do |dossier, evaluator| dossier.state = Dossier.states.fetch(:accepte) dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur - processed_at = evaluator.processed_at - if processed_at.present? - dossier.en_construction_at ||= processed_at - 2.minutes - dossier.en_instruction_at ||= processed_at - 1.minute - dossier.processed_at = processed_at - dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: processed_at) + if dossier.processed_at.present? + dossier.en_construction_at ||= dossier.processed_at - 2.minutes + dossier.depose_at ||= dossier.en_construction_at + dossier.en_instruction_at ||= dossier.processed_at - 1.minute + dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.processed_at) else dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.depose_at ||= dossier.en_construction_at dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute dossier.processed_at = dossier.en_instruction_at + 1.minute - dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.en_instruction_at + 1.minute) + dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.processed_at) end dossier.save! end @@ -152,6 +153,7 @@ FactoryBot.define do dossier.state = Dossier.states.fetch(:refuse) dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.depose_at ||= dossier.en_construction_at dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute dossier.traitements.refuser(processed_at: dossier.en_instruction_at + 1.minute) dossier.save! @@ -163,6 +165,7 @@ FactoryBot.define do dossier.state = Dossier.states.fetch(:sans_suite) dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.depose_at ||= dossier.en_construction_at dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute dossier.traitements.classer_sans_suite(processed_at: dossier.en_instruction_at + 1.minute) dossier.save! diff --git a/spec/models/concern/procedure_stats_concern_spec.rb b/spec/models/concern/procedure_stats_concern_spec.rb index 050989259..7384aa01f 100644 --- a/spec/models/concern/procedure_stats_concern_spec.rb +++ b/spec/models/concern/procedure_stats_concern_spec.rb @@ -89,6 +89,6 @@ describe ProcedureStatsConcern do private def create_dossier(construction_date:, instruction_date:, processed_date:) - dossier = create(:dossier, :accepte, procedure: procedure, en_construction_at: construction_date, en_instruction_at: instruction_date, processed_at: processed_date) + dossier = create(:dossier, :accepte, procedure: procedure, depose_at: construction_date, en_instruction_at: instruction_date, processed_at: processed_date) end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 674cddb04..96b924fc8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -356,15 +356,15 @@ describe Dossier do let(:service) { create(:service, nom: 'nom du service') } let(:procedure) { create(:procedure, libelle: "Démarche", organisation: "Organisme", service: service) } - context 'when the dossier has been en_construction' do - let(:dossier) { create :dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: "31/12/2010".to_date } + context 'when the dossier has been submitted' do + let(:dossier) { create :dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), depose_at: "31/12/2010".to_date } subject { dossier.text_summary } it { is_expected.to eq("Dossier déposé le 31/12/2010 sur la démarche Démarche gérée par l'organisme nom du service") } end - context 'when the dossier has not been en_construction' do + context 'when the dossier has not been submitted' do let(:dossier) { create :dossier, procedure: procedure, state: Dossier.states.fetch(:brouillon) } subject { dossier.text_summary } @@ -538,9 +538,9 @@ describe Dossier do describe '.downloadable_sorted' do let(:procedure) { create(:procedure) } let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:brouillon)) } - let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: Time.zone.parse('03/01/2010')) } - let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_construction_at: Time.zone.parse('01/01/2010')) } - let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, en_construction_at: Time.zone.parse('02/01/2010')) } + let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), depose_at: Time.zone.parse('03/01/2010')) } + let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), depose_at: Time.zone.parse('01/01/2010')) } + let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, depose_at: Time.zone.parse('02/01/2010')) } subject { procedure.dossiers.downloadable_sorted } diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 9dce6c912..cde42e401 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -60,6 +60,7 @@ describe ProcedurePresentation do [ { "label" => 'Créé le', "table" => 'self', "column" => 'created_at' }, { "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at' }, + { "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at' }, { "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at' }, { "label" => 'Demandeur', "table" => 'user', "column" => 'email' }, { "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email' }, diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 146c98926..c9414ceae 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -437,7 +437,7 @@ describe Procedure do end TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ.repetition)).each do |ptc, stc| - expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id"]) + expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id", "migrated_parent"]) expect(stc.revision).to eq(subject.draft_revision) end @@ -447,7 +447,7 @@ describe Procedure do end TypeDeChamp.where(parent: procedure.draft_types_de_champ_private.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ_private.repetition)).each do |ptc, stc| - expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id"]) + expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id", "migrated_parent"]) expect(stc.revision).to eq(subject.draft_revision) end diff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rb index b49693ec7..518cf04bf 100644 --- a/spec/models/stat_spec.rb +++ b/spec/models/stat_spec.rb @@ -54,11 +54,11 @@ describe Stat do describe '.cumulative_hash' do it 'works count and cumulate counters by month for both dossier and deleted dossiers' do 12.downto(1).map do |i| - create(:dossier, state: :en_construction, en_construction_at: i.months.ago) + create(:dossier, state: :en_construction, depose_at: i.months.ago) create(:deleted_dossier, dossier_id: i + 100, state: :en_construction, deleted_at: i.month.ago) end rs = Stat.send(:cumulative_hash, [ - [Dossier.state_not_brouillon, :en_construction_at], + [Dossier.state_not_brouillon, :depose_at], [DeletedDossier.where.not(state: :brouillon), :deleted_at] ]) expect(rs).to eq({ @@ -82,11 +82,11 @@ describe Stat do it 'works count and cumulate counters by month for both dossier and deleted dossiers' do travel_to Time.zone.local(2021, 11, 25) do 4.downto(1).map do |i| - create(:dossier, state: :en_construction, en_construction_at: i.months.ago) + create(:dossier, state: :en_construction, depose_at: i.months.ago) create(:deleted_dossier, dossier_id: i + 100, state: :en_construction, deleted_at: i.month.ago) end rs = Stat.send(:last_four_months_hash, [ - [Dossier.state_not_brouillon, :en_construction_at], + [Dossier.state_not_brouillon, :depose_at], [DeletedDossier.where.not(state: :brouillon), :deleted_at] ]) expect(rs).to eq([ diff --git a/spec/serializers/dossier_serializer_spec.rb b/spec/serializers/dossier_serializer_spec.rb index 0257e634e..eb7681891 100644 --- a/spec/serializers/dossier_serializer_spec.rb +++ b/spec/serializers/dossier_serializer_spec.rb @@ -5,7 +5,7 @@ describe DossierSerializer do context 'when the dossier is en_construction' do let(:dossier) { create(:dossier, :en_construction) } - it { is_expected.to include(initiated_at: dossier.en_construction_at) } + it { is_expected.to include(initiated_at: dossier.depose_at) } it { is_expected.to include(state: 'initiated') } end diff --git a/spec/serializers/dossiers_serializer_spec.rb b/spec/serializers/dossiers_serializer_spec.rb index 1fd01f41e..77cfa2b53 100644 --- a/spec/serializers/dossiers_serializer_spec.rb +++ b/spec/serializers/dossiers_serializer_spec.rb @@ -5,7 +5,7 @@ describe DossiersSerializer do context 'when the dossier is en_construction' do let(:dossier) { create(:dossier, :en_construction) } - it { is_expected.to include(initiated_at: dossier.en_construction_at) } + it { is_expected.to include(initiated_at: dossier.depose_at) } it { is_expected.to include(state: 'initiated') } end end diff --git a/spec/services/dossier_projection_service_spec.rb b/spec/services/dossier_projection_service_spec.rb index d08d8d396..ac81263b2 100644 --- a/spec/services/dossier_projection_service_spec.rb +++ b/spec/services/dossier_projection_service_spec.rb @@ -70,6 +70,13 @@ describe DossierProjectionService do it { is_expected.to eq('17/10/2018') } end + context 'for depose_at column' do + let(:column) { 'depose_at' } + let(:dossier) { create(:dossier, :en_construction, depose_at: Time.zone.local(2018, 10, 17)) } + + it { is_expected.to eq('17/10/2018') } + end + context 'for updated_at column' do let(:column) { 'updated_at' } let(:dossier) { create(:dossier) } diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 3938bf0a7..dc4507ab3 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -91,10 +91,10 @@ describe ProcedureExportService do expect(etablissements_sheet.data.size).to eq(1) # SimpleXlsxReader is transforming datetimes in utc... It is only used in test so we just hack around. - offset = dossier.en_construction_at.utc_offset - en_construction_at = Time.zone.at(dossiers_sheet.data[0][8] - offset.seconds) + offset = dossier.depose_at.utc_offset + depose_at = Time.zone.at(dossiers_sheet.data[0][8] - offset.seconds) en_instruction_at = Time.zone.at(dossiers_sheet.data[0][9] - offset.seconds) - expect(en_construction_at).to eq(dossier.en_construction_at.round) + expect(depose_at).to eq(dossier.depose_at.round) expect(en_instruction_at).to eq(dossier.en_instruction_at.round) end diff --git a/spec/system/users/dossier_details_spec.rb b/spec/system/users/dossier_details_spec.rb index 741626461..b2346120d 100644 --- a/spec/system/users/dossier_details_spec.rb +++ b/spec/system/users/dossier_details_spec.rb @@ -17,7 +17,7 @@ describe 'Dossier details:' do end describe "the user can see the mean time they are expected to wait" do - let(:other_dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) } + let(:other_dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, depose_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) } context "when the dossier is in construction" do it "displays the estimated wait duration" do diff --git a/spec/views/commencer/show.html.haml_spec.rb b/spec/views/commencer/show.html.haml_spec.rb index 40010ea92..f462eefb9 100644 --- a/spec/views/commencer/show.html.haml_spec.rb +++ b/spec/views/commencer/show.html.haml_spec.rb @@ -58,7 +58,7 @@ RSpec.describe 'commencer/show.html.haml', type: :view do it 'renders a link to the submitted dossier' do subject - expect(rendered).to have_text(time_ago_in_words(dossier.en_construction_at)) + expect(rendered).to have_text(time_ago_in_words(dossier.depose_at)) expect(rendered).to have_link('Voir mon dossier', href: dossier_path(dossier)) end end diff --git a/spec/views/users/dossiers/demande.html.haml_spec.rb b/spec/views/users/dossiers/demande.html.haml_spec.rb index 4b0859420..67aeb8459 100644 --- a/spec/views/users/dossiers/demande.html.haml_spec.rb +++ b/spec/views/users/dossiers/demande.html.haml_spec.rb @@ -28,7 +28,7 @@ describe 'users/dossiers/demande.html.haml', type: :view do it { is_expected.not_to have_link('Modifier le dossier') } end - context 'when the dossier has no en_construction_at date' do + context 'when the dossier has no depose_at date' do let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) } it { expect(rendered).not_to have_text('Déposé le') }