Skip to content

Commit

Permalink
Ajout du champ 'start_year' dans 'exclusions'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Jan 27, 2025
1 parent b61db93 commit b02339f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
12 changes: 6 additions & 6 deletions app/models/exclusion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class Exclusion < ApplicationRecord
scope :outside_contract, -> { where.not(mef_code: nil) }

class << self
def outside_contract?(uai, mef_code)
exists?(uai: uai, mef_code: mef_code)
def outside_contract?(uai, mef_code, start_year)
exists?(uai:, mef_code:, start_year:)
end

def establishment_excluded?(uai)
whole_establishment.exists?(uai: uai)
def establishment_excluded?(uai, start_year)
whole_establishment.exists?(uai:, start_year:)
end

def excluded?(uai, mef_code)
establishment_excluded?(uai) || outside_contract?(uai, mef_code)
def excluded?(uai, mef_code, start_year = nil)
establishment_excluded?(uai, start_year) || outside_contract?(uai, mef_code, start_year)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/schooling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def max_end_date
end

def excluded?
Exclusion.excluded?(establishment.uai, mef.code)
Exclusion.excluded?(establishment.uai, mef.code, classe.school_year)
end

def removed?
Expand Down
2 changes: 1 addition & 1 deletion app/models/student/mappers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def map_classe!(entry)

return if label.nil? || mef.nil? || school_year.nil?

return if Exclusion.excluded?(uai, mef_code)
return if Exclusion.excluded?(uai, mef_code, school_year.start_year)

Classe.find_or_create_by!(
label:,
Expand Down
8 changes: 4 additions & 4 deletions db/exclusion_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class ExclusionSeeder
%w[0442083A 2473121131],
%w[0442083A 2473121332],
%w[0442083A 2473121333],
%w[0442227G 2403320511],
%w[0910838S 2473000433],
%w[0910838S 2473121432]
%w[0910838S 2473121432],
%w[0442227G 2403320511 2023]
].freeze

def self.seed
logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))

EXCLUSIONS.each do |uai, mef_code|
Exclusion.find_or_create_by!(uai: uai, mef_code: mef_code)
EXCLUSIONS.each do |uai, mef_code, start_year|
Exclusion.find_or_create_by!(uai:, mef_code:, start_year:)
end

logger.info { "[seeds] upserted #{Exclusion.count} exclusions" }
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20250127092313_add_school_year_to_exclusions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddSchoolYearToExclusions < ActiveRecord::Migration[8.0]
def change
add_column :exclusions, :start_year, :int, default: nil

remove_index :exclusions, %i[uai mef_code]
add_index :exclusions, %i[uai mef_code start_year], unique: true
end
end
5 changes: 3 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b02339f

Please sign in to comment.