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
def total_dossiers
Dossier.where.not(state: :draft).size
Dossier.state_not_brouillon.size
end
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

View file

@ -7,7 +7,7 @@ class API::V1::DossiersController < APIController
def index
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
rescue ActiveRecord::RecordNotFound

View file

@ -8,11 +8,11 @@ class AdminProceduresShowFacades
end
def dossiers
@procedure.dossiers.where.not(state: :draft)
@procedure.dossiers.state_not_brouillon
end
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)|
translated_key = DossierDecorator.case_state_fr(key)
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 :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 :follows
has_many :preference_list_dossiers

View file

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

View file

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

View file

@ -21,7 +21,7 @@
= admin.procedures.published.count
%td
- 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
= smart_listing.paginate
= smart_listing.pagination_per_page_links