Skip to content

Commit

Permalink
tss-2243 preliminary assessments (#854)
Browse files Browse the repository at this point in the history
Preliminary Assessment Frontend

---------

Co-authored-by: abarolo <asmundbekker@DBT000435.local>
Co-authored-by: asmund bekker <145478290+abarolo@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 2079d3d commit 5408e57
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 5 deletions.
6 changes: 6 additions & 0 deletions barriers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ class Statuses:
("investments", "Investments"),
)

PRELIMINARY_ASSESSMENT_CHOICES = Choices(
("1", "Over 10 million pounds"),
("2", "Less than 10 million pounds"),
("3", "Unable to assess"),
)

# Related barriers rag tags
RELATED_BARRIER_TAGS = {
"duplicate": {
Expand Down
1 change: 0 additions & 1 deletion barriers/forms/assessments/economic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def save(self):

class EconomicAssessmentRatingForm(DocumentMixin, forms.Form):
rating = forms.ChoiceField(
label="What is the initial economic assessment of this barrier?",
choices=[],
error_messages={
"required": "Select the initial economic assessment of this barrier"
Expand Down
43 changes: 43 additions & 0 deletions barriers/forms/assessments/preliminary_assessment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django import forms

from barriers.constants import PRELIMINARY_ASSESSMENT_CHOICES
from barriers.forms.mixins import APIFormMixin
from utils.api.client import MarketAccessAPIClient


class UpdatePreliminaryAssessmentForm(APIFormMixin, forms.Form):
preliminary_value = forms.ChoiceField(
label="Barrier value",
choices=PRELIMINARY_ASSESSMENT_CHOICES,
widget=forms.RadioSelect,
error_messages={
"required": "Select a value",
},
)

preliminary_value_details = forms.CharField(
widget=forms.Textarea,
label="Provide an explanation on how the value has been assessed",
error_messages={"required": "Enter details of the preliminary value"},
)

def __init__(self, preliminary_assessment=None, *args, **kwargs):
self.token = kwargs.pop("token")
self.barrier = kwargs.pop("barrier")
self.preliminary_assessment = preliminary_assessment
super().__init__(*args, **kwargs)

def save(self):
client = MarketAccessAPIClient(self.token)
if self.preliminary_assessment:
client.preliminary_assessment.patch_preliminary_assessment(
barrier_id=self.barrier.id,
value=self.cleaned_data["preliminary_value"],
details=self.cleaned_data["preliminary_value_details"],
)
else:
client.preliminary_assessment.create_preliminary_assessment(
barrier_id=self.barrier.id,
value=self.cleaned_data["preliminary_value"],
details=self.cleaned_data["preliminary_value_details"],
)
2 changes: 2 additions & 0 deletions barriers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .assessments import (
EconomicAssessment,
EconomicImpactAssessment,
PreliminaryAssessment,
ResolvabilityAssessment,
StrategicAssessment,
)
Expand Down Expand Up @@ -33,4 +34,5 @@
ActionPlan,
Stakeholder,
BarrierDownload,
PreliminaryAssessment,
]
13 changes: 13 additions & 0 deletions barriers/models/assessments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from barriers.constants import PRELIMINARY_ASSESSMENT_CHOICES
from utils.models import APIModel

from .documents import Document
Expand Down Expand Up @@ -45,3 +46,15 @@ class ResolvabilityAssessment(APIModel):

class StrategicAssessment(APIModel):
date_fields = ("archived_on", "created_on", "reviewed_on")


class PreliminaryAssessment(APIModel):
date_fields = "created_on"

@property
def get_value_display(self):
value = str(self.data.get("value", ""))
if value:
return PRELIMINARY_ASSESSMENT_CHOICES[value]
else:
return ""
6 changes: 5 additions & 1 deletion barriers/models/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
ActionPlanTaskHistoryItem,
)

from .assessments.economic import EconomicAssessmentHistoryItem
from .assessments.economic import (
EconomicAssessmentHistoryItem,
PreliminaryAssessmentHistoryItem,
)
from .assessments.economic_impact import EconomicImpactAssessmentHistoryItem
from .assessments.resolvability import ResolvabilityAssessmentHistoryItem
from .assessments.strategic import StrategicAssessmentHistoryItem
Expand Down Expand Up @@ -45,5 +48,6 @@ class HistoryItem(PolymorphicBase):
ProgressUpdateHistoryItem,
BarrierTopPrioritySummaryItem,
ProgrammeFundsHistoryItem,
PreliminaryAssessmentHistoryItem,
)
class_lookup = {}
21 changes: 21 additions & 0 deletions barriers/models/history/assessments/economic.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,24 @@ class EconomicAssessmentHistoryItem(PolymorphicBase):
)
default_subclass = GenericHistoryItem
class_lookup = {}


