Use the state_not_brouillon Dossier scope

This commit is contained in:
gregoirenovel 2017-07-10 16:11:12 +02:00
parent 09d596eec1
commit f480f26bd4
7 changed files with 9 additions and 9 deletions

View file

@ -9,10 +9,10 @@ class API::StatistiquesController < ApplicationController
private private
def total_dossiers def total_dossiers
Dossier.where.not(state: :draft).size Dossier.state_not_brouillon.size
end end
def dossiers_mois def dossiers_mois
Dossier.where.not(state: :draft).where(created_at: (1.month.ago)..Time.now).size Dossier.state_not_brouillon.where(created_at: (1.month.ago)..Time.now).size
end end
end end

View file

@ -7,7 +7,7 @@ class API::V1::DossiersController < APIController
def index def index
procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure = current_administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) dossiers = procedure.dossiers.state_not_brouillon.paginate(page: params[:page])
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200 render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View file

@ -8,11 +8,11 @@ class AdminProceduresShowFacades
end end
def dossiers def dossiers
@procedure.dossiers.where.not(state: :draft) @procedure.dossiers.state_not_brouillon
end end
def dossiers_for_pie_highchart def dossiers_for_pie_highchart
dossiers.where.not(state: :draft, archived: true).group(:state).count dossiers.state_not_brouillon.where.not(archived: true).group(:state).count
.reduce({}) do |acc, (key, val)| .reduce({}) do |acc, (key, val)|
translated_key = DossierDecorator.case_state_fr(key) translated_key = DossierDecorator.case_state_fr(key)
acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val

View file

@ -8,7 +8,7 @@ class Gestionnaire < ActiveRecord::Base
has_many :assign_to, dependent: :destroy has_many :assign_to, dependent: :destroy
has_many :procedures, through: :assign_to has_many :procedures, through: :assign_to
has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures has_many :dossiers, -> { state_not_brouillon }, through: :procedures
has_many :followed_dossiers, through: :follows, source: :dossier has_many :followed_dossiers, through: :follows, source: :dossier
has_many :follows has_many :follows
has_many :preference_list_dossiers has_many :preference_list_dossiers

View file

@ -128,7 +128,7 @@ class Procedure < ActiveRecord::Base
end end
def total_dossier def total_dossier
self.dossiers.where.not(state: :draft).size self.dossiers.state_not_brouillon.size
end end
def generate_export def generate_export

View file

@ -47,7 +47,7 @@ class Search < ActiveRecord::Base
dossier_ids = @gestionnaire.dossiers dossier_ids = @gestionnaire.dossiers
.select(:id) .select(:id)
.where(archived: false) .where(archived: false)
.where.not(state: "draft") .state_not_brouillon
q = Search q = Search
.select("DISTINCT(searches.dossier_id)") .select("DISTINCT(searches.dossier_id)")

View file

@ -21,7 +21,7 @@
= admin.procedures.published.count = admin.procedures.published.count
%td %td
- total_dossier = 0 - total_dossier = 0
- admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.not(state: :draft).count end - admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.state_not_brouillon.count end
= total_dossier = total_dossier
= smart_listing.paginate = smart_listing.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links