Browse Source

Merge branch 'main' into CLDC-2140-scheme-typeahead-with-inactive-locations

# Conflicts:
#	app/models/location.rb
#	spec/models/validations/date_validations_spec.rb
#	spec/models/validations/setup_validations_spec.rb
pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
70ab30cc22
  1. 7
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 7
      app/controllers/bulk_upload_sales_logs_controller.rb
  3. 27
      app/models/forms/bulk_upload_lettings/guidance.rb
  4. 14
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  5. 27
      app/models/forms/bulk_upload_sales/guidance.rb
  6. 14
      app/models/forms/bulk_upload_sales/prepare_your_file.rb
  7. 2
      app/models/validations/financial_validations.rb
  8. 2
      app/models/validations/sales/financial_validations.rb
  9. 2
      app/models/validations/tenancy_validations.rb
  10. 6
      app/services/imports/lettings_logs_import_service.rb
  11. 5
      app/services/imports/sales_logs_import_service.rb
  12. 4
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file.html.erb
  13. 2
      app/views/bulk_upload_lettings_results/show.html.erb
  14. 2
      app/views/bulk_upload_lettings_results/summary.html.erb
  15. 4
      app/views/bulk_upload_sales_logs/forms/prepare_your_file.html.erb
  16. 2
      app/views/bulk_upload_sales_results/show.html.erb
  17. 6
      app/views/bulk_upload_shared/guidance.html.erb
  18. 2
      config/routes.rb
  19. BIN
      public/files/bulk-upload-lettings-specification-2023-24.xlsx
  20. 0
      public/files/bulk-upload-lettings-template-2022-23.xlsx
  21. BIN
      public/files/bulk-upload-lettings-template-2023-24.xlsx
  22. BIN
      public/files/bulk-upload-sales-specification-2023-24.xlsx
  23. 0
      public/files/bulk-upload-sales-template-2022-23.xlsx
  24. BIN
      public/files/bulk-upload-sales-template-2023-24.xlsx
  25. 10
      spec/models/validations/tenancy_validations_spec.rb
  26. 42
      spec/services/imports/lettings_logs_import_service_spec.rb
  27. 24
      spec/services/imports/sales_logs_import_service_spec.rb

7
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -21,11 +21,6 @@ class BulkUploadLettingsLogsController < ApplicationController
end
end
def guidance
@form = Forms::BulkUploadLettings::PrepareYourFile.new
render "bulk_upload_shared/guidance"
end
private
def current_year
@ -44,6 +39,8 @@ private
Forms::BulkUploadLettings::Year.new(form_params)
when "prepare-your-file"
Forms::BulkUploadLettings::PrepareYourFile.new(form_params)
when "guidance"
Forms::BulkUploadLettings::Guidance.new(form_params)
when "needstype"
Forms::BulkUploadLettings::Needstype.new(form_params)
when "upload-your-file"

7
app/controllers/bulk_upload_sales_logs_controller.rb

@ -21,11 +21,6 @@ class BulkUploadSalesLogsController < ApplicationController
end
end
def guidance
@form = Forms::BulkUploadSales::PrepareYourFile.new
render "bulk_upload_shared/guidance"
end
private
def current_year
@ -42,6 +37,8 @@ private
Forms::BulkUploadSales::Year.new(form_params)
when "prepare-your-file"
Forms::BulkUploadSales::PrepareYourFile.new(form_params)
when "guidance"
Forms::BulkUploadSales::Guidance.new(form_params)
when "upload-your-file"
Forms::BulkUploadSales::UploadYourFile.new(form_params.merge(current_user:))
when "checking-file"

27
app/models/forms/bulk_upload_lettings/guidance.rb

@ -0,0 +1,27 @@
module Forms
module BulkUploadLettings
class Guidance
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_shared/guidance"
end
def back_path
bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: })
end
def template_path
Forms::BulkUploadLettings::PrepareYourFile.new(year:).template_path
end
def specification_path
Forms::BulkUploadLettings::PrepareYourFile.new(year:).specification_path
end
end
end
end

14
app/models/forms/bulk_upload_lettings/prepare_your_file.rb

