Skip to content

Commit

Permalink
Merge branch 'master' into TP2000-1064--fix-quota-origins-create-meas…
Browse files Browse the repository at this point in the history
…ure-journey
  • Loading branch information
dalecannon committed Sep 26, 2023
2 parents 37e2cf6 + 0378761 commit 6c13a6f
Show file tree
Hide file tree
Showing 20 changed files with 735 additions and 80 deletions.
4 changes: 3 additions & 1 deletion common/static/common/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { initAll } from 'govuk-frontend';
import initCheckboxes from './checkboxes';
import initConditionalMeasureConditions from './conditionalMeasureConditions';
import initFilterDisabledToggleForComCode from './conditionalDisablingFilters'
import initOpenCloseAccordionSection from './openCloseAccordion';
showHideCheckboxes();
// Initialise accessible-autocomplete components without a `name` attr in order
// to avoid the "dummy" autocomplete field being submitted as part of the form
Expand All @@ -24,4 +25,5 @@ initAll();
initCheckboxes();
initConditionalMeasureConditions();
initAutocompleteProgressiveEnhancement();
initFilterDisabledToggleForComCode();
initFilterDisabledToggleForComCode();
initOpenCloseAccordionSection();
16 changes: 16 additions & 0 deletions common/static/common/js/openCloseAccordion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// TODO: adjust the pathname filter to account for all objects search/filter pages
const initOpenCloseAccordionSection = () => {
document.addEventListener('DOMContentLoaded', function() {

let expandedSection = document.getElementById('accordion-open-close-section')
let pathname = window.location.pathname
if(expandedSection){
if (!pathname.includes('search')){
expandedSection.classList.remove('govuk-accordion__section--expanded');
}
}
}
)
}

export default initOpenCloseAccordionSection;
9 changes: 9 additions & 0 deletions common/static/common/scss/_accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
.govuk-accordion__section-content > :last-child {
@extend .govuk-\!-margin-bottom-6;
}

.black-label--no-button {
.govuk-accordion__section-button {
color: black !important;
}
.govuk-accordion__icon {
display: none !important;
}
}
24 changes: 24 additions & 0 deletions common/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,20 @@ class Meta:
model = "notifications.EnvelopeReadyForProcessingNotification"


class EnvelopeAcceptedNotificationFactory(factory.django.DjangoModelFactory):
"""This is a factory for an envelope that has been accepted notification."""

class Meta:
model = "notifications.EnvelopeAcceptedNotification"


class EnvelopeRejectedNotificationFactory(factory.django.DjangoModelFactory):
"""This is a factory for an envelope that has been rejected notification."""

class Meta:
model = "notifications.EnvelopeRejectedNotification"


