Skip to content

Commit

Permalink
Merge pull request #6956 from ministryofjustice/ap-5142-zero-cost-lim…
Browse files Browse the repository at this point in the history
…its-associated-applications

Ap 5142 zero cost limits associated applications
  • Loading branch information
kmahern authored Aug 29, 2024
2 parents 2fe3735 + adced11 commit 11e57c5
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/controllers/providers/limitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def no_state_change_required?
end

def form_needs_checking?
(legal_aid_application.used_delegated_functions? && !legal_aid_application.special_children_act_proceedings?) || @legal_aid_application.substantive_cost_overridable?
@legal_aid_application.emergency_cost_overridable? || @legal_aid_application.substantive_cost_overridable?
end

def clear_limit_and_reason
Expand Down
18 changes: 17 additions & 1 deletion app/models/legal_aid_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ def display_emergency_certificate?
end

def substantive_cost_overridable?
substantive_cost_limitation.present? && default_substantive_cost_limitation < MAX_SUBSTANTIVE_COST_LIMIT && !special_children_act_proceedings?
substantive_cost_limitation.present? && default_substantive_cost_limitation < MAX_SUBSTANTIVE_COST_LIMIT && !special_children_act_proceedings? && !family_linked_associated_application?
end

def emergency_cost_overridable?
display_emergency_certificate? && !family_linked_associated_application?
end

def substantive_cost_limitation
Expand All @@ -423,13 +427,25 @@ def substantive_cost_limitation
end

def default_substantive_cost_limitation
return 0.0 if family_linked_associated_application?

proceedings.map(&:substantive_cost_limitation).max
end

def default_delegated_functions_cost_limitation
return 0.0 if family_linked_associated_application?

lead_proceeding.delegated_functions_cost_limitation
end

def additional_family_lead_delegated_functions_cost_limitation
default_delegated_functions_cost_limitation / 2
end

def family_linked_associated_application?
lead_linked_application&.link_type_code == "FC_LEAD"
end

def find_or_create_ccms_submission
create_ccms_submission! unless ccms_submission
ccms_submission
Expand Down
3 changes: 0 additions & 3 deletions app/services/copy_case/cloner_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def clone_application_merits
merits = %i[
allegation
domestic_abuse_summary
emergency_cost_override
emergency_cost_reasons
emergency_cost_requested
latest_incident
in_scope_of_laspo
matter_opposition
Expand Down
4 changes: 1 addition & 3 deletions app/views/providers/limitations/_cost_limits.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<h3 class="govuk-heading-m">
<%= t(title_translation_path) %>
</h3>
<h3 class="govuk-heading-m"><%= t(".substantive_certificate") %></h3>

<p><%= t(".default_substantive_limit_is") %> <strong><%= gds_number_to_currency(@legal_aid_application.default_substantive_cost_limitation, precision: 0) %></strong></p>

Expand Down
53 changes: 34 additions & 19 deletions app/views/providers/limitations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
collection: @legal_aid_application.proceedings.in_order_of_addition, as: :proceeding,
locals: { translation_path: "providers.limitations.show" } %>

<h2 class="govuk-heading-l"><%= t(".cost_heading") %></h2>
<% if @legal_aid_application.display_emergency_certificate? %>
<h2 class="govuk-heading-l"><%= t(".cost_heading") %></h2>
<h3 class="govuk-heading-m"><%= t(".emergency_certificate") %></h3>

<p class="govuk-body">
Expand All @@ -26,31 +26,46 @@
) %>
</strong>
</p>
<%= form.govuk_radio_buttons_fieldset(:emergency_cost_override,
legend: { size: "s", tag: "h2", text: t(".cost_override_question") }) do %>
<%= form.govuk_radio_button(:emergency_cost_override, true, link_errors: true, label: { text: t("generic.yes") }) do %>
<%= form.govuk_text_field(
:emergency_cost_requested,
label: { text: t(".enter_cost_limit") },
value: number_to_currency_or_original_string(@form.emergency_cost_requested),
prefix_text: t("currency.gbp"),
width: "one-third",
) %>

<%= form.govuk_text_area(
:emergency_cost_reasons,
label: { text: t(".enter_cost_reasons") },
) %>
<% if Setting.linked_applications? && !@legal_aid_application.family_linked_associated_application? %>
<%= govuk_details(summary_text: t(".emergency_certificate_details_heading")) do %>
<p><%= sanitize(t(".emergency_certificate_details", limit: "<strong>#{gds_number_to_currency(
@legal_aid_application.additional_family_lead_delegated_functions_cost_limitation,
precision: 0,
)}</strong>")) %></p>
<% end %>
<% end %>

<% if @legal_aid_application.emergency_cost_overridable? %>
<%= form.govuk_radio_buttons_fieldset(:emergency_cost_override,
legend: { size: "s", tag: "h2", text: t(".cost_override_question") }) do %>
<%= form.govuk_radio_button(:emergency_cost_override, true, link_errors: true, label: { text: t("generic.yes") }) do %>
<%= form.govuk_text_field(
:emergency_cost_requested,
label: { text: t(".enter_cost_limit") },
value: number_to_currency_or_original_string(@form.emergency_cost_requested),
prefix_text: t("currency.gbp"),
width: "one-third",
) %>

<%= form.govuk_text_area(
:emergency_cost_reasons,
label: { text: t(".enter_cost_reasons") },
) %>
<% end %>
<%= form.govuk_radio_button(:emergency_cost_override, false, label: { text: t("generic.no") }) %>
<% end %>
<%= form.govuk_radio_button(:emergency_cost_override, false, label: { text: t("generic.no") }) %>
<% end %>
<% end %>

