Merge pull request #360 from sgmap/clean-dossier

[Fix #125] Clean dossier
This commit is contained in:
gregoirenovel 2017-06-01 14:43:21 +02:00 committed by GitHub
commit b3cec9d48b
7 changed files with 58 additions and 126 deletions

View file

@ -16,13 +16,13 @@ class Users::DossiersController < UsersController
@dossiers_filtered = case @liste
when 'brouillon'
@user_dossiers.brouillon.order_by_updated_at
@user_dossiers.state_brouillon.order_by_updated_at
when 'a_traiter'
@user_dossiers.en_construction.order_by_updated_at
@user_dossiers.state_en_construction.order_by_updated_at
when 'en_instruction'
@user_dossiers.en_instruction.order_by_updated_at
@user_dossiers.state_en_instruction.order_by_updated_at
when 'termine'
@user_dossiers.termine.order_by_updated_at
@user_dossiers.state_termine.order_by_updated_at
when 'invite'
current_user.invites
else

View file

@ -1,14 +1,25 @@
class Dossier < ActiveRecord::Base
enum state: {draft: 'draft',
enum state: {
draft: 'draft',
initiated: 'initiated',
replied: 'replied', #action utilisateur demandé
updated: 'updated', #etude par l'administration en cours
replied: 'replied', # action utilisateur demandé
updated: 'updated', # etude par l'administration en cours
received: 'received',
closed: 'closed',
refused: 'refused',
without_continuation: 'without_continuation'
}
BROUILLON = %w(draft)
NOUVEAUX = %w(initiated)
OUVERT = %w(updated replied)
WAITING_FOR_GESTIONNAIRE = %w(updated)
WAITING_FOR_USER = %w(replied)
EN_CONSTRUCTION = %w(initiated updated replied)
EN_INSTRUCTION = %w(received)
A_INSTRUIRE = %w(received)
TERMINE = %w(closed refused without_continuation)
has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy
has_one :individual, dependent: :destroy
@ -30,6 +41,31 @@ class Dossier < ActiveRecord::Base
belongs_to :procedure
belongs_to :user
scope :state_brouillon, -> { where(state: BROUILLON) }
scope :state_not_brouillon, -> { where.not(state: BROUILLON) }
scope :state_nouveaux, -> { where(state: NOUVEAUX) }
scope :state_ouvert, -> { where(state: OUVERT) }
scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) }
scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) }
scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) }
scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) }
scope :state_a_instruire, -> { where(state: A_INSTRUIRE) }
scope :state_termine, -> { where(state: TERMINE) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
scope :all_state, -> { not_archived.state_not_brouillon.order_by_updated_at(:asc) }
scope :nouveaux, -> { not_archived.state_nouveaux.order_by_updated_at(:asc) }
scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) }
scope :waiting_for_gestionnaire, -> { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(:asc) }
scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) }
scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) }
scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) }
scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) }
accepts_nested_attributes_for :individual
delegate :siren, to: :entreprise
@ -45,16 +81,6 @@ class Dossier < ActiveRecord::Base
validates :user, presence: true
BROUILLON = %w(draft)
NOUVEAUX = %w(initiated)
OUVERT = %w(updated replied)
WAITING_FOR_GESTIONNAIRE = %w(updated)
WAITING_FOR_USER = %w(replied)
EN_CONSTRUCTION = %w(initiated updated replied)
EN_INSTRUCTION = %w(received)
A_INSTRUIRE = %w(received)
TERMINE = %w(closed refused without_continuation)
def unreaded_notifications
@unreaded_notif ||= notifications.where(already_read: false)
end
@ -158,50 +184,10 @@ class Dossier < ActiveRecord::Base
state
end
def self.all_state order = 'ASC'
not_brouillon.not_archived.order_by_updated_at(order)
end
def brouillon?
BROUILLON.include?(state)
end
scope :brouillon, -> { where(state: BROUILLON) }
scope :not_brouillon, -> { where.not(state: BROUILLON) }
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
def self.nouveaux order = 'ASC'
not_archived.where(state: NOUVEAUX).order_by_updated_at(order)
end
def self.waiting_for_gestionnaire order = 'ASC'
not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order)
end
def self.waiting_for_user order = 'ASC'
not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order)
end
scope :en_construction, -> { where(state: EN_CONSTRUCTION) }
def self.ouvert order = 'ASC'
not_archived.where(state: OUVERT).order_by_updated_at(order)
end
def self.a_instruire order = 'ASC'
not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order)
end
scope :en_instruction, -> { where(state: EN_INSTRUCTION) }
scope :termine, -> { where(state: TERMINE) }
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }
scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") }
def cerfa_available?
procedure.cerfa_flag? && cerfa.size != 0
end

View file

@ -45,7 +45,7 @@ class DossiersListGestionnaireService
end
def termine
@termine ||= filter_dossiers.termine.not_archived
@termine ||= filter_dossiers.termine
end
def filter_dossiers

