Skip to content

Commit

Permalink
AP-5347 Mandatory disregards page (#7351)
Browse files Browse the repository at this point in the history
* AP-5347 Add mandatory disregards page

Add route, controller, view, step and form for new mandatory disregards page, behind the MTR2A feature flag. 

Add specs and feature test 

---------

Co-authored-by: RoseSAK <[email protected]>
  • Loading branch information
RoseSAK and RoseSAK authored Nov 4, 2024
1 parent d204c8d commit 88c93f5
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Providers
module Means
module CapitalDisregards
class MandatoryController < ProviderBaseController
prefix_step_with :capital_disregards

def show
@form = Providers::Means::CapitalDisregards::MandatoryForm.new(model: legal_aid_application)
end

def update
@form = Providers::Means::CapitalDisregards::MandatoryForm.new(form_params)
render :show unless save_continue_or_draft(@form)
end

private

def form_params
merge_with_model(legal_aid_application) do
params.require(:providers_means_capital_disregards_mandatory_form)
.permit(:none_selected, mandatory_capital_disregards: [])
.merge(legal_aid_application:)
end
end
end
end
end
end
115 changes: 115 additions & 0 deletions app/forms/providers/means/capital_disregards/mandatory_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
module Providers
module Means
module CapitalDisregards
class MandatoryForm
include ActiveModel::Model

DISREGARD_TYPES = %i[
backdated_benefits
backdated_community_care
budgeting_advances
compensation_miscarriage_of_justice
government_cost_of_living
independent_living_fund
infected_blood_support_scheme
modern_slavery_victim_care
payment_on_account_of_benefit
historical_child_abuse
social_fund
vaccine_damage
variant_creutzfeldt_jakob_disease
welsh_independent_living_grant
windrush_compensation_scheme
].freeze

attr_reader :mandatory_capital_disregards
attr_accessor :legal_aid_application, :none_selected

validate :validate_any_checkbox_checked, unless: :draft?
validate :validate_none_selected_and_another_checkbox_not_both_checked, unless: :draft?

def initialize(params = {})
self.legal_aid_application = params.delete(:model)
self.mandatory_capital_disregards = params["mandatory_capital_disregards"] || existing_mandatory_disregards

super
end

def mandatory_capital_disregards=(names)
@mandatory_capital_disregards = [names].flatten.compact_blank
end

def save_as_draft
@draft = true
save!
end

def draft?
@draft
end

def save
return false unless valid?

destroy_previous_disregards!
create_new_disregards!
end
alias_method :save!, :save

private

# create new records if they don't already exist
def create_new_disregards!
return unless mandatory_capital_disregards

mandatory_capital_disregards&.reject { |disregard|
existing_mandatory_disregards.include?(disregard)
}&.each { |disregard| legal_aid_application.capital_disregards.create!(name: disregard, mandatory: true) }
end

# destroy only the records which already exist but aren't selected
def destroy_previous_disregards!
legal_aid_application.mandatory_capital_disregards&.where&.not(name: mandatory_capital_disregards)&.destroy_all
end

def existing_mandatory_disregards
legal_aid_application.mandatory_capital_disregards.pluck(:name)
end

def none_selected?
none_selected == "true"
end

def any_checkbox_checked?
none_selected? || mandatory_capital_disregards.any?
end

def none_and_another_checkbox_checked?
none_selected? && mandatory_capital_disregards.any?
end

def validate_any_checkbox_checked
errors.add :mandatory_capital_disregards, error_message_for_none_selected unless any_checkbox_checked?
end

def validate_none_selected_and_another_checkbox_not_both_checked
errors.add :mandatory_capital_disregards, error_message_for_none_and_another_option_selected if none_and_another_checkbox_checked?
end

def error_message_for_none_selected
I18n.t("activemodel.errors.models.mandatory_capital_disregards.attributes.base.none_selected")
end

def error_message_for_none_and_another_option_selected
I18n.t("activemodel.errors.models.mandatory_capital_disregards.attributes.base.#{error_key('none_and_another_option_selected')}")
end

def error_key(key_name)
return "#{key_name}_with_partner" if legal_aid_application&.applicant&.has_partner_with_no_contrary_interest?

key_name
end
end
end
end
end
4 changes: 2 additions & 2 deletions app/forms/providers/policy_disregards_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PolicyDisregardsForm < BaseForm
attr_accessor(*CHECK_BOXES_ATTRIBUTES)

validate :validate_any_checkbox_checked, unless: :draft?
validate :validate_no_account_and_another_checkbox_not_both_checked, unless: :draft?
validate :validate_none_of_these_and_another_checkbox_not_both_checked, unless: :draft?

def has_partner_with_no_contrary_interest?
model.legal_aid_application.applicant&.has_partner_with_no_contrary_interest?
Expand All @@ -41,7 +41,7 @@ def validate_any_checkbox_checked
errors.add SINGLE_VALUE_ATTRIBUTES.first.to_sym, error_message_for_none_selected unless any_checkbox_checked?
end

def validate_no_account_and_another_checkbox_not_both_checked
def validate_none_of_these_and_another_checkbox_not_both_checked
errors.add SINGLE_VALUE_ATTRIBUTES.first.to_sym, error_message_for_none_and_another_option_selected if none_and_another_checkbox_checked?
end

Expand Down
1 change: 1 addition & 0 deletions app/models/legal_aid_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LegalAidApplication < ApplicationRecord
has_many :associated_applications, class_name: "LegalAidApplication", through: :associated_linked_applications
has_many :capital_disregards, dependent: :destroy
has_many :discretionary_capital_disregards, -> { where(mandatory: "false") }, class_name: "CapitalDisregard"
has_many :mandatory_capital_disregards, -> { where(mandatory: "true") }, class_name: "CapitalDisregard"

before_save :set_open_banking_consent_choice_at
before_create :create_app_ref
Expand Down
1 change: 1 addition & 0 deletions app/services/flow/flows/provider_capital_disregards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Flows
class ProviderCapitalDisregards < FlowSteps
STEPS = {
capital_disregards_discretionary: Steps::ProviderCapitalDisregards::DiscretionaryStep,
capital_disregards_mandatory: Steps::ProviderCapitalDisregards::MandatoryStep,
}.freeze
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ProviderCapital
if application.own_capital?
:restrictions
elsif application.capture_policy_disregards?
:policy_disregards
Setting.means_test_review_a? ? :capital_disregards_mandatory : :policy_disregards
else
application.passported? ? :check_passported_answers : :check_capital_answers
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Flow
module Steps
module ProviderCapitalDisregards
MandatoryStep = Step.new(
path: ->(application) { Steps.urls.providers_legal_aid_application_means_capital_disregards_mandatory_path(application) },
forward: :capital_disregards_discretionary,
check_answers: ->(application) { application.provider_checking_or_checked_citizens_means_answers? ? :check_capital_answers : :check_passported_answers },
)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%= form_with(model: @form,
url: providers_legal_aid_application_means_capital_disregards_mandatory_path(@legal_aid_application),
method: :patch,
local: true) do |form| %>
<% individual = @legal_aid_application.applicant.has_partner_with_no_contrary_interest? ? "partner" : "client" %>
<%= page_template page_title: t(".h1-heading"), template: :basic, form: do %>
<h1 class="govuk-heading-xl"><%= page_title %></h1>
<p class="govuk-body govuk-!-margin-bottom-6"><%= t(".paragraph.#{individual}") %></p>

<%= form.govuk_check_boxes_fieldset :mandatory_capital_disregards,
legend: { text: t(".h2-heading.#{individual}"), size: "l", tag: "h1" },
hint: { text: t(".hint-text_html") },
form_group: { class: @form.errors[:mandatory_capital_disregards].any? ? "govuk-form-group--error" : "" } do %>
<div class="deselect-group" data-deselect-ctrl="#providers-means-capital-disregards-mandatory-form-none-selected-true-field">
<% Providers::Means::CapitalDisregards::MandatoryForm::DISREGARD_TYPES.each_with_index do |disregard_type, idx| %>
<%= form.govuk_check_box :mandatory_capital_disregards,
disregard_type.to_s,
link_errors: idx.zero?,
label: { text: t(".#{disregard_type}") },
hint: { text: t(".#{disregard_type}_hint", default: "") } %>
<% end %>
</div>

<%= form.govuk_radio_divider %>
<%= form.govuk_check_box :mandatory_capital_disregards,
:none_of_these,
exclusive: true,
label: { text: t(".none_of_these") } %>
<% end %>
<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
17 changes: 8 additions & 9 deletions app/views/providers/means/policy_disregards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
<p class="govuk-error-message" id="savings-amount-cash-error">
<span class="govuk-visually-hidden">Error: </span><%= @form.errors[:england_infected_blood_support].first %></p>
<% end %>
<div class="deselect-group" data-deselect-ctrl="#policy-disregards-none-selected-true-field">
<% Providers::PolicyDisregardsForm::SINGLE_VALUE_ATTRIBUTES.each do |checkbox| %>
<%= form.govuk_check_box checkbox, true, "", multiple: false, link_errors: true, label: { text: t(".#{checkbox}") } %>
<% end %>
</div>

<%= form.govuk_radio_divider %>
<%= form.govuk_check_box :none_selected, true, "", multiple: false, label: { text: t(".none_of_these") } %>
<div class="deselect-group" data-deselect-ctrl="#policy-disregards-none-selected-true-field">
<% Providers::PolicyDisregardsForm::SINGLE_VALUE_ATTRIBUTES.each_with_index do |checkbox, idx| %>
<%= form.govuk_check_box checkbox, true, "", multiple: false, link_errors: idx.zero?, label: { text: t(".#{checkbox}") } %>
<% end %>
</div>

<% end %>
<%= form.govuk_radio_divider %>
<%= form.govuk_check_box :none_selected, true, "", multiple: false, label: { text: t(".none_of_these") } %>
<% end %>
<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
6 changes: 6 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ en:
blank: Select if you want to link this application with another one
confirm_link:
blank: Select if you want to link to the application
mandatory_capital_disregards:
attributes:
base:
none_selected: Select if your client has received any of these payments
none_selected_with_partner: Select if your client or their partner has received any of these payments, or select 'My client has not received any of these payments'
none_and_another_option_selected: Your client must either receive one or more of these payments or none
other_assets_declaration:
attributes:
valuable_items_value:
Expand Down
30 changes: 30 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,36 @@ en:
victims_of_overseas_terrorism_compensation: Victims of Overseas Terrorism Compensation Scheme (VOTCS) 2012 payment
we_love_manchester_emergency_fund: We Love Manchester Emergency Fund payment
none_of_these: My client has not received any of these payments
mandatory:
show:
h1-heading: Disregarded payments
paragraph:
client: These payments are not counted, but we still need to know about them to understand your client’s finances. They are called mandatory disregards.
partner: These payments are not counted, but we still need to know about them to understand your client and their partner’s finances. They are called mandatory disregards.
h2-heading:
client: Select if your client has received any of these payments
partner: Select if your client or their partner has received any of these payments
hint-text_html: |
These are one-off payments. Do not include any regular payments.<br><br>
Select all that apply.
backdated_benefits: Backdated benefits and child maintenance payments received in the last 24 months
backdated_community_care: Backdated Community Care payments
budgeting_advances: Budgeting Advances
compensation_miscarriage_of_justice: Compensation for miscarriage of justice
government_cost_of_living: Government cost of living payment
government_cost_of_living_hint: For example, Pensioner Cost of Living Payment, Cost of Living Payment, Disability Cost of Living Payment, Household support fund, Council tax rebate, Energy Bills Support Scheme (EBSS), Payments for those who are not served by mains gas
independent_living_fund: Independent Living Fund payment
infected_blood_support_scheme: Infected Blood Support Scheme payment
infected_blood_support_scheme_hint: Includes Infected Blood Interim Compensation Payment Scheme, Infected Blood Further Interim Compensation Payment Scheme, Infected Blood Compensation Scheme, arrangements made under section 56(1) of the Victims and Prisoners Act 2024, or earlier support schemes
modern_slavery_victim_care: Modern Slavery Victim Care Contract (MSVCC) payment
payment_on_account_of_benefit: Payments on Account of Benefit
historical_child_abuse: Scotland and Northern Ireland Redress Schemes for historical child abuse payment
social_fund: Social Fund payment
vaccine_damage: Vaccine Damage Payment
variant_creutzfeldt_jakob_disease: Variant Creutzfeldt-Jakob disease (vCJD) Trust payment
welsh_independent_living_grant: Welsh Independent Living Grant
windrush_compensation_scheme: Windrush Compensation Scheme payment
none_of_these: My client has not received any of these payments
receives_state_benefits:
show:
page_title: Does your client get any benefits, charitable or government payments?
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@

namespace :capital_disregards do
resource :discretionary, only: %i[show update], path: "payments_to_review", controller: "discretionary"
resource :mandatory, only: %i[show update], path: "disregarded_payments", controller: "mandatory"
end
end
namespace :correspondence_address do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddUniquenessIndexToCapitalDisregards < ActiveRecord::Migration[7.2]
disable_ddl_transaction!

def change
add_index(:capital_disregards, [:legal_aid_application_id, :name], unique: true, algorithm: :concurrently)
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_10_22_133251) do
ActiveRecord::Schema[7.2].define(version: 2024_10_30_094958) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -297,6 +297,7 @@
t.string "account_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["legal_aid_application_id", "name"], name: "index_capital_disregards_on_legal_aid_application_id_and_name", unique: true
t.index ["legal_aid_application_id"], name: "index_capital_disregards_on_legal_aid_application_id"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,26 @@ Feature: Discretionary capital disregards question and flow
And I select "None of these assets"