class CrownDependenciesEnvelopeSuccessNotificationFactory(
factory.django.DjangoModelFactory,
):
Expand All @@ -1457,3 +1471,13 @@ class CrownDependenciesEnvelopeSuccessNotificationFactory(

class Meta:
model = "notifications.CrownDependenciesEnvelopeSuccessNotification"


class CrownDependenciesEnvelopeFailedNotificationFactory(
factory.django.DjangoModelFactory,
):
"""This is a factory for a crown dependencies envelope failed
notification."""

class Meta:
model = "notifications.CrownDependenciesEnvelopeFailedNotification"
38 changes: 38 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,44 @@ def factory_method(**kwargs):
return factory_method


@pytest.fixture(scope="function")
def failed_envelope_factory(
published_envelope_factory,
mocked_send_emails_apply_async,
):
"""
Factory fixture to create a successfully processed envelope and update the
packaged_workbasket envelope field.
params:
packaged_workbasket defaults to packaged_workbasket_factory() which creates a
Packaged workbasket with a Workbasket in the state QUEUED
with an approved transaction and tracked models
"""

def factory_method(**kwargs):
envelope = published_envelope_factory(**kwargs)

packaged_workbasket = PackagedWorkBasket.objects.get(
envelope=envelope,
)

packaged_workbasket.begin_processing()
assert packaged_workbasket.position == 0
assert (
packaged_workbasket.pk
== PackagedWorkBasket.objects.currently_processing().pk
)
factories.LoadingReportFactory.create(packaged_workbasket=packaged_workbasket)

packaged_workbasket.processing_failed()
packaged_workbasket.save()
assert packaged_workbasket.position == 0
return envelope

return factory_method


@pytest.fixture(scope="function")
def crown_dependencies_envelope_factory(successful_envelope_factory):
"""
Expand Down
9 changes: 9 additions & 0 deletions measures/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ def show_step_duties(wizard):
return MeasureEditSteps.DUTIES.value in cleaned_data.get("fields_to_edit")


def show_step_geographical_area_exclusions(wizard):
cleaned_data = wizard.get_cleaned_data_for_step(START)
if cleaned_data:
return MeasureEditSteps.GEOGRAPHICAL_AREA_EXCLUSIONS.value in cleaned_data.get(
"fields_to_edit",
)


measure_edit_condition_dict = {
MeasureEditSteps.START_DATE: show_step_start_date,
MeasureEditSteps.END_DATE: show_step_end_date,
MeasureEditSteps.QUOTA_ORDER_NUMBER: show_step_quota_order_number,
MeasureEditSteps.REGULATION: show_step_regulation,
MeasureEditSteps.DUTIES: show_step_duties,
MeasureEditSteps.GEOGRAPHICAL_AREA_EXCLUSIONS: show_step_geographical_area_exclusions,
}
4 changes: 4 additions & 0 deletions measures/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class MeasureEditSteps(models.TextChoices):
QUOTA_ORDER_NUMBER = ("quota_order_number", "Quota order number")
REGULATION = ("regulation", "Regulation")
DUTIES = ("duties", "Duties")
GEOGRAPHICAL_AREA_EXCLUSIONS = (
"geographical_area_exclusions",
"Geographical area exclusions",
)
53 changes: 50 additions & 3 deletions measures/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,17 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Accordion(
AccordionSection(
"Select one or more options to search",
"Search and filter",
HTML(
'<h3 class="govuk-body">Select one or more options to search</h3>',
),
Div(
Div(
Div(
"goods_nomenclature",
Field.text("sid", field_width=Fluid.TWO_THIRDS),
"regulation",
"footnote",
css_class="govuk-grid-column-one-third",
),
Div(
Expand Down Expand Up @@ -813,6 +817,9 @@ def __init__(self, *args, **kwargs):
),
Div(
"modc",
HTML(
"<h3 class='govuk-body'>To use the 'Include inherited measures' filter, enter a valid commodity code in the 'Select commodity code' filter above</h3>",
),
css_class="govuk-grid-column-full form-group-margin-bottom-2",
),
css_class="govuk-grid-row govuk-!-margin-top-6",
Expand Down Expand Up @@ -840,7 +847,7 @@ def __init__(self, *args, **kwargs):
"end_date",
css_class="govuk-grid-column-one-half form-group-margin-bottom-2",
),
css_class="govuk-grid-row govuk-!-padding-top-6 filter-layout__filters",
css_class="govuk-grid-row govuk-!-padding-top-6",
),
Div(
Div(
Expand All @@ -857,7 +864,8 @@ def __init__(self, *args, **kwargs):
css_class="govuk-grid-row govuk-!-padding-top-3",
),
),
css_class="govuk-grid-row govuk-!-padding-3",
css_class="govuk-grid-row govuk-!-padding-3 black-label--no-button govuk-accordion__section--expanded",
id="accordion-open-close-section",
),
),
)
Expand Down Expand Up @@ -1636,3 +1644,42 @@ def clean(self):
validate_duties(duties, measure.valid_between.lower)

return cleaned_data


class MeasureGeographicalAreaExclusionsForm(forms.Form):
excluded_area = forms.ModelChoiceField(
label="",
queryset=GeographicalArea.objects.all(),
help_text="Select a geographical area to be excluded",
required=False,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["excluded_area"].queryset = (
GeographicalArea.objects.current()
.with_latest_description()
.as_at_today_and_beyond()
.order_by("description")
)

self.fields[
"excluded_area"
].label_from_instance = lambda obj: f"{obj.area_id} - {obj.description}"

self.helper = FormHelper(self)
self.helper.form_tag = False
self.helper.legend_size = Size.SMALL
self.helper.layout = Layout(
Fieldset(
"excluded_area",
),
)


class MeasureGeographicalAreaExclusionsFormSet(FormSet):
"""Allows editing the geographical area exclusions of multiple measures in
`MeasureEditWizard`."""

form = MeasureGeographicalAreaExclusionsForm
58 changes: 58 additions & 0 deletions measures/jinja2/measures/edit-multiple-formset.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% extends "measures/edit-wizard-step.jinja" %}

{% from "components/fieldset/macro.njk" import govukFieldset %}
{% from "components/error-summary/macro.njk" import govukErrorSummary %}

{% block form %}
{% set formset = form %}
{{ crispy(formset.management_form, no_form_tags) }}

{% if formset.non_form_errors() %}
{% set error_list = [] %}
{% for error in formset.non_form_errors() %}
{{ error_list.append({
"html": '<p class="govuk-error-message">' ~ error ~ '</p>',
}) or "" }}
{% endfor %}

{{ govukErrorSummary({
"titleText": "There is a problem",
"errorList": error_list
}) }}
{% endif %}

{% for form in formset %}
{% if form.non_field_errors() %}
{% set error_list = [] %}
{% for error in form.non_field_errors() %}
{{ error_list.append({
"html": '<p class="govuk-error-message">' ~ error ~ '</p>',
}) or "" }}
{% endfor %}

{{ govukErrorSummary({
"titleText": "There is a problem",
"errorList": error_list
}) }}
{% endif %}
{{ crispy(form) }}
{% endfor %}

{% if formset.data[formset.prefix ~ "-ADD"] %}
{{ crispy(formset.empty_form)|replace("__prefix__", formset.forms|length)|safe }}
{% endif %}

<div class="govuk-button-group">
{{ govukButton({"text": "Save"}) }}

{% if formset.total_form_count() + 1 < formset.max_num %}
{{ govukButton({
"text": "Add another",
"attributes": {"id": "add-new"},
"classes": "govuk-button--secondary",
"value": "1",
"name": formset.prefix ~ "-ADD",
}) }}
{% endif %}
</div>
{% endblock %}
4 changes: 0 additions & 4 deletions measures/jinja2/measures/list.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

<div class="full-width-search">
<div class="govuk-!-margin-bottom-5">
<h2 class="govuk-heading-m govuk-!-margin-bottom-5">Search and filter</h2>
<p class="govuk-body">
Select one or more options to search
</p>
<form method="get" action="{{ url(form_url) }}">
{{ crispy(filter.form) }}
</form>
Expand Down
1 change: 0 additions & 1 deletion measures/jinja2/measures/search.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<div class="filter-layout full-width-search">
<div class="govuk-!-margin-bottom-5 govuk-grid-column-full">
<h2 class="govuk-heading-m ">Search and filter</h2>
<form method="get" action="{{ url(form_url) }}">
{{ crispy(filter.form) }}
</form>
Expand Down
26 changes: 26 additions & 0 deletions measures/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,3 +1590,29 @@ def test_measure_review_form_validates_components_applicability_exclusivity(
"A duty cannot be specified on both commodities and conditions"
in form.errors["__all__"]
)


def test_measure_geographical_area_exclusions_form_valid_choice():
"""Tests that `MeasureGeographicalAreaExclusionsForm` is valid when an
available geographical area is selected."""
geo_area = factories.GeographicalAreaFactory.create()
data = {
"excluded_area": geo_area.pk,
}
with override_current_transaction(geo_area.transaction):
form = forms.MeasureGeographicalAreaExclusionsForm(data)
assert form.is_valid()
assert form.cleaned_data["excluded_area"] == geo_area


def test_measure_geographical_area_exclusions_form_invalid_choice():
"""Tests that `MeasureGeographicalAreaExclusionsForm` raises an raises an
invalid choice error when an unavailable geographical area is selected."""
data = {
"excluded_area": "geo_area",
}
form = forms.MeasureGeographicalAreaExclusionsForm(data)
assert not form.is_valid()
assert form.errors["excluded_area"] == [
"Select a valid choice. That choice is not one of the available choices.",
]
Loading

0 comments on commit 6c13a6f

Please sign in to comment.