Skip to content

Commit

Permalink
takes antenne filter if institution filter is present
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMLD committed May 30, 2024
1 parent e5166e6 commit 87d59b7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/models/match_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,25 @@ def raw_excluded_legal_forms=(legal_form_code)
updated_legal_form_code = legal_form_code.split(/[,\s]/).delete_if(&:empty?)
self.excluded_legal_forms = updated_legal_form_code
end

def same_antenne_match_filter?(match_filter_collection)
return false if filtrable_element_type != 'Institution'
match_filter_collection.any? do |mf|
mf != self &&
mf.filtrable_element_type == 'Antenne' &&
mf.filtrable_element.institution_id == filtrable_element.id &&
mf.has_same_fields_filled?(self)
end
end

def has_same_fields_filled?(other_match_filter)
fields_to_compare = %i[
accepted_naf_codes excluded_naf_codes accepted_legal_forms excluded_legal_forms
effectif_min effectif_max min_years_of_existence max_years_of_existence
]
subjects == other_match_filter.subjects &&
fields_to_compare.all? do |field|
self.send(field).present? == other_match_filter.send(field).present?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def apply_match_filters(expert_subjects)
expert_subjects.select do |es|
# On retire les filtres sur les sujets autres que celui du besoin
examined_match_filters = es.match_filters.reject{ |mf| other_subject_filter?(mf) }
# On retire les filtres aux institutions si on a le même filtre à une antenne
examined_match_filters = examined_match_filters.reject do |mf|
mf.same_antenne_match_filter?(examined_match_filters)
end
# On garde les experts_subjects
# - qui n'ont pas de filtres
# - ou bien où au moins un filtre passe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,35 @@
end
end
end

describe 'With institution and antenne filters take antenne filter' do
context 'min_years_of_existence' do
let(:diagnosis) { create :diagnosis, company: company }
let(:need) { create :need, diagnosis: diagnosis }
let!(:es_01) { create :expert_subject }
let(:institution) { create :institution }
let(:antenne) { create :antenne, institution: institution }
let(:match_filter_01) { create :match_filter, antenne: antenne, min_years_of_existence: 10 }
let(:match_filter_02) { create :match_filter, institution: institution, min_years_of_existence: 5 }

before do
es_01.expert.antenne.match_filters << match_filter_01
es_01.expert.institution.match_filters << match_filter_02
end

context 'young company' do
let(:company) { create :company, date_de_creation: 7.years.ago }

it { is_expected.to contain_exactly(es_temoin) }
end

context 'old company' do
let(:company) { create :company, date_de_creation: 11.years.ago }

it { is_expected.to contain_exactly(es_01, es_temoin) }
end
end
end
end

describe 'apply_institution_filters' do
Expand Down

0 comments on commit 87d59b7

Please sign in to comment.