Browse Source

feat: only confirm locations if complete (old) AND save button clicked (new)

pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
c0f9088251
  1. 9
      app/controllers/locations_controller.rb
  2. 5
      app/models/location.rb

9
app/controllers/locations_controller.rb

@ -134,10 +134,19 @@ class LocationsController < ApplicationController
def check_answers; end
def confirm
confirm_location
if @location.confirmed
flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
end
redirect_to scheme_locations_path(@scheme)
end
def confirm_location
if [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?)
@location.update!(confirmed: true)
end
end
def show; end
def new_deactivation

5
app/models/location.rb

@ -7,7 +7,6 @@ class Location < ApplicationRecord
validates :mobility_type, on: :mobility_type, presence: { message: I18n.t("validations.location.mobility_standards") }
validates :startdate, on: :startdate, presence: { message: I18n.t("validations.location.startdate_invalid") }
validate :validate_startdate, on: :startdate, if: proc { |model| model.startdate.presence }
validate :validate_confirmed
belongs_to :scheme
has_many :lettings_logs, class_name: "LettingsLog"
has_many :location_deactivation_periods, class_name: "LocationDeactivationPeriod"
@ -127,10 +126,6 @@ class Location < ApplicationRecord
end
end
def validate_confirmed
self.confirmed = [postcode, location_admin_district, location_code, units, type_of_unit, mobility_type].all?(&:present?)
end
def linked_local_authorities
la = LocalAuthority.find_by(code: location_code)
return LocalAuthority.none unless la

Loading…
Cancel
Save