From 8e28cf8358225ece819878dfbe481b069b11faad Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Wed, 25 Sep 2024 16:51:38 +0100 Subject: [PATCH 1/6] Indicate to user that a Case has been re-circulated --- caseworker/advice/templates/advice/view_my_advice.html | 8 +++++++- caseworker/advice/views.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/caseworker/advice/templates/advice/view_my_advice.html b/caseworker/advice/templates/advice/view_my_advice.html index f8476e66e0..3b3c83ca85 100644 --- a/caseworker/advice/templates/advice/view_my_advice.html +++ b/caseworker/advice/templates/advice/view_my_advice.html @@ -31,7 +31,13 @@


-

View recommendation

+

View recommendation + {% if case_basic.circulation_details.is_case_sent_back %} + + Re-circulated + + {% endif %} +

{% if my_advice %} {% if buttons.edit_recommendation %} diff --git a/caseworker/advice/views.py b/caseworker/advice/views.py index 83cbd5d5ad..8e16cf8cec 100644 --- a/caseworker/advice/views.py +++ b/caseworker/advice/views.py @@ -10,7 +10,7 @@ from caseworker.advice import forms, services, constants from caseworker.advice.forms import DESNZTriggerListAssessmentForm, DESNZTriggerListAssessmentEditForm from caseworker.cases.helpers.case import CaseworkerMixin -from caseworker.cases.services import get_case, get_final_decision_documents +from caseworker.cases.services import get_case, get_case_basic_details, get_final_decision_documents from caseworker.cases.helpers.ecju_queries import has_open_queries from caseworker.cases.views.main import CaseTabsMixin from caseworker.core.helpers import get_organisation_documents @@ -40,6 +40,10 @@ def case_id(self): def case(self): return get_case(self.request, self.case_id) + @cached_property + def case_basic(self): + return get_case_basic_details(self.request, self.case_id) + @cached_property def denial_reasons_display(self): denial_reasons_data = get_denial_reasons(self.request) @@ -259,6 +263,7 @@ def get_context_data(self, **kwargs): "current_tab": "cases:view_my_advice", "security_approvals_classified_display": self.security_approvals_classified_display, "assessed_trigger_list_goods": self.assessed_trigger_list_goods, + "case_basic": self.case_basic, **services.get_advice_tab_context(self.case, self.caseworker, str(self.kwargs["queue_pk"])), } @@ -805,6 +810,7 @@ def get_context(self, **kwargs): "queue_id": self.queue_id, "refusal_note": refusal_note, "has_open_queries": has_open_queries(self.request, self.case_id), + "case_basic": self.case_basic, } def form_valid(self, form): From 35ea91c2613f8b3d9769722a40f3e75e679719a2 Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Thu, 26 Sep 2024 15:20:10 +0100 Subject: [PATCH 2/6] Allow user to give advice multiple times There will be other changes required as well, this is only adjusting a rule and adding button. --- caseworker/advice/rules.py | 2 +- caseworker/advice/templates/advice/view_my_advice.html | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/caseworker/advice/rules.py b/caseworker/advice/rules.py index cabc597733..dc689cf8f9 100644 --- a/caseworker/advice/rules.py +++ b/caseworker/advice/rules.py @@ -46,7 +46,7 @@ def can_user_make_recommendation(request, case): # Existing advice, so this must be edited if existing_advice: - return False + return True if team == services.FCDO_TEAM: return can_fcdo_make_recommendation(user, case, queue_alias) diff --git a/caseworker/advice/templates/advice/view_my_advice.html b/caseworker/advice/templates/advice/view_my_advice.html index 3b3c83ca85..a8f116f0b4 100644 --- a/caseworker/advice/templates/advice/view_my_advice.html +++ b/caseworker/advice/templates/advice/view_my_advice.html @@ -31,6 +31,7 @@


+ {% test_rule 'can_user_make_recommendation' request case as can_user_make_recommendation %}

View recommendation {% if case_basic.circulation_details.is_case_sent_back %} @@ -49,6 +50,10 @@

View recommendation Clear recommendation {% endif %} + {% if can_user_make_recommendation %} + Make new recommendation + {% endif %} + {% for advice in my_advice %} {% include "advice/advice_details.html" %} {% endfor %} From 59f1238e535e51de854856bc50e79eb783e726a7 Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Fri, 27 Sep 2024 12:57:35 +0100 Subject: [PATCH 3/6] Add helper function to group advice by date --- caseworker/advice/services.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/caseworker/advice/services.py b/caseworker/advice/services.py index 144f7124d2..6ebbd0e13a 100644 --- a/caseworker/advice/services.py +++ b/caseworker/advice/services.py @@ -291,11 +291,22 @@ def order_by_party_type(all_advice): return ordered_advice +def group_advice_by_date(all_advice): + grouped = defaultdict(list) + for item in all_advice: + created = item['created_at'][:19] # TODO parse and extract date + grouped[created].append(item) + + return grouped + def get_consolidated_advice(advice, team_alias): level = "final" if team_alias == LICENSING_UNIT_TEAM else "team" team_advice = filter_advice_by_level(advice, [level]) consolidated_advice = filter_advice_by_team(team_advice, team_alias) + grouped_by_date = group_advice_by_date(consolidated_advice) + recent_date = sorted(grouped_by_date.keys())[-1] + consolidated_advice = grouped_by_date[recent_date] return order_by_party_type(consolidated_advice) From 06019e6752027cd16cf4260c184d1283ee9cfd67 Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Fri, 27 Sep 2024 12:58:07 +0100 Subject: [PATCH 4/6] Add option to give final advice again --- caseworker/advice/templates/advice/view-advice.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/caseworker/advice/templates/advice/view-advice.html b/caseworker/advice/templates/advice/view-advice.html index 01610ec584..5f5c335b8f 100644 --- a/caseworker/advice/templates/advice/view-advice.html +++ b/caseworker/advice/templates/advice/view-advice.html @@ -97,6 +97,13 @@