@ -26,11 +26,21 @@ module Forms
end
def template_path
"/files/bulk-upload-lettings-template-v1.xlsx"
case year
when 2022
"/files/bulk-upload-lettings-template-2022-23.xlsx"
when 2023
"/files/bulk-upload-lettings-template-2023-24.xlsx"
end
end
def specification_path
"/files/bulk-upload-lettings-specification-2022-23.xlsx"
case year
when 2022
"/files/bulk-upload-lettings-specification-2022-23.xlsx"
when 2023
"/files/bulk-upload-lettings-specification-2023-24.xlsx"
end
end
def year_combo

27
app/models/forms/bulk_upload_sales/guidance.rb

@ -0,0 +1,27 @@
module Forms
module BulkUploadSales
class Guidance
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
attribute :year, :integer
def view_path
"bulk_upload_shared/guidance"
end
def back_path
bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: })
end
def template_path
Forms::BulkUploadSales::PrepareYourFile.new(year:).template_path
end
def specification_path
Forms::BulkUploadSales::PrepareYourFile.new(year:).specification_path
end
end
end
end

14
app/models/forms/bulk_upload_sales/prepare_your_file.rb

@ -24,11 +24,21 @@ module Forms
end
def template_path
"/files/bulk-upload-sales-template-v1.xlsx"
case year
when 2022
"/files/bulk-upload-sales-template-2022-23.xlsx"
when 2023
"/files/bulk-upload-sales-template-2023-24.xlsx"
end
end
def specification_path
"/files/bulk-upload-sales-specification-2022-23.xlsx"
case year
when 2022
"/files/bulk-upload-sales-specification-2022-23.xlsx"
when 2023
"/files/bulk-upload-sales-specification-2023-24.xlsx"
end
end
def year_combo

2
app/models/validations/financial_validations.rb

@ -4,7 +4,7 @@ module Validations::FinancialValidations
# or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record)
if !record.has_hbrentshortfall? && record.tshortfall.present?
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.outstanding_amount_not_required")
record.errors.add :tshortfall, :no_outstanding_charges, message: I18n.t("validations.financial.tshortfall.outstanding_amount_not_required")
end
end

2
app/models/validations/sales/financial_validations.rb

@ -37,7 +37,7 @@ module Validations::Sales::FinancialValidations
end
def validate_mortgage(record)
record.errors.add :mortgage, I18n.t("validations.financial.mortgage") if record.mortgage_used? && record.mortgage&.zero?
record.errors.add :mortgage, :cannot_be_0, message: I18n.t("validations.financial.mortgage") if record.mortgage_used? && record.mortgage&.zero?
end
def validate_cash_discount(record)

2
app/models/validations/tenancy_validations.rb

@ -42,7 +42,7 @@ module Validations::TenancyValidations
def validate_joint_tenancy(record)
return unless record.collection_start_year && record.joint
if record.hhmemb == 1 && record.joint != 2 && record.collection_start_year >= 2022
if record.hhmemb == 1 && record.joint == 1 && record.collection_start_year >= 2022
record.errors.add :joint, :not_joint_tenancy, message: I18n.t("validations.tenancy.not_joint")
record.errors.add :hhmemb, I18n.t("validations.tenancy.joint_more_than_one_member")
end

6
app/services/imports/lettings_logs_import_service.rb

@ -332,6 +332,12 @@ module Imports
@logs_overridden << lettings_log.old_id
attributes.delete("ecstat1")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:tshortfall, :no_outstanding_charges)
@logger.warn("Log #{lettings_log.old_id}: Removing tshortfall as there are no outstanding charges")
@logs_overridden << lettings_log.old_id
attributes.delete("tshortfall")
attributes.delete("hbrentshortfall")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

5
app/services/imports/sales_logs_import_service.rb

@ -225,6 +225,11 @@ module Imports
attributes.delete("postcode_full")
attributes["pcodenk"] = attributes["la"].present? ? 1 : nil
save_sales_log(attributes, previous_status)
elsif sales_log.errors.of_kind?(:mortgage, :cannot_be_0)
@logger.warn("Log #{sales_log.old_id}: Removing mortgage because it cannot be 0")
@logs_overridden << sales_log.old_id
attributes.delete("mortgage")
save_sales_log(attributes, previous_status)
else
@logger.error("Log #{sales_log.old_id}: Failed to import")
sales_log.errors.each do |error|

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