When I click "Save and continue"
Then I should be on a page with title "Which schemes or trusts have paid your client?"
And I select "None of these schemes or trusts"
Then I should be on a page with title "Disregarded payments"
And I should see "Select if your client has received any of these payments"
And the following sections should exist:
| tag | section |
| .govuk-checkboxes__label | Backdated benefits and child maintenance payments received in the last 24 months |
| .govuk-checkboxes__label | Backdated Community Care payments |
| .govuk-checkboxes__label | Budgeting Advances |
| .govuk-checkboxes__label | Compensation for miscarriage of justice|
| .govuk-checkboxes__label | Government cost of living payment |
| .govuk-checkboxes__label | Independent Living Fund payment |
| .govuk-checkboxes__label | Infected Blood Support Scheme payment |
| .govuk-checkboxes__label | Modern Slavery Victim Care Contract (MSVCC) payment |
| .govuk-checkboxes__label | Payments on Account of Benefit |
| .govuk-checkboxes__label | Scotland and Northern Ireland Redress Schemes for historical child abuse payment |
| .govuk-checkboxes__label | Social Fund payment |
| .govuk-checkboxes__label | Vaccine Damage Payment |
| .govuk-checkboxes__label | Variant Creutzfeldt-Jakob disease (vCJD) Trust payment |
| .govuk-checkboxes__label | Welsh Independent Living Grant |
| .govuk-checkboxes__label | Windrush Compensation Scheme payment |
And I select "Infected Blood Support Scheme payment"

When I click "Save and continue"
Then I should be on a page with title "Payments to be reviewed"
Expand All @@ -93,3 +111,8 @@ Feature: Discretionary capital disregards question and flow
Then I should be on a page with title "Payments to be reviewed"
And the checkbox for Grenfell Tower fire victims payment should be unchecked
And the checkbox for London Emergencies Trust payment should be checked

When I click link "Back"
Then I should be on a page with title "Disregarded payments"
And the checkbox for Government cost of living payment should be unchecked
And the checkbox for Infected Blood Support Scheme payment should be checked
Loading

0 comments on commit 88c93f5

Please sign in to comment.