From 30cf46bab8642cc887eafa4253afd0aac2e95ecd Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Wed, 20 Sep 2023 15:27:21 +0100 Subject: [PATCH 1/3] Use active origins when setting cleaned_data --- measures/forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/measures/forms.py b/measures/forms.py index 3b321d851..c3ea7bf68 100644 --- a/measures/forms.py +++ b/measures/forms.py @@ -1132,7 +1132,9 @@ def clean(self): # Use quota order number origins and exclusions to set cleaned_data if self.order_number: - origins = self.order_number.quotaordernumberorigin_set.current() + origins = ( + self.order_number.quotaordernumberorigin_set.current().as_at_today_and_beyond() + ) cleaned_data["geo_areas_and_exclusions"] = [ { "geo_area": origin.geographical_area, From c2ab1f00edaedd905f33cd32daba1d4a496aaf3c Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Wed, 20 Sep 2023 15:28:00 +0100 Subject: [PATCH 2/3] Fix page heading --- .../measures/create-geo-areas-formset.jinja | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/measures/jinja2/measures/create-geo-areas-formset.jinja b/measures/jinja2/measures/create-geo-areas-formset.jinja index 5bbd1786c..99c5a33d6 100644 --- a/measures/jinja2/measures/create-geo-areas-formset.jinja +++ b/measures/jinja2/measures/create-geo-areas-formset.jinja @@ -3,12 +3,22 @@ {% from "components/summary-list/macro.njk" import govukSummaryList %} {% block breadcrumb %} - {% if request.path != "/" %} - {{ breadcrumbs(request, [{"text": "Review the geographical areas"}]) }} + {% if order_number %} + {% if request.path != "/" %} + {{ breadcrumbs(request, [{"text": "Review the geographical areas"}]) }} + {% endif %} + {% else %} + {{ super() }} {% endif %} - {% endblock %} +{% endblock %} -{% block page_title_heading %}Review the geographical areas{% endblock %} +{% block page_title_heading %} + {% if order_number %} + Review the geographical areas + {% else %} + {{ super() }} + {% endif %} +{% endblock %} {% block form %} {% if order_number and origins_and_exclusions %} From e59b6eb90ba96b72cb128d401ff32702870e41dc Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Wed, 20 Sep 2023 16:09:54 +0100 Subject: [PATCH 3/3] Update test --- measures/tests/test_forms.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/measures/tests/test_forms.py b/measures/tests/test_forms.py index 09c9f2818..dbf92f767 100644 --- a/measures/tests/test_forms.py +++ b/measures/tests/test_forms.py @@ -471,18 +471,26 @@ def test_measure_forms_geo_area_invalid_data_error_messages(data, error, erga_om assert error in form.errors["geo_area"] -def test_measure_geographical_area_form_quota_order_number(): +def test_measure_geographical_area_form_quota_order_number(date_ranges): """Tests that `MeasureGeographicalAreaForm` sets `cleaned_data` with geographical data from quota order number if one is passed in `kwargs`.""" - origin_1 = factories.QuotaOrderNumberOriginFactory.create() - origin_2 = factories.QuotaOrderNumberOriginFactory.create( - order_number=origin_1.order_number, + old_origin = factories.QuotaOrderNumberOriginFactory.create( + valid_between=date_ranges.earlier, ) - origin_1_exclusions = factories.QuotaOrderNumberOriginExclusionFactory.create_batch( - 2, - origin=origin_1, + order_number = old_origin.order_number + + new_origin_1 = factories.QuotaOrderNumberOriginFactory.create( + order_number=order_number, + ) + new_origin_2 = factories.QuotaOrderNumberOriginFactory.create( + order_number=order_number, + ) + new_origin_1_exclusions = ( + factories.QuotaOrderNumberOriginExclusionFactory.create_batch( + 2, + origin=new_origin_1, + ) ) - order_number = origin_1.order_number with override_current_transaction(Transaction.objects.last()): form = forms.MeasureGeographicalAreaForm( @@ -495,11 +503,11 @@ def test_measure_geographical_area_form_quota_order_number(): expected_cleaned_data = [ { - "geo_area": origin_1.geographical_area, - "exclusions": list(origin_1.excluded_areas.all()), + "geo_area": new_origin_1.geographical_area, + "exclusions": list(new_origin_1.excluded_areas.all()), }, { - "geo_area": origin_2.geographical_area, + "geo_area": new_origin_2.geographical_area, "exclusions": [], }, ]