@ -13,14 +13,14 @@
<h2 class="govuk-heading-m">Create your file</h2>
<ul class="govuk-list govuk-list--bullet">
<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", bulk_upload_lettings_log_path(id: "guidance", form: { year: @form.year }) %></li>
<li>If you cannot export it in this format, you may have to input it manually</li>
<li>You cannot have a file with both general needs logs and supported housing logs. These must be in separate files</li>
</ul>
<h2 class="govuk-heading-m">Check your data</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li>
<li>Check data is complete and formatted correctly, using <%= govuk_link_to "data specifications", @form.specification_path, target: "_blank" %></li>
</ul>
<h2 class="govuk-heading-m">Save your file</h2>

2
app/views/bulk_upload_lettings_results/show.html.erb

@ -4,7 +4,7 @@
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the specification to help you fix the cells in your CSV file.
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadLettings::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
</div>
<h2 class="govuk-heading-m"><%= @bulk_upload.filename %></h2>

2
app/views/bulk_upload_lettings_results/summary.html.erb

@ -4,7 +4,7 @@
<h1 class="govuk-heading-l">Fix <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> and upload file again</h1>
<p class="govuk-body-l">
We could not create logs from your bulk upload. Below is a list of everything that you need to fix your spreadsheet. You can download the specification to help you fix the cells in your CSV file.
We could not create logs from your bulk upload. Below is a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadLettings::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
</p>
<p class="govuk-body-l">

4
app/views/bulk_upload_sales_logs/forms/prepare_your_file.html.erb

@ -13,13 +13,13 @@
<h2 class="govuk-heading-m">Create your file</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Download the <%= govuk_link_to "bulk sales 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_sales_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", bulk_upload_sales_log_path(id: "guidance", form: { year: @form.year }) %></li>
<li>If you cannot export it in this format, you may have to input it manually</li>
</ul>
<h2 class="govuk-heading-m">Check your data</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Check data is complete and formatted correctly, using data specifications (opens in a new tab)</li>
<li>Check data is complete and formatted correctly, using data <%= govuk_link_to "specifications", @form.specification_path, target: "_blank" %></li>
</ul>
<h2 class="govuk-heading-m">Save your file</h2>

2
app/views/bulk_upload_sales_results/show.html.erb

@ -4,7 +4,7 @@
<h1 class="govuk-heading-l">We found <%= pluralize(@bulk_upload.bulk_upload_errors.count, "error") %> in your file</h1>
<div class="govuk-body">
Here’s a list of everything that you need to fix your spreadsheet. You can download the specification to help you fix the cells in your CSV file.
Here’s a list of everything that you need to fix your spreadsheet. You can download the <%= govuk_link_to "specification", Forms::BulkUploadSales::PrepareYourFile.new(year: @bulk_upload.year).specification_path, target: "_blank" %> to help you fix the cells in your CSV file.
</div>
<h2 class="govuk-heading-m"><%= @bulk_upload.filename %></h2>

6
app/views/bulk_upload_shared/guidance.html.erb

@ -1,5 +1,5 @@
<% content_for :before_content do %>
<%= govuk_back_link href: :back %>
<%= govuk_back_link href: @form.back_path %>
<% end %>
<div class="govuk-grid-row">
@ -33,7 +33,7 @@
<p class="govuk-!-font-weight-bold">It can take HMS providers a while to update these per new collection year, so you may have to wait for updates to export, or adjust your data manually post-export.</p>
<% end %>
<%= govuk_details(summary_text: "My organisation does not have a CMS") do %>
<p class="govuk-body">Your organisation’s IT team may be able to export CSV data for you - <%= govuk_link_to "find out more about data specification", @form.specification_path %>. This document outlines:</p>
<p class="govuk-body">Your organisation’s IT team may be able to export CSV data for you - <%= govuk_link_to "find out more about data specification", @form.specification_path, target: "_blank" %>. This document outlines:</p>
<ul class="govuk-list govuk-list--bullet">
<li>required fields</li>
<li>each field's valid response</li>
@ -45,7 +45,7 @@
<div class="govuk-!-padding-bottom-4">
<h2 class="govuk-heading-s">Getting help</h2>
<p class="govuk-body">There is no step-by-step bulk upload guide like there is with single log upload. However, you can download <%= govuk_link_to "our template", @form.template_path %>, which you can copy-paste data into from your systems column-by-column. You can also view a post-upload report showing any data errors, and our <%= govuk_link_to "data specification", @form.specification_path %> can help fix these.</p>
<p class="govuk-body">There is no step-by-step bulk upload guide like there is with single log upload. However, you can download <%= govuk_link_to "our template", @form.template_path %>, which you can copy-paste data into from your systems column-by-column. You can also view a post-upload report showing any data errors, and our <%= govuk_link_to "data specification", @form.specification_path, target: "_blank" %> can help fix these.</p>
<p class="govuk-body">If you still need support mapping data in the way we need, DLUHC’s helpdesk can help. If your data is across multiple systems, or is hard to export as a single file in the correct format, you could try different exports, or copy-pasting data by hand.</p>
</div>
</div>

