Browse Source

feat: tidy inference logic, update has_other_client_group on import in future

CLDC-1741-scheme-attributes-bug-fix
natdeanlewissoftwire 2 years ago
parent
commit
ec5e95c629
  1. 1
      app/controllers/schemes_controller.rb
  2. 7
      app/models/derived_variables/scheme_variables.rb
  3. 6
      app/models/scheme.rb
  4. 3
      app/services/imports/scheme_location_import_service.rb

1
app/controllers/schemes_controller.rb

@ -145,7 +145,6 @@ class SchemesController < ApplicationController
if confirm_secondary_page? page if confirm_secondary_page? page
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
else else
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
redirect_to scheme_check_answers_path(@scheme) redirect_to scheme_check_answers_path(@scheme)
end end
else else

7
app/models/derived_variables/scheme_variables.rb

@ -0,0 +1,7 @@
module DerivedVariables::SchemeVariables
def set_derived_fields!
if has_other_client_group == "No"
self.secondary_client_group = nil
end
end
end

6
app/models/scheme.rb

@ -1,4 +1,6 @@
class Scheme < ApplicationRecord class Scheme < ApplicationRecord
include DerivedVariables::SchemeVariables
belongs_to :owning_organisation, class_name: "Organisation" belongs_to :owning_organisation, class_name: "Organisation"
has_many :locations, dependent: :delete_all has_many :locations, dependent: :delete_all
has_many :lettings_logs, class_name: "LettingsLog", dependent: :delete_all has_many :lettings_logs, class_name: "LettingsLog", dependent: :delete_all
@ -23,6 +25,8 @@ class Scheme < ApplicationRecord
validate :validate_confirmed validate :validate_confirmed
validate :validate_owning_organisation validate :validate_owning_organisation
before_validation :set_derived_fields!
auto_strip_attributes :service_name auto_strip_attributes :service_name
SENSITIVE = { SENSITIVE = {
@ -188,7 +192,7 @@ class Scheme < ApplicationRecord
end end
def validate_confirmed def validate_confirmed
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group deactivation_date deactivation_date_type] required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units deactivation_date deactivation_date_type]
if confirmed == true if confirmed == true
required_attributes.any? do |attribute| required_attributes.any? do |attribute|

3
app/services/imports/scheme_location_import_service.rb

@ -33,6 +33,7 @@ module Imports
support_type: attributes["support_type"], support_type: attributes["support_type"],
intended_stay: attributes["intended_stay"], intended_stay: attributes["intended_stay"],
primary_client_group: attributes["primary_client_group"], primary_client_group: attributes["primary_client_group"],
has_other_client_group: attributes["has_other_client_group"],
secondary_client_group: attributes["secondary_client_group"], secondary_client_group: attributes["secondary_client_group"],
sensitive: attributes["sensitive"], sensitive: attributes["sensitive"],
# These values were set by the scheme import (management groups) # These values were set by the scheme import (management groups)
@ -56,6 +57,7 @@ module Imports
support_type: attributes["support_type"], support_type: attributes["support_type"],
intended_stay: attributes["intended_stay"], intended_stay: attributes["intended_stay"],
primary_client_group: attributes["primary_client_group"], primary_client_group: attributes["primary_client_group"],
has_other_client_group: attributes["has_other_client_group"],
secondary_client_group: attributes["secondary_client_group"], secondary_client_group: attributes["secondary_client_group"],
sensitive: attributes["sensitive"], sensitive: attributes["sensitive"],
} }
@ -83,6 +85,7 @@ module Imports
attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1") attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1")
attributes["secondary_client_group"] = string_or_nil(xml_doc, "client-group-2") attributes["secondary_client_group"] = string_or_nil(xml_doc, "client-group-2")
attributes["secondary_client_group"] = nil if attributes["primary_client_group"] == attributes["secondary_client_group"] attributes["secondary_client_group"] = nil if attributes["primary_client_group"] == attributes["secondary_client_group"]
attributes["has_other_client_group"] = attributes["secondary_client_group"].present? ? "Yes" : "No"
attributes["sensitive"] = sensitive(xml_doc) attributes["sensitive"] = sensitive(xml_doc)
attributes["start_date"] = parse_date(xml_doc, "start-date") attributes["start_date"] = parse_date(xml_doc, "start-date")
attributes["end_date"] = parse_date(xml_doc, "end-date") attributes["end_date"] = parse_date(xml_doc, "end-date")

Loading…
Cancel
Save