From b1031847795790e21db8d6aa47115ac17894b96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Mon, 10 Jan 2022 15:20:12 +0000 Subject: [PATCH] CDLC-504: Only changes the status after validation --- app/models/case_log.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index f28549902..2658adcb3 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -35,9 +35,10 @@ class CaseLog < ApplicationRecord default_scope -> { kept } validates_with CaseLogValidator - before_validation :update_status! + before_save :update_status! before_validation :process_postcode_changes!, if: :property_postcode_changed? before_validation :reset_location_fields!, unless: :postcode_known? + before_validation :set_derived_fields! belongs_to :owning_organisation, class_name: "Organisation" belongs_to :managing_organisation, class_name: "Organisation" @@ -203,10 +204,9 @@ private else "in_progress" end - set_derived_fields end - def set_derived_fields + def set_derived_fields! if previous_postcode.present? self.ppostc1 = UKPostcode.parse(previous_postcode).outcode self.ppostc2 = UKPostcode.parse(previous_postcode).incode