View file

@ -15,25 +15,25 @@
.procedure-list-element#brouillon{ class: ('active' if @liste == 'brouillon') }
Brouillons
.badge.progress-bar-default
= @user_dossiers.brouillon.count
= @user_dossiers.state_brouillon.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'a_traiter')}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.' }
.procedure-list-element#a_traiter{ class: ('active' if @liste == 'a_traiter') }
En construction
.badge.progress-bar-danger
= @user_dossiers.en_construction.count
= @user_dossiers.state_en_construction.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'en_instruction')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours d\'examen par l\'administration compétante.' }
.procedure-list-element#en_instruction{ class: ('active' if @liste == 'en_instruction') }
En instruction
.badge.progress-bar-default
= @user_dossiers.en_instruction.count
= @user_dossiers.state_en_instruction.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'termine')}", 'data-toggle' => :tooltip, title: 'Les dossiers cloturés qui peuvent être "Accepté", "Refusé" ou "Sans suite".' }
.procedure-list-element#termine{ class: ('active' if @liste == 'termine') }
Terminé
.badge.progress-bar-success
= @user_dossiers.termine.count
= @user_dossiers.state_termine.count
%a{ :href => "#{url_for users_dossiers_path(liste: 'invite')}" }
.procedure-list-element#invite{ class: ('active' if @liste == 'invite') }

View file

@ -5,7 +5,7 @@ class AutoArchiveProcedureWorker
procedures_to_archive = Procedure.not_archived.where("auto_archive_on <= ?", Date.today)
procedures_to_archive.each do |p|
p.dossiers.en_construction.update_all(state: :received)
p.dossiers.state_en_construction.update_all(state: :received)
end
procedures_to_archive.update_all(archived: true, auto_archive_on: nil)

View file

@ -409,59 +409,6 @@ describe Dossier do
end
end
end
describe 'gestionnaire backoffice methods' do
let(:admin) { create(:administrateur) }
let(:admin_2) { create(:administrateur) }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [admin]) }
let(:procedure_admin) { create(:procedure, administrateur: admin) }
let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) }
let!(:dossier) { create(:dossier, procedure: procedure_admin, state: 'draft') }
let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux
let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux
let!(:dossier4) { create(:dossier, procedure: procedure_admin, state: 'replied') } #en_attente
let!(:dossier5) { create(:dossier, procedure: procedure_admin, state: 'updated') } #a_traiter
let!(:dossier6) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire
let!(:dossier7) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire
let!(:dossier8) { create(:dossier, procedure: procedure_admin, state: 'closed') } #termine
let!(:dossier9) { create(:dossier, procedure: procedure_admin, state: 'refused') } #termine
let!(:dossier10) { create(:dossier, procedure: procedure_admin, state: 'without_continuation') } #termine
let!(:dossier11) { create(:dossier, procedure: procedure_admin_2, state: 'closed') } #termine
let!(:dossier12) { create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) } #a_traiter #archived
let!(:dossier13) { create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived
let!(:dossier14) { create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived
before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin
end
describe '#nouveaux' do
subject { gestionnaire.dossiers.nouveaux }
it { expect(subject.size).to eq(2) }
end
describe '#waiting_for_gestionnaire' do
subject { gestionnaire.dossiers.waiting_for_gestionnaire }
it { expect(subject.size).to eq(1) }
end
describe '#waiting_for_user' do
subject { gestionnaire.dossiers.waiting_for_user }
it { expect(subject.size).to eq(1) }
end
describe '#en_instruction' do
subject { gestionnaire.dossiers.en_instruction }
it { expect(subject.size).to eq(2) }
it { expect(subject).to include(dossier6, dossier7) }
end
end
end
describe '#cerfa_available?' do

View file

@ -43,7 +43,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'on tab en construction' do
let(:total_dossiers) { 3 }
let(:active_class) { '.active .text-danger' }
let(:dossiers_to_display) { user.dossiers.en_construction }
let(:dossiers_to_display) { user.dossiers.state_en_construction }
let(:liste) { 'a_traiter' }
it_behaves_like 'check_tab_content' do
@ -59,11 +59,10 @@ describe 'users/dossiers/index.html.haml', type: :view do
end
end
describe 'on tab etude en examen' do
let(:total_dossiers) { 1 }
let(:active_class) { '.active .text-default' }
let(:dossiers_to_display) { user.dossiers.en_instruction }
let(:dossiers_to_display) { user.dossiers.state_en_instruction }
let(:liste) { 'en_instruction' }
it_behaves_like 'check_tab_content' do
@ -74,7 +73,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
describe 'on tab etude termine' do
let(:total_dossiers) { 3 }
let(:active_class) { '.active .text-success' }
let(:dossiers_to_display) { user.dossiers.termine }
let(:dossiers_to_display) { user.dossiers.state_termine }
let(:liste) { 'termine' }
it_behaves_like 'check_tab_content' do