Reason for returning

{% endif %} + {% if case_basic.circulation_details.is_case_sent_back %} + + Re-circulated + + {% endif %} +

+ {% if finalise_case %} {% if has_open_queries %}
@@ -119,6 +126,11 @@

Reason for returning

{% endif %} + {% test_rule 'can_user_review_and_combine' request case as can_user_review_and_combine %} + {% if can_user_review_and_combine %} + Re-review and combine + {% endif %} +

{% if decisions %} {% include "advice/decision_documents.html" with decisions=decisions case=case queue_id=queue_id %} From 9fde5639354a0796e966bb2aeac5627e7375199f Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Fri, 27 Sep 2024 13:56:51 +0100 Subject: [PATCH 5/6] Quick view to show the movement of queues --- .../templates/activities/notes-and-timeline.html | 16 ++++++++++++++++ caseworker/activities/views.py | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/caseworker/activities/templates/activities/notes-and-timeline.html b/caseworker/activities/templates/activities/notes-and-timeline.html index 47060d00c7..807fa1f0bb 100644 --- a/caseworker/activities/templates/activities/notes-and-timeline.html +++ b/caseworker/activities/templates/activities/notes-and-timeline.html @@ -55,6 +55,22 @@

Case history

+
+ + + Queue movement + + +
+ {% for item in queue_movements %} +

+ {{ item.created_at|to_datetime|date:"d F Y" }}: {{ item.text }} +

+                               + ↓ + {% endfor %} +
+
{% crispy form %} diff --git a/caseworker/activities/views.py b/caseworker/activities/views.py index 288f715c40..a031eb169b 100644 --- a/caseworker/activities/views.py +++ b/caseworker/activities/views.py @@ -93,6 +93,7 @@ def get_form_kwargs(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + activities = get_activity(self.request, self.case_id, activity_filters=self.request.GET) return { **context, "case": self.case, @@ -101,7 +102,12 @@ def get_context_data(self, **kwargs): "team_filters": self.get_team_filters(), "tabs": self.get_standard_application_tabs(), "current_tab": "cases:activities:notes-and-timeline", - "activities": get_activity(self.request, self.case_id, activity_filters=self.request.GET), + "activities": activities, + "queue_movements": [ + {**item, "text": item["text"][18:]} + for item in reversed(activities) + if item["verb"] == "move_case" + ], } def form_valid(self, form): From da00e6d0d105d6afc3af1c3edc883bd981c53fc0 Mon Sep 17 00:00:00 2001 From: Arun Siluvery Date: Mon, 30 Sep 2024 12:24:36 +0100 Subject: [PATCH 6/6] Only consider valid advice --- caseworker/advice/services.py | 13 +------------ core/builtins/custom_tags.py | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/caseworker/advice/services.py b/caseworker/advice/services.py index 6ebbd0e13a..c51fc20692 100644 --- a/caseworker/advice/services.py +++ b/caseworker/advice/services.py @@ -121,7 +121,7 @@ def filter_advice_by_type(all_advice, advice_types): def filter_advice_by_level(all_advice, advice_levels): - return [advice for advice in all_advice if advice["level"] in advice_levels] + return [advice for advice in all_advice if advice["level"] in advice_levels and advice["valid"] is True] def filter_advice_by_user(all_advice, caseworker): @@ -291,22 +291,11 @@ def order_by_party_type(all_advice): return ordered_advice -def group_advice_by_date(all_advice): - grouped = defaultdict(list) - for item in all_advice: - created = item['created_at'][:19] # TODO parse and extract date - grouped[created].append(item) - - return grouped - def get_consolidated_advice(advice, team_alias): level = "final" if team_alias == LICENSING_UNIT_TEAM else "team" team_advice = filter_advice_by_level(advice, [level]) consolidated_advice = filter_advice_by_team(team_advice, team_alias) - grouped_by_date = group_advice_by_date(consolidated_advice) - recent_date = sorted(grouped_by_date.keys())[-1] - consolidated_advice = grouped_by_date[recent_date] return order_by_party_type(consolidated_advice) diff --git a/core/builtins/custom_tags.py b/core/builtins/custom_tags.py index 20ebbec7a0..2b6f8dfba5 100644 --- a/core/builtins/custom_tags.py +++ b/core/builtins/custom_tags.py @@ -543,7 +543,7 @@ def values(dictionary): @register.filter() def filter_advice_by_level(advice, level): - return [advice for advice in advice if advice["level"] == level] + return [advice for advice in advice if advice["level"] == level and advice["valid"] == True] @register.filter()