diff --git a/app/controllers/ribs_controller.rb b/app/controllers/ribs_controller.rb index ab4659371..96234dd97 100644 --- a/app/controllers/ribs_controller.rb +++ b/app/controllers/ribs_controller.rb @@ -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 diff --git a/app/models/student.rb b/app/models/student.rb index 62bf48f32..cead42443 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -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" @@ -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