<% title_translation = @legal_aid_application.used_delegated_functions? ? ".substantive_certificate" : ".cost_heading" %>
<%= render partial: "providers/limitations/cost_limits",
locals: { title_translation_path: title_translation, form: } %>
<div class="govuk-!-padding-bottom-6"></div>
locals: { form: } %>

<%= if @legal_aid_application&.lead_linked_application&.link_type_code == "FC_LEAD"
govuk_warning_text(text: t(".family_warning"))
end %>

<div class="govuk-!-padding-bottom-6"></div>
<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
yes_no_options,
:value,
:label,
caption: { text: t(".caption"), size: "l" },
caption: { text: t(".caption"), size: "xl" },
legend: { text: content_for(:page_title), size: "xl", tag: "h1" } %>

<%= next_action_buttons(show_draft: true, form:) %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ en:
substantive_certificate: Substantive certificate
emergency_certificate: Emergency certificate
default_limit_is: The default emergency cost limit is
emergency_certificate_details_heading: What to add for family link applications
emergency_certificate_details: You can request %{limit} more for each application that will be family linked to this one
family_warning: As you have made a family link, the cost limit will be on the certificate of the application you submitted first.
proceeding_type:
client_role: "Client role: "
details_heading: Scope limitations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ Scenario: If I change the copied from Yes to No

Then I should be on a page showing "What you're applying for"
And I should be on a page showing "default substantive cost limit"
And I should be on a page showing "Do you want to request a higher emergency cost limit?"

When I choose 'No'
And I click 'Save and continue'
Then I should be on a page showing 'Check your answers'
And I should see "Non-molestation order"
109 changes: 109 additions & 0 deletions spec/models/legal_aid_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,74 @@

it { is_expected.to eq 12_000 }
end

context "when the application is is an associated family linked application" do
let(:lead_application) { create(:legal_aid_application) }

before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD") }

it { is_expected.to eq 0 }
end
end

describe "#default_delegated_functions_cost_limitation" do
subject(:default_delegated_functions_cost_limitation) { legal_aid_application.default_delegated_functions_cost_limitation }

before do
create(:proceeding, :da006, legal_aid_application:, delegated_functions_cost_limitation: 5_000, lead_proceeding: true)
create(:proceeding, :se013, legal_aid_application:, delegated_functions_cost_limitation: 10_000)
end

it { is_expected.to eq 5_000 }

context "when the application is is an associated family linked application" do
let(:lead_application) { create(:legal_aid_application) }

before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD") }

it { is_expected.to eq 0 }
end
end

describe "#additional_family_lead_delegated_functions_cost_limitation" do
subject(:additional_family_lead_delegated_functions_cost_limitation) { legal_aid_application.additional_family_lead_delegated_functions_cost_limitation }

before do
create(:proceeding, :da006, legal_aid_application:, delegated_functions_cost_limitation: 5_000, lead_proceeding: true)
create(:proceeding, :se013, legal_aid_application:, delegated_functions_cost_limitation: 10_000)
end

it { is_expected.to eq 2_500 }

context "when the application is is an associated family linked application" do
let(:lead_application) { create(:legal_aid_application) }

before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD") }

it { is_expected.to eq 0 }
end
end

describe "#family_linked_associated_application?" do
subject(:family_linked_associated_application?) { legal_aid_application.family_linked_associated_application? }

let(:lead_application) { create(:legal_aid_application) }

context "when the application does not have a lead application" do
it { is_expected.to be false }
end

context "when the application has been legal linked" do
before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "LEGAL") }

it { is_expected.to be false }
end

context "when the application has been family linked" do
before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD") }

it { is_expected.to be true }
end
end

describe "#bank_transactions" do
Expand Down Expand Up @@ -1930,6 +1998,47 @@

it { is_expected.to be false }
end

context "when the application is is an associated family linked application" do
let(:lead_application) { create(:legal_aid_application) }

before do
create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD")
create(:proceeding, :da001, legal_aid_application:, substantive_cost_limitation: 24_999)
end

it { is_expected.to be false }
end
end

describe "#emergency_cost_overridable?" do
subject { legal_aid_application.emergency_cost_overridable? }

let(:legal_aid_application) { create(:legal_aid_application, :with_proceedings, :with_delegated_functions_on_proceedings, explicit_proceedings: %i[da001], df_options: { DA001: [Time.zone.today, Time.zone.today] }) }

context "when the provider has used delegated functions" do
it { is_expected.to be true }
end

context "when the provider has not used delegated functions" do
let(:legal_aid_application) { create(:legal_aid_application) }

it { is_expected.to be false }
end

context "when there are special childrens act proceedings" do
before { legal_aid_application.proceedings << create(:proceeding, :pb003) }

it { is_expected.to be false }
end

context "when the application is is an associated family linked application" do
let(:lead_application) { create(:legal_aid_application) }

before { create(:linked_application, lead_application:, associated_application: legal_aid_application, link_type_code: "FC_LEAD") }

it { is_expected.to be false }
end
end

describe "#display_emergency_certificate?" do
Expand Down
3 changes: 0 additions & 3 deletions spec/services/copy_case/cloner_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@
expect { call }
.to change { target.reload.allegation }.from(nil)
.and change { target.reload.domestic_abuse_summary }.from(nil)
.and change { target.reload.emergency_cost_override.present? }.from(false).to(true)
.and change { target.reload.emergency_cost_reasons.present? }.from(false).to(true)
.and change { target.reload.emergency_cost_requested.present? }.from(false).to(true)
.and change { target.reload.in_scope_of_laspo }.from(nil).to(true)
.and change { target.reload.involved_children.size }.from(0).to(3)
.and change { target.reload.latest_incident }.from(nil)
Expand Down

0 comments on commit 11e57c5

Please sign in to comment.