class PreliminaryAssessmentValueHistoryItem(BaseHistoryItem):
field = "value"
field_name = "Preliminary assessment value"


class PreliminaryAssessmentDetailsHistoryItem(BaseHistoryItem):
field = "details"
field_name = "Preliminary assessment details"


class PreliminaryAssessmentHistoryItem(PolymorphicBase):
model = "preliminary_assessment"
key = "field"
subclasses = (
PreliminaryAssessmentValueHistoryItem,
PreliminaryAssessmentDetailsHistoryItem,
)
default_subclass = GenericHistoryItem
class_lookup = {}
6 changes: 6 additions & 0 deletions barriers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
EconomicImpactAssessmentDetail,
)
from barriers.views.assessments.overview import AssessmentOverview
from barriers.views.assessments.preliminary_assessment import PreliminaryAssessmentValue
from barriers.views.assessments.resolvability import (
AddResolvabilityAssessment,
ArchiveResolvabilityAssessment,
Expand Down Expand Up @@ -331,6 +332,11 @@
BarrierEditCommercialValue.as_view(),
name="edit_commercial_value",
),
path(
"barriers/<uuid:barrier_id>/edit/preliminary-assessment/",
PreliminaryAssessmentValue.as_view(),
name="edit_preliminary_assessment",
),
path(
"barriers/<uuid:barrier_id>/edit/commodities/",
BarrierEditCommodities.as_view(),
Expand Down
1 change: 1 addition & 0 deletions barriers/views/assessments/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ def get_context_data(self, **kwargs):
assement_class += " visually-hidden"

context["strategic_ass"] = assement_class
context["preliminary_assessment"] = self.preliminary_assessment
return context
34 changes: 34 additions & 0 deletions barriers/views/assessments/preliminary_assessment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.urls import reverse
from django.views.generic import FormView

from barriers.forms.assessments.preliminary_assessment import (
UpdatePreliminaryAssessmentForm,
)
from barriers.views.mixins import APIBarrierFormViewMixin


class PreliminaryAssessmentValue(APIBarrierFormViewMixin, FormView):
template_name = "barriers/assessments/preliminary_assessment.html"
form_class = UpdatePreliminaryAssessmentForm

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["token"] = self.request.session.get("sso_token")
kwargs["barrier"] = self.barrier
kwargs["preliminary_assessment"] = self.preliminary_assessment
return kwargs

def get_initial(self):
if self.preliminary_assessment:
return {
"preliminary_value": self.preliminary_assessment.value,
"preliminary_value_details": self.preliminary_assessment.details,
}
else:
return

def get_success_url(self):
return reverse(
"barriers:assessment_detail",
kwargs={"barrier_id": self.kwargs.get("barrier_id")},
)
18 changes: 18 additions & 0 deletions barriers/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BarrierMixin:
_notes = None
_note = None
_action_plan = None
_preliminary_assessment = None

@property
def barrier(self):
Expand Down Expand Up @@ -51,6 +52,12 @@ def action_plan(self):
self._action_plan = self.get_action_plan()
return self._action_plan

@property
def preliminary_assessment(self):
if not self._preliminary_assessment:
self._preliminary_assessment = self.get_preliminary_assessment()
return self._preliminary_assessment

def get_barrier(self):
client = MarketAccessAPIClient(self.request.session.get("sso_token"))
barrier_id = self.kwargs.get("barrier_id")
Expand Down Expand Up @@ -97,6 +104,17 @@ def get_action_plan(self):
raise Http404()
raise

def get_preliminary_assessment(self):
client = MarketAccessAPIClient(self.request.session.get("sso_token"))
barrier_id = self.barrier.id
try:
return client.preliminary_assessment.get_preliminary_assessment(
barrier_id=barrier_id
)
except APIHttpException as e:
if e.status_code == HTTPStatus.NOT_FOUND:
return None


class PublicBarrierMixin:
_public_barrier = None
Expand Down
3 changes: 3 additions & 0 deletions core/frontend/src/css/pages/barrier/_assessment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
&:first-child {
margin-top: govuk-em( 32, 16 );
}
&.archived {
opacity: 0.5;
}
}

.assessment-item__heading {
Expand Down
11 changes: 11 additions & 0 deletions core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ActionPlanTaskResource,
BarriersResource,
NotesResource,
PreliminaryAssessmentResource,
PublicBarriersResource,
ReportsResource,
UserProfileResource,
Expand Down Expand Up @@ -485,3 +486,13 @@ def profile(self):
"overseas_regions": [],
}
)

@property
def preliminary_assessment(self):
return PreliminaryAssessmentResource.model(
{
"id": 1,
"value": "1",
"details": "test details",
}
)
28 changes: 26 additions & 2 deletions templates/barriers/assessments/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@
{% include 'barriers/partials/barrier_tabs.html' with active='assessment' %}

<div class="restrict-width">

<div class="assessment-item">
<h2 class="assessment-item__heading">Initial economic assessment</h2>
{% include "barriers/assessments/economic/partials/summary.html" %}
<h2 class="assessment-item__heading">Preliminary economic assessment</h2>
{% if preliminary_assessment %}
<p class="assessment-item__value"><strong>Preliminary value: {{ preliminary_assessment.get_value_display }}</p></strong>
<p class="assessment-item__value">Details:</p>
<p class="assessment-item__value">{{ preliminary_assessment.details|linebreaksbr }}</p>
{% if current_user|has_permission:"change_preliminaryassessment" %}
<a class="assessment-item__edit" href="{% url 'barriers:edit_preliminary_assessment' barrier.id %}">Edit</a>
{% endif %}
{% else %}
<div class="assessment-item-content">
{% if current_user|has_permission:"add_preliminaryassessment" %}
<p class="assessment-item-content__hint">No preliminary assessment</p>
<a class="assessment-item-content__link" href="{% url 'barriers:edit_preliminary_assessment' barrier.id %}">Add preliminary assessment</a>
{% else %}
<p class="assessment-item-content__hint">This barrier has not yet received a preliminary assessment. Analysts carry out preliminary assessments of all new market access barriers uploaded to DMAS.</p>
<p class="assessment-item-content__hint">Preliminary assessments are an estimate of whether a market access barrier is likely to be worth less or more than £10M in additional exports, or earnings on UK outward <strong>Foreign Direct Investment</strong> (FDI), over a 5-year period.</p>
{% endif %}
</div>
{% endif %}
</div>

<div class="assessment-item">
Expand Down Expand Up @@ -50,5 +68,11 @@ <h2 class="assessment-item__heading">Resolvability assessment</h2>
<h2 class="assessment-item__heading">Strategic assessment</h2>
{% include "barriers/assessments/strategic/partials/summary.html" %}
</div>

<div class="assessment-item archived">
<h2 class="assessment-item__heading">Initial economic assessment - archived</h2>
{% include "barriers/assessments/economic/partials/summary.html" %}
</div>

</div>
{% endblock %}
24 changes: 24 additions & 0 deletions templates/barriers/assessments/preliminary_assessment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "barriers/edit/base.html" %}

{% block page_title %}{{ block.super }} - Commercial value estimate{% endblock %}

{% block back_link %}
<a href="{% url 'barriers:assessment_detail' barrier.id %}" class="govuk-back-link ma-back-link">Back</a>
{% endblock %}

{% block page_content %}

{% include 'partials/heading.html' with text='Preliminary economic assessment' %}

<form action="" method="POST" class="restrict-width">

{% csrf_token %}

{% include "partials/forms/radio_input.html" with field=form.preliminary_value %}
{% include "partials/forms/textarea.html" with field=form.preliminary_value_details %}

<button class="govuk-button" data-module="govuk-button">Save and return</button>
<a href="{% url 'barriers:assessment_detail' barrier.id %}" class="form-cancel">Cancel</a>
</form>

{% endblock %}
5 changes: 4 additions & 1 deletion tests/assessments/test_economic_assessment_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def test_delete_new_economic_assessment_document_ajax(self):
]
assert session_document_ids == document_ids[1:]

def test_strategic_assessments(self):
@patch(
"utils.api.resources.PreliminaryAssessmentResource.get_preliminary_assessment"
)
def test_strategic_assessments(self, mock_get_preliminary_assessment):
url = reverse(
"barriers:assessment_detail",
kwargs={
Expand Down
Loading

0 comments on commit 5408e57

Please sign in to comment.