Browse Source

feat: show completed/incomplete locations and validate when completed == 0

pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
fdf230928f
  1. 2
      app/models/form/lettings/questions/location_id.rb
  2. 20
      app/models/scheme.rb
  3. 8
      app/models/validations/setup_validations.rb
  4. 2
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb
  5. 1
      config/locales/en.yml

2
app/models/form/lettings/questions/location_id.rb

@ -27,7 +27,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question
def displayed_answer_options(lettings_log, _user = nil) def displayed_answer_options(lettings_log, _user = nil)
return {} unless lettings_log.scheme return {} unless lettings_log.scheme
scheme_location_ids = lettings_log.scheme.locations.reject { |location| location.status_at(lettings_log.startdate || Time.zone.today) == :incomplete }.pluck(:id) scheme_location_ids = lettings_log.scheme.locations.reject { |location| location.status == :incomplete }.pluck(:id)
answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) }
end end

20
app/models/scheme.rb

@ -166,9 +166,7 @@ class Scheme < ApplicationRecord
end end
def appended_text def appended_text
active_count = locations.count { |location| %i[active deactivating_soon].include?(location.status) } "#{completed_locations_count} completed #{'location'.pluralize(completed_locations_count)}, #{incomplete_locations_count} incomplete #{'location'.pluralize(incomplete_locations_count)}"
inactive_count = locations.count { |location| !%i[active deactivating_soon].include?(location.status) }
"#{active_count} active #{'location'.pluralize(active_count)}, #{inactive_count} inactive #{'location'.pluralize(inactive_count)}"
end end
def hint def hint
@ -237,7 +235,7 @@ class Scheme < ApplicationRecord
end end
def status_at(date) def status_at(date)
return :incomplete unless confirmed && has_active_locations? return :incomplete unless confirmed && has_completed_locations?
return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date return :deactivated if open_deactivation&.deactivation_date.present? && date >= open_deactivation.deactivation_date
return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date return :deactivating_soon if open_deactivation&.deactivation_date.present? && date < open_deactivation.deactivation_date
return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date return :reactivating_soon if recent_deactivation&.reactivation_date.present? && date < recent_deactivation.reactivation_date
@ -257,7 +255,17 @@ class Scheme < ApplicationRecord
status == :deactivated status == :deactivated
end end
def has_active_locations? def has_completed_locations?
locations.count { |location| %i[active deactivating_soon].include?(location.status) }.positive? completed_locations_count.positive?
end
private
def completed_locations_count
locations.count { |location| location.status != :incomplete }
end
def incomplete_locations_count
locations.count { |location| location.status == :incomplete }
end end
end end

8
app/models/validations/setup_validations.rb

@ -20,6 +20,14 @@ module Validations::SetupValidations
location_during_startdate_validation(record, :location_id) location_during_startdate_validation(record, :location_id)
end end
def validate_scheme_has_completed_locations_validation(record)
return unless record.scheme
unless record.scheme.has_completed_locations?
record.errors.add :scheme_id, I18n.t("validations.scheme.no_completed_locations")
end
end
def validate_scheme(record) def validate_scheme(record)
location_during_startdate_validation(record, :scheme_id) location_during_startdate_validation(record, :scheme_id)
scheme_during_startdate_validation(record, :scheme_id) scheme_during_startdate_validation(record, :scheme_id)

2
app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb

@ -15,7 +15,7 @@
<li>Download the <%= govuk_link_to "bulk lettings template", @form.template_path %></li> <li>Download the <%= govuk_link_to "bulk lettings template", @form.template_path %></li>
<li>Export the data from your housing management system, matching the template. <%= govuk_link_to "Find out more about exporting your data", guidance_bulk_upload_lettings_logs_path %></li> <li>Export the data from your housing management system, matching the template. <%= govuk_link_to "Find out more about exporting your data", guidance_bulk_upload_lettings_logs_path %></li>
<li>If you cannot export it in this format, you may have to input it manually</li> <li>If you cannot export it in this format, you may have to input it manually</li>
<li>You can not have a file with both general needs logs and supported housing logs. These must be in separate files</li> <li>You cannot have a file with both general needs logs and supported housing logs. These must be in separate files</li>
</ul> </ul>
<h2 class="govuk-heading-m">Check your data</h2> <h2 class="govuk-heading-m">Check your data</h2>

1
config/locales/en.yml

@ -446,6 +446,7 @@ en:
during_deactivated_period: "The scheme is already deactivated during this date, please enter a different date" during_deactivated_period: "The scheme is already deactivated during this date, please enter a different date"
owning_organisation: owning_organisation:
does_not_own_stock: "Enter an organisation that owns housing stock" does_not_own_stock: "Enter an organisation that owns housing stock"
no_completed_locations: "This scheme cannot be chosen as it has 0 completed locations"
location: location:
postcode_blank: "Enter a postcode" postcode_blank: "Enter a postcode"

Loading…
Cancel
Save