2
config/routes.rb

@ -134,7 +134,6 @@ Rails.application.routes.draw do
resources :bulk_upload_lettings_logs, path: "bulk-upload-logs", only: %i[show update] do
collection do
get :start
get "guidance", to: "bulk_upload_lettings_logs#guidance"
end
end
@ -169,7 +168,6 @@ Rails.application.routes.draw do
resources :bulk_upload_sales_logs, path: "bulk-upload-logs" do
collection do
get :start
get "guidance", to: "bulk_upload_sales_logs#guidance"
end
end

BIN
public/files/bulk-upload-lettings-specification-2023-24.xlsx

Binary file not shown.

0
public/files/bulk-upload-lettings-template-v1.xlsx → public/files/bulk-upload-lettings-template-2022-23.xlsx

BIN
public/files/bulk-upload-lettings-template-2023-24.xlsx

Binary file not shown.

BIN
public/files/bulk-upload-sales-specification-2023-24.xlsx

Binary file not shown.

0
public/files/bulk-upload-sales-template-v1.xlsx → public/files/bulk-upload-sales-template-2022-23.xlsx

BIN
public/files/bulk-upload-sales-template-2023-24.xlsx

Binary file not shown.

10
spec/models/validations/tenancy_validations_spec.rb

@ -311,6 +311,16 @@ RSpec.describe Validations::TenancyValidations do
expect(record.errors["joint"]).to be_empty
expect(record.errors["hhmemb"]).to be_empty
end
it "does not error when don't know answer to joint" do
record.hhmemb = 1
record.joint = 3
tenancy_validator.validate_joint_tenancy(record)
expect(record.errors["joint"]).to be_empty
expect(record.errors["hhmemb"]).to be_empty
end
end
end
end

42
spec/services/imports/lettings_logs_import_service_spec.rb

@ -671,5 +671,47 @@ RSpec.describe Imports::LettingsLogsImportService do
expect(lettings_log.hhmemb).to eq(1)
end
end
context "when there are no outstanding charges but outstanding amount is given" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
let(:lettings_log_file) { open_file(fixture_directory, lettings_log_id) }
let(:lettings_log_xml) { Nokogiri::XML(lettings_log_file) }
before do
FormHandler.instance.use_fake_forms!
Singleton.__init__(FormHandler)
lettings_log_xml.at_xpath("//xmlns:DAY").content = "10"
lettings_log_xml.at_xpath("//xmlns:MONTH").content = "10"
lettings_log_xml.at_xpath("//xmlns:YEAR").content = "2022"
lettings_log_xml.at_xpath("//xmlns:P1Nat").content = "18"
lettings_log_xml.at_xpath("//xmlns:Q18d").content = "2"
lettings_log_xml.at_xpath("//xmlns:Q18dyes").content = "20"
lettings_log_xml.at_xpath("//xmlns:_2cYears").content = ""
lettings_log_xml.at_xpath("//xmlns:Inj").content = ""
lettings_log_xml.at_xpath("//xmlns:LeftAF").content = ""
end
after do
FormHandler.instance.use_real_forms!
Singleton.__init__(FormHandler)
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing tshortfall as there are no outstanding charges/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the referral answer" do
allow(logger).to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log).not_to be_nil
expect(lettings_log.tshortfall).to be_nil
expect(lettings_log.hbrentshortfall).to be_nil
end
end
end
end

24
spec/services/imports/sales_logs_import_service_spec.rb

@ -637,6 +637,30 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "when mortgage value is 0" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = "0"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing mortgage because it cannot be 0/)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error
end
it "clears out the referral answer" do
allow(logger).to receive(:warn)
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log).not_to be_nil
expect(sales_log.mortgage).to be_nil
end
end
context "and it has an invalid income" do
let(:sales_log_id) { "shared_ownership_sales_log" }

Loading…
Cancel
Save