Skip to content

Commit

Permalink
Fix rib creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Nov 21, 2024
1 parent 9357dcb commit 34bdcb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ribs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def rib_params
:bic,
:name,
:owner_type
).with_defaults(student: @student, establishment: current_establishment)
).with_defaults(student_id: @student.id, establishment_id: current_establishment.id)
end

def bulk_ribs_params
Expand Down
7 changes: 4 additions & 3 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class Student < ApplicationRecord # rubocop:disable Metrics/ClassLength
:birthplace_country_insee_code,
:biological_sex

def rib(etab = establishment)
ribs.find_by(establishment: etab || schoolings.last.establishment, archived_at: nil)
def rib(etab_id = establishment_id)
ribs.find_by(establishment_id: etab_id, archived_at: nil)
end

# NOTE: used in stats for column "Données d'élèves nécessaires présentes"
Expand Down Expand Up @@ -143,7 +143,8 @@ def born_in_france?
end

def create_new_rib(rib_params)
rib.archive! if rib.present? && rib.archivable?
current_rib = rib(rib_params.fetch("establishment_id"))
current_rib.archive! if current_rib.present? && current_rib.archivable?
ribs.create(rib_params)
end

Expand Down

0 comments on commit 34bdcb6

Please sign in to comment.