refactor(traitement.process_expired): move process expired to procedure
This commit is contained in:
parent
f8a17b2cc4
commit
ce87878ff0
7 changed files with 70 additions and 56 deletions
|
@ -24,6 +24,7 @@
|
||||||
# last_commentaire_updated_at :datetime
|
# last_commentaire_updated_at :datetime
|
||||||
# motivation :text
|
# motivation :text
|
||||||
# private_search_terms :text
|
# private_search_terms :text
|
||||||
|
# process_expired :boolean default(FALSE)
|
||||||
# processed_at :datetime
|
# processed_at :datetime
|
||||||
# search_terms :text
|
# search_terms :text
|
||||||
# state :string
|
# state :string
|
||||||
|
@ -91,20 +92,17 @@ class Dossier < ApplicationRecord
|
||||||
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
|
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:en_construction),
|
build(state: Dossier.states.fetch(:en_construction),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
process_expired: false,
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
|
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:en_instruction),
|
build(state: Dossier.states.fetch(:en_instruction),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
process_expired: false,
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepter_automatiquement(processed_at: Time.zone.now)
|
def accepter_automatiquement(processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:accepte),
|
build(state: Dossier.states.fetch(:accepte),
|
||||||
process_expired: proxy_association.owner.procedure.feature_enabled?(:procedure_process_expired_dossiers_termine),
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,7 +110,6 @@ class Dossier < ApplicationRecord
|
||||||
build(state: Dossier.states.fetch(:accepte),
|
build(state: Dossier.states.fetch(:accepte),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation: motivation,
|
||||||
process_expired: proxy_association.owner.procedure.feature_enabled?(:procedure_process_expired_dossiers_termine),
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,7 +117,6 @@ class Dossier < ApplicationRecord
|
||||||
build(state: Dossier.states.fetch(:refuse),
|
build(state: Dossier.states.fetch(:refuse),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation: motivation,
|
||||||
process_expired: proxy_association.owner.procedure.feature_enabled?(:procedure_process_expired_dossiers_termine),
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,7 +124,6 @@ class Dossier < ApplicationRecord
|
||||||
build(state: Dossier.states.fetch(:sans_suite),
|
build(state: Dossier.states.fetch(:sans_suite),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation: motivation,
|
||||||
process_expired: proxy_association.owner.procedure.feature_enabled?(:procedure_process_expired_dossiers_termine),
|
|
||||||
processed_at: processed_at)
|
processed_at: processed_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -300,11 +295,10 @@ class Dossier < ApplicationRecord
|
||||||
scope :interval_en_construction_close_to_expiration, -> do
|
scope :interval_en_construction_close_to_expiration, -> do
|
||||||
state_en_construction.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
state_en_construction.where("dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||||
end
|
end
|
||||||
scope :interval_en_instruction_close_to_expiration, -> do
|
|
||||||
state_en_instruction.where("dossiers.en_instruction_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
|
||||||
end
|
|
||||||
scope :interval_termine_close_to_expiration, -> do
|
scope :interval_termine_close_to_expiration, -> do
|
||||||
state_termine.where(id: Traitement.termine_close_to_expiration.select(:dossier_id).distinct)
|
state_termine
|
||||||
|
.where(procedures: { procedure_expires_when_termine_enabled: true})
|
||||||
|
.where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||||
end
|
end
|
||||||
|
|
||||||
scope :brouillon_close_to_expiration, -> do
|
scope :brouillon_close_to_expiration, -> do
|
||||||
|
@ -313,9 +307,6 @@ class Dossier < ApplicationRecord
|
||||||
scope :en_construction_close_to_expiration, -> do
|
scope :en_construction_close_to_expiration, -> do
|
||||||
joins(:procedure).interval_en_construction_close_to_expiration
|
joins(:procedure).interval_en_construction_close_to_expiration
|
||||||
end
|
end
|
||||||
scope :en_instruction_close_to_expiration, -> do
|
|
||||||
joins(:procedure).interval_en_instruction_close_to_expiration
|
|
||||||
end
|
|
||||||
scope :termine_close_to_expiration, -> do
|
scope :termine_close_to_expiration, -> do
|
||||||
joins(:procedure).interval_termine_close_to_expiration
|
joins(:procedure).interval_termine_close_to_expiration
|
||||||
end
|
end
|
||||||
|
@ -324,7 +315,6 @@ class Dossier < ApplicationRecord
|
||||||
joins(:procedure).scoping do
|
joins(:procedure).scoping do
|
||||||
interval_brouillon_close_to_expiration
|
interval_brouillon_close_to_expiration
|
||||||
.or(interval_en_construction_close_to_expiration)
|
.or(interval_en_construction_close_to_expiration)
|
||||||
.or(interval_en_instruction_close_to_expiration)
|
|
||||||
.or(interval_termine_close_to_expiration)
|
.or(interval_termine_close_to_expiration)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -545,7 +535,11 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def expirable?
|
def expirable?
|
||||||
[brouillon?, en_construction?, termine? && procedure.feature_enabled?(:procedure_process_expired_dossiers_termine)].any?
|
[
|
||||||
|
brouillon?,
|
||||||
|
en_construction?,
|
||||||
|
termine? && procedure.procedure_expires_when_termine_enabled
|
||||||
|
].any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def approximative_expiration_date_reference
|
def approximative_expiration_date_reference
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
# monavis_embed :text
|
# monavis_embed :text
|
||||||
# organisation :string
|
# organisation :string
|
||||||
# path :string not null
|
# path :string not null
|
||||||
|
# procedure_expires_when_termine_enabled :boolean default(FALSE)
|
||||||
# published_at :datetime
|
# published_at :datetime
|
||||||
# routing_criteria_name :text default("Votre ville")
|
# routing_criteria_name :text default("Votre ville")
|
||||||
# routing_enabled :boolean
|
# routing_enabled :boolean
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
#
|
#
|
||||||
# Table name: traitements
|
# Table name: traitements
|
||||||
#
|
#
|
||||||
# id :bigint not null, primary key
|
# id :bigint not null, primary key
|
||||||
# instructeur_email :string
|
# instructeur_email :string
|
||||||
# motivation :string
|
# motivation :string
|
||||||
# process_expired :boolean
|
# process_expired :boolean
|
||||||
# processed_at :datetime
|
# process_expired_migrated :boolean default(FALSE)
|
||||||
# state :string
|
# processed_at :datetime
|
||||||
# dossier_id :bigint
|
# state :string
|
||||||
|
# dossier_id :bigint
|
||||||
#
|
#
|
||||||
class Traitement < ApplicationRecord
|
class Traitement < ApplicationRecord
|
||||||
belongs_to :dossier, optional: false
|
belongs_to :dossier, optional: false
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
class MoveProcessExpireToProcedures < ActiveRecord::Migration[6.1]
|
||||||
|
include Database::MigrationHelpers
|
||||||
|
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def up
|
||||||
|
add_column :procedures, :procedure_expires_when_termine_enabled, :boolean, default: false
|
||||||
|
add_column :traitements, :process_expired_migrated, :boolean, default: false
|
||||||
|
add_concurrent_index :procedures, :procedure_expires_when_termine_enabled
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_index :procedures, name: :index_procedures_on_process_expired
|
||||||
|
remove_column :traitements, :process_expired_migrated
|
||||||
|
remove_column :procedures, :procedure_expires_when_termine_enabled
|
||||||
|
end
|
||||||
|
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -320,12 +320,12 @@ ActiveRecord::Schema.define(version: 2021_11_27_143736) do
|
||||||
t.interval "conservation_extension", default: "PT0S"
|
t.interval "conservation_extension", default: "PT0S"
|
||||||
t.string "deleted_user_email_never_send"
|
t.string "deleted_user_email_never_send"
|
||||||
t.datetime "declarative_triggered_at"
|
t.datetime "declarative_triggered_at"
|
||||||
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
|
|
||||||
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
|
|
||||||
t.bigint "dossier_transfer_id"
|
t.bigint "dossier_transfer_id"
|
||||||
t.datetime "identity_updated_at"
|
t.datetime "identity_updated_at"
|
||||||
t.datetime "depose_at"
|
t.datetime "depose_at"
|
||||||
t.datetime "hidden_by_user_at"
|
t.datetime "hidden_by_user_at"
|
||||||
|
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
|
||||||
|
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
|
||||||
t.index ["archived"], name: "index_dossiers_on_archived"
|
t.index ["archived"], name: "index_dossiers_on_archived"
|
||||||
t.index ["dossier_transfer_id"], name: "index_dossiers_on_dossier_transfer_id"
|
t.index ["dossier_transfer_id"], name: "index_dossiers_on_dossier_transfer_id"
|
||||||
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
|
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
|
||||||
|
@ -646,15 +646,21 @@ ActiveRecord::Schema.define(version: 2021_11_27_143736) do
|
||||||
t.text "api_particulier_scopes", default: [], array: true
|
t.text "api_particulier_scopes", default: [], array: true
|
||||||
t.jsonb "api_particulier_sources", default: {}
|
t.jsonb "api_particulier_sources", default: {}
|
||||||
t.boolean "instructeurs_self_management_enabled"
|
t.boolean "instructeurs_self_management_enabled"
|
||||||
|
<<<<<<< HEAD
|
||||||
t.bigint "zone_id"
|
t.bigint "zone_id"
|
||||||
t.index ["api_particulier_sources"], name: "index_procedures_on_api_particulier_sources", using: :gin
|
t.index ["api_particulier_sources"], name: "index_procedures_on_api_particulier_sources", using: :gin
|
||||||
|
=======
|
||||||
|
>>>>>>> a6fcae97b (refactor(traitement.process_expired): move process expired to procedure)
|
||||||
t.boolean "routing_enabled"
|
t.boolean "routing_enabled"
|
||||||
|
t.boolean "procedure_expires_when_termine_enabled", default: false
|
||||||
|
t.index ["api_particulier_sources"], name: "index_procedures_on_api_particulier_sources", using: :gin
|
||||||
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
|
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
|
||||||
t.index ["draft_revision_id"], name: "index_procedures_on_draft_revision_id"
|
t.index ["draft_revision_id"], name: "index_procedures_on_draft_revision_id"
|
||||||
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
||||||
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
||||||
t.index ["path", "closed_at", "hidden_at", "unpublished_at"], name: "procedure_path_uniqueness", unique: true
|
t.index ["path", "closed_at", "hidden_at", "unpublished_at"], name: "procedure_path_uniqueness", unique: true
|
||||||
t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true
|
t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true
|
||||||
|
t.index ["procedure_expires_when_termine_enabled"], name: "index_procedures_on_procedure_expires_when_termine_enabled"
|
||||||
t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id"
|
t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id"
|
||||||
t.index ["service_id"], name: "index_procedures_on_service_id"
|
t.index ["service_id"], name: "index_procedures_on_service_id"
|
||||||
t.index ["zone_id"], name: "index_procedures_on_zone_id"
|
t.index ["zone_id"], name: "index_procedures_on_zone_id"
|
||||||
|
@ -745,6 +751,7 @@ ActiveRecord::Schema.define(version: 2021_11_27_143736) do
|
||||||
t.datetime "processed_at"
|
t.datetime "processed_at"
|
||||||
t.string "instructeur_email"
|
t.string "instructeur_email"
|
||||||
t.boolean "process_expired"
|
t.boolean "process_expired"
|
||||||
|
t.boolean "process_expired_migrated", default: false
|
||||||
t.index ["dossier_id"], name: "index_traitements_on_dossier_id"
|
t.index ["dossier_id"], name: "index_traitements_on_dossier_id"
|
||||||
t.index ["process_expired"], name: "index_traitements_on_process_expired"
|
t.index ["process_expired"], name: "index_traitements_on_process_expired"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: move_traitement_process_expired_to_procedure'
|
||||||
|
|
||||||
|
task move_traitement_process_expired_to_procedure: :environment do
|
||||||
|
procedures = Procedure.joins(dossiers: :traitements).where(dossiers: {traitements: {process_expired: true, process_expired_migrated: false}})
|
||||||
|
progress = ProgressReport.new(procedures.count)
|
||||||
|
|
||||||
|
procedures.group(:id).find_each do |procedure|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
puts "update traitements from dossier_ids: #{procedure.dossiers.ids}"
|
||||||
|
Traitement.where(id: procedure.dossiers.ids).update_all(process_expired_migrated: true)
|
||||||
|
Procedure.update(procedure_expires_when_termine_enabled: true)
|
||||||
|
progress.inc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
progress.finish
|
||||||
|
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -109,39 +109,12 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'en_instruction_close_to_expiration' do
|
|
||||||
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6) }
|
|
||||||
let!(:young_dossier) { create(:dossier, procedure: procedure) }
|
|
||||||
let!(:expiring_dossier) { create(:dossier, :en_instruction, en_instruction_at: 175.days.ago, procedure: procedure) }
|
|
||||||
let!(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: (6.months + 1.hour + 10.seconds).ago, procedure: procedure) }
|
|
||||||
let!(:long_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 1.year.ago, procedure: procedure) }
|
|
||||||
|
|
||||||
subject { Dossier.en_instruction_close_to_expiration }
|
|
||||||
|
|
||||||
it do
|
|
||||||
is_expected.not_to include(young_dossier)
|
|
||||||
is_expected.to include(expiring_dossier)
|
|
||||||
is_expected.to include(just_expired_dossier)
|
|
||||||
is_expected.to include(long_expired_dossier)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when .close_to_expiration' do
|
|
||||||
subject { Dossier.close_to_expiration }
|
|
||||||
it do
|
|
||||||
is_expected.not_to include(young_dossier)
|
|
||||||
is_expected.to include(expiring_dossier)
|
|
||||||
is_expected.to include(just_expired_dossier)
|
|
||||||
is_expected.to include(long_expired_dossier)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'termine_close_to_expiration' do
|
describe 'termine_close_to_expiration' do
|
||||||
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6) }
|
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6, procedure_expires_when_termine_enabled: true) }
|
||||||
let!(:young_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte)]) }
|
let!(:young_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 2.days.ago) }
|
||||||
let!(:expiring_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: 175.days.ago)]) }
|
let!(:expiring_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 175.days.ago) }
|
||||||
let!(:just_expired_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: (6.months + 1.hour + 10.seconds).ago)]) }
|
let!(:just_expired_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: (6.months + 1.hour + 10.seconds).ago) }
|
||||||
let!(:long_expired_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: 1.year.ago)]) }
|
let!(:long_expired_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 1.year.ago) }
|
||||||
|
|
||||||
subject { Dossier.termine_close_to_expiration }
|
subject { Dossier.termine_close_to_expiration }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue