diff --git a/common/jinja2/layouts/detail.jinja b/common/jinja2/layouts/detail.jinja index 6356a88a6..d0a607a09 100644 --- a/common/jinja2/layouts/detail.jinja +++ b/common/jinja2/layouts/detail.jinja @@ -12,6 +12,13 @@ {% block content %}
+ {% if title_caption %} + {% block page_subtitle%} + + {{ title_caption }} + + {% endblock %} + {% endif %}

{{ page_title }}

diff --git a/quotas/jinja2/includes/quotas/actions.jinja b/quotas/jinja2/includes/quotas/actions.jinja index 393fe213c..88e8ee8c0 100644 --- a/quotas/jinja2/includes/quotas/actions.jinja +++ b/quotas/jinja2/includes/quotas/actions.jinja @@ -2,15 +2,7 @@ diff --git a/quotas/jinja2/includes/quotas/tabs/blocking_periods.jinja b/quotas/jinja2/includes/quotas/tabs/blocking_periods.jinja index 542ebaa28..e65adc223 100644 --- a/quotas/jinja2/includes/quotas/tabs/blocking_periods.jinja +++ b/quotas/jinja2/includes/quotas/tabs/blocking_periods.jinja @@ -1,6 +1,6 @@
-

Details

+

Blocking periods

{% if blocking_period %} {{ govukSummaryList({ "rows": [ diff --git a/quotas/jinja2/includes/quotas/tabs/core_data.jinja b/quotas/jinja2/includes/quotas/tabs/core_data.jinja index d5209de73..f88e22ddf 100644 --- a/quotas/jinja2/includes/quotas/tabs/core_data.jinja +++ b/quotas/jinja2/includes/quotas/tabs/core_data.jinja @@ -8,11 +8,11 @@
-

Details

+

Order number details

{{ govukSummaryList({ "rows": [ { - "key": {"text": "Order Number"}, + "key": {"text": "Order number"}, "value": {"text": object.order_number}, "actions": {"items": []} }, diff --git a/quotas/jinja2/includes/quotas/tabs/definition_details.jinja b/quotas/jinja2/includes/quotas/tabs/definition_details.jinja index 628036b57..1cc10892a 100644 --- a/quotas/jinja2/includes/quotas/tabs/definition_details.jinja +++ b/quotas/jinja2/includes/quotas/tabs/definition_details.jinja @@ -1,6 +1,6 @@
-

Details

+

Definition details

{% if current_definition %} {{ govukSummaryList({ "rows": [ diff --git a/quotas/jinja2/includes/quotas/tabs/measures.jinja b/quotas/jinja2/includes/quotas/tabs/measures.jinja index 7798c56df..761e6a562 100644 --- a/quotas/jinja2/includes/quotas/tabs/measures.jinja +++ b/quotas/jinja2/includes/quotas/tabs/measures.jinja @@ -24,7 +24,7 @@
-

Details

+

Measures

{% if measures %}

Showing currently active measures.

{{ govukTable({ diff --git a/quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja b/quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja index a03d4147e..f8514ccba 100644 --- a/quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja +++ b/quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja @@ -1,33 +1,69 @@ {% set table_rows = [] %} -{% for quota_association in quota_associations %} +{% for object in sub_quota_associations %} {% set sub_quota_link %} - {{ quota_association.sub_quota.order_number }} + href="{{ url('quota-ui-detail', args=[object.sub_quota.order_number.sid]) }}"> + {{ object.sub_quota.order_number }} {% endset %} + {% set actions_html %} + Edit +
+ Delete + {% endset %} {{ table_rows.append([ {"html": sub_quota_link}, - {"html": quota_association.sub_quota_relation_type}, - {"text": quota_association.coefficient}, + {"html": object.get_sub_quota_relation_type_display()}, + {"text": object.coefficient}, + {"text": actions_html } + ]) or "" }} +{% endfor %} + +{% for object in main_quota_associations %} + {% set main_quota_link %} + + {{ object.main_quota.order_number }} + + {% endset %} + {% set actions_html %} + Edit +
+ Delete + {% endset %} + + {{ table_rows.append([ + {"html": main_quota_link}, + {"html": object.get_sub_quota_relation_type_display()}, + {"text": object.coefficient}, + {"text": actions_html } ]) or "" }} {% endfor %}
-

Details

- {% if quota_associations %} - {{ govukTable({ - "head": [ - {"text": "Sub-quota order number"}, - {"text": "Relation type"}, +

Quota associations

+ {% if sub_quota_associations or main_quota_associations %} + {% if main_quota_associations %} +

Main quota

+ {% elif sub_quota_associations %} +

Sub-quotas

+ {% endif %} + {{ + govukTable({ + "head": [ + {"text": "Order number"}, + {"text": "Relationship type"}, {"text": "Co-efficient"}, - ], - "rows": table_rows - }) }} - {% else %} -

No active sub-quotas.

- {% endif %} + {"text": "Actions"} + ], + "rows": table_rows + }) + }} + {% else %} +

No active main or sub-quotas.

+ {% endif %} +
{% include "includes/quotas/actions.jinja"%}
diff --git a/quotas/jinja2/includes/quotas/tabs/suspension_periods.jinja b/quotas/jinja2/includes/quotas/tabs/suspension_periods.jinja index 960fc4e3f..722db386e 100644 --- a/quotas/jinja2/includes/quotas/tabs/suspension_periods.jinja +++ b/quotas/jinja2/includes/quotas/tabs/suspension_periods.jinja @@ -1,6 +1,6 @@
-

Details

+

Suspension periods

{% if suspension_period %} {{ govukSummaryList({ "rows": [ diff --git a/quotas/jinja2/quota-definitions/sub-quota-definitions-updates.jinja b/quotas/jinja2/quota-definitions/sub-quota-definitions-updates.jinja index 8d6974575..303aba2f4 100644 --- a/quotas/jinja2/quota-definitions/sub-quota-definitions-updates.jinja +++ b/quotas/jinja2/quota-definitions/sub-quota-definitions-updates.jinja @@ -3,9 +3,10 @@ {% from "components/table/macro.njk" import govukTable %} -{% set page_title = "Update sub-quota definition and association" %} +{% set page_title = "Edit sub-quota definition and association" %} {% block content %} +

{{ page_title }}

Main quota definition details

{% set main_definition = view.get_main_definition() %} {% set table_rows = [] %} diff --git a/quotas/jinja2/quotas/definitions.jinja b/quotas/jinja2/quotas/definitions.jinja index 7fdf121a9..614da2ec4 100644 --- a/quotas/jinja2/quotas/definitions.jinja +++ b/quotas/jinja2/quotas/definitions.jinja @@ -10,6 +10,12 @@ {% set page_title = "Quota ID: " ~ quota.order_number ~ " - Data" %} {% set find_edit_url = url("quota-ui-list") %} +{% if sub_quotas %} + {% set page_subtitle = "Main quota" %} +{% elif main_quotas %} + {% set page_subtitle = "Sub-quota" %} +{% endif %} + {% set links = [ { "text": "Quota definition periods", @@ -17,9 +23,9 @@ "selected": quota_type == None }, { - "text": "Sub-quotas", - "href": url('quota_definition-ui-list-filter', kwargs={"sid": quota.sid, "quota_type": "sub_quotas"}), - "selected": quota_type == "sub_quotas", + "text": "Quota associations", + "href": url('quota_definition-ui-list-filter', kwargs={"sid": quota.sid, "quota_type": "quota_associations"}), + "selected": quota_type == "quota_associations", }, { "text": "Blocking periods", @@ -43,9 +49,16 @@ {% endblock %} {% block content %} - +{% if page_subtitle %} + + {% block page_subtitle %} + {{ page_subtitle }} + {% endblock %} + +{% endif %}

{{ page_title }}

+ {{ fake_tabs(links) }}
{% set base_url = url('quota_definition-ui-list', args=[quota.sid] ) %} @@ -54,7 +67,7 @@ {% include "quotas/tables/blocking_periods.jinja" %} {% elif quota_type == "suspension_periods" %} {% include "quotas/tables/suspension_periods.jinja" %} - {% elif quota_type == "sub_quotas" %} + {% elif quota_type == "quota_associations" %} {% include "quotas/tables/sub_quotas.jinja" %} {% else %} {% include "quotas/tables/definitions.jinja" %} diff --git a/quotas/jinja2/quotas/detail.jinja b/quotas/jinja2/quotas/detail.jinja index 77d02fa2d..a3f18e522 100644 --- a/quotas/jinja2/quotas/detail.jinja +++ b/quotas/jinja2/quotas/detail.jinja @@ -2,9 +2,15 @@ {% from "components/summary-list/macro.njk" import govukSummaryList %} {% from "components/table/macro.njk" import govukTable %} -{% set page_title = "Quota ID: " ~ object.order_number %} +{% set page_title = "Quota order number: " ~ object.order_number %} {% set find_edit_url = url("quota-ui-list") %} +{% if sub_quota_associations %} + {% set title_caption = "Main quota" %} +{% elif main_quota_associations %} + {% set title_caption = "Sub-quota" %} +{% endif %} + {% set core_data_tab_html %}{% include "includes/quotas/tabs/core_data.jinja" %}{% endset %} {% set definition_details_html %}{% include "includes/quotas/tabs/definition_details.jinja" %}{% endset %} {% set sub_quotas_html %}{% include "includes/quotas/tabs/sub_quotas.jinja" %}{% endset %} @@ -30,8 +36,8 @@ } }, { - "label": "Sub-quotas", - "id": "sub-quotas", + "label": "Quota associations", + "id": "quotas-associations", "panel": { "html": sub_quotas_html } diff --git a/quotas/jinja2/quotas/tables/definitions.jinja b/quotas/jinja2/quotas/tables/definitions.jinja index 27105d196..494a25dca 100644 --- a/quotas/jinja2/quotas/tables/definitions.jinja +++ b/quotas/jinja2/quotas/tables/definitions.jinja @@ -65,7 +65,7 @@ {% endfor %} {% set sid %} - {{ create_sortable_anchor(request, "sid", "Quota definition sid", base_url) }} + {{ create_sortable_anchor(request, "sid", "Quota definition SID", base_url) }} {% endset %} {% set start_date %} diff --git a/quotas/jinja2/quotas/tables/sub_quotas.jinja b/quotas/jinja2/quotas/tables/sub_quotas.jinja index 430089fa7..acc8b0701 100644 --- a/quotas/jinja2/quotas/tables/sub_quotas.jinja +++ b/quotas/jinja2/quotas/tables/sub_quotas.jinja @@ -1,8 +1,8 @@ -

Sub-quotas

- +

Quota associations

{% set table_rows = [] %} {% if sub_quotas %} +

Sub-quotas

{% for object in sub_quotas %} {% set definition_link -%} {{ object.sub_quota.sid }} @@ -11,9 +11,9 @@ {{ object.sub_quota.order_number.order_number }} {% endset %} {% set actions_html %} - Edit association + Edit
- Delete association + Delete {% endset %} {{ table_rows.append([ @@ -30,7 +30,43 @@ {{ govukTable({ "head": [ {"text": "Quota definition SID"}, - {"text": "Sub-quota order number"}, + {"text": "Order number"}, + {"text": "Start date"}, + {"text": "End date"}, + {"text": "Relationship type"}, + {"text": "Coefficient"}, + {"text": "Actions"}, + ], + "rows": table_rows + }) }} +{% elif main_quotas %} +

Main quotas

+ {% for object in main_quotas %} + {% set definition_link -%} + {{ object.main_quota.sid }} + {% endset %} + {% set main_quota_link -%} + {{ object.main_quota.order_number.order_number }} + {% endset %} + {% set actions_html %} + Edit +
+ Delete + {% endset %} + {{ table_rows.append([ + {"text": definition_link }, + {"text": main_quota_link }, + {"text": "{:%d %b %Y}".format(object.main_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.lower) }, + {"text": "{:%d %b %Y}".format(object.main_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.upper) if object.main_quota.valid_between.upper else "-"}, + {"text": object.get_sub_quota_relation_type_display() }, + {"text": object.coefficient }, + {"text": actions_html }, + ]) or "" }} + {% endfor %} + {{ govukTable({ + "head": [ + {"text": "Quota definition SID"}, + {"text": "Order number"}, {"text": "Start date"}, {"text": "End date"}, {"text": "Relationship type"}, @@ -40,5 +76,5 @@ "rows": table_rows }) }} {% else %} -

There are no sub-quotas for this quota order number.

+

There are no main or sub-quotas for this quota order number.

{% endif %} \ No newline at end of file diff --git a/quotas/tests/test_views.py b/quotas/tests/test_views.py index eb960c1a5..ca366c957 100644 --- a/quotas/tests/test_views.py +++ b/quotas/tests/test_views.py @@ -680,6 +680,7 @@ def test_quota_detail_sub_quota_tab( valid_user_client, date_ranges, mock_quota_api_no_data, + session_request_with_workbasket, ): quota_order_number = factories.QuotaOrderNumberFactory() current_definition = factories.QuotaDefinitionFactory.create( @@ -2010,7 +2011,7 @@ def test_quota_definition_view(client_with_current_workbasket): response = client_with_current_workbasket.get( reverse( "quota_definition-ui-list-filter", - kwargs={"sid": main_quota.sid, "quota_type": "sub_quotas"}, + kwargs={"sid": main_quota.sid, "quota_type": "quota_associations"}, ), ) assert response.status_code == 200 diff --git a/quotas/views.py b/quotas/views.py index af6bf09e3..d373a8a3f 100644 --- a/quotas/views.py +++ b/quotas/views.py @@ -240,12 +240,14 @@ def get_context_data(self, *args, **kwargs): f"{URLs.BASE_URL.value}quota_search?order_number={self.object.order_number}" ) - context[ - "quota_associations" - ] = QuotaAssociation.objects.latest_approved().filter( + context["sub_quota_associations"] = QuotaAssociation.objects.current().filter( main_quota=current_definition, ) + context["main_quota_associations"] = QuotaAssociation.objects.current().filter( + sub_quota=current_definition, + ) + context["blocking_period"] = ( QuotaBlocking.objects.filter(quota_definition=current_definition) .as_at_and_beyond(date.today()) @@ -314,6 +316,13 @@ def sub_quotas(self): .order_by("sub_quota__sid") ) + @property + def main_quotas(self): + main_quotas = QuotaAssociation.objects.current().filter( + sub_quota__order_number=self.quota, + ) + return main_quotas + @cached_property def quota_data(self): if not self.kwargs.get("quota_type"): @@ -332,6 +341,7 @@ def get_context_data(self, *args, **kwargs): blocking_periods=self.blocking_periods, suspension_periods=self.suspension_periods, sub_quotas=self.sub_quotas, + main_quotas=self.main_quotas, *args, **kwargs, )