From 34bdcb62a4ca19af586d3b4fdbd7303d9514a640 Mon Sep 17 00:00:00 2001 From: pskl Date: Thu, 21 Nov 2024 15:58:44 +0100 Subject: [PATCH] Fix rib creation --- app/controllers/ribs_controller.rb | 2 +- app/models/student.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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..129f740e1 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