Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TP2000-1500 Update find commodity code view #1299

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions commodities/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from commodities.models.orm import GoodsNomenclature
from common.filters import ActiveStateMixin
from common.filters import CurrentWorkBasketMixin
from common.filters import EndDateMixin
from common.filters import TamatoFilter
from common.filters import TamatoFilterBackend
from common.validators import AlphanumericValidator
Expand All @@ -33,9 +34,14 @@ def search_queryset(self, queryset, search_term):
return super().search_queryset(queryset, search_term)


class CommodityFilter(ActiveStateMixin, TamatoFilter, CurrentWorkBasketMixin):
class CommodityFilter(
ActiveStateMixin,
TamatoFilter,
CurrentWorkBasketMixin,
EndDateMixin,
):
item_id = CharFilter(
label="Code",
label="Commodity code",
widget=forms.TextInput(),
lookup_expr="startswith",
validators=[NumericValidator],
Expand Down
19 changes: 16 additions & 3 deletions commodities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,28 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Field.text("item_id", label_size=Size.SMALL),
Field.text("descriptions__description", label_size=Size.SMALL),
Field.text("active_state", label_size=Size.SMALL),
Field.checkboxes(
"active_state",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("with_footnotes", label_size=Size.SMALL),
legend="Footnotes",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("with_end_date", label_size=Size.SMALL),
legend="End date",
legend_size=Size.SMALL,
),
Fieldset(
Field.text("current_work_basket", label_size=Size.SMALL),
legend="Workbasket",
legend_size=Size.SMALL,
),
Field.text("current_work_basket", label_size=Size.SMALL),
Button(
"submit",
"Search and Filter",
"Search and filter",
),
HTML(
f'<a class="govuk-button govuk-button--secondary" href="{self.clear_url}"> Clear </a>',
Expand Down
4 changes: 4 additions & 0 deletions commodities/jinja2/includes/commodities/table.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
{"text": commodity.suffix},
{"text": commodity.get_indent_as_at(today).indent},
{"text": commodity.get_description().description},
{"text": "{:%d %b %Y}".format(commodity.valid_between.lower)},
{"text": "{:%d %b %Y}".format(commodity.valid_between.upper) if commodity.valid_between.upper else "-"},
{"text": commodity_footnotes},
]) or "" }}
{% endfor %}
Expand All @@ -24,6 +26,8 @@
{"text": "Suffix"},
{"text": "Indent"},
{"text": "Commodity description"},
{"text": "Start date"},
{"text": "End date"},
{"text": "Footnotes"},

],
Expand Down
16 changes: 16 additions & 0 deletions commodities/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

def test_commodity_list_displays_commodity_suffix_indent_and_description(
valid_user_client,
date_ranges,
):
"""Test that a list of commodity codes with links and their suffixes,
indents and descriptions are displayed on the list view template."""
Expand All @@ -37,6 +38,9 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
description="A second commodity code description",
).described_goods_nomenclature

commodity2.valid_between = date_ranges.normal
commodity2.save(force_write=True)

url = reverse("commodity-ui-list")
response = valid_user_client.get(url)
page = BeautifulSoup(
Expand All @@ -51,6 +55,10 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
text=commodity1.get_indent_as_at(datetime.date.today()).indent,
)
assert page.find("tbody").find("td", text="A commodity code description")
assert page.find("tbody").find(
"td",
text=f"{commodity1.valid_between.lower:%d %b %Y}",
)

assert page.find("tbody").find("td", text=commodity2.item_id)
assert page.find("tbody").find(href=f"/commodities/{commodity2.sid}/")
Expand All @@ -60,6 +68,14 @@ def test_commodity_list_displays_commodity_suffix_indent_and_description(
text=commodity2.get_indent_as_at(datetime.date.today()).indent,
)
assert page.find("tbody").find("td", text="A second commodity code description")
assert page.find("tbody").find(
"td",
text=f"{commodity2.valid_between.lower:%d %b %Y}",
)
assert page.find("tbody").find(
"td",
text=f"{commodity2.valid_between.upper:%d %b %Y}",
)


def test_commodity_list_queryset():
Expand Down
18 changes: 17 additions & 1 deletion common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ActiveStateMixin(FilterSet):
widget=forms.CheckboxSelectMultiple,
method="filter_active_state",
label="Active state",
help_text="Select all that apply",
help_text="Select one to filter by active or terminated items",
required=False,
)

Expand Down Expand Up @@ -348,3 +348,19 @@ def filter_work_basket(self, queryset, name, value):
id__in=wanted_objects_id,
)
return queryset


class EndDateMixin(FilterSet):
"""A filter to only show objects which have an end date."""

with_end_date = BooleanFilter(
label="Show items with an end date",
widget=forms.CheckboxInput(),
method="filter_end_date",
required=False,
)

def filter_end_date(self, queryset, name, value):
if value:
queryset = queryset.filter(valid_between__upper_inf=False)
return queryset
4 changes: 4 additions & 0 deletions common/static/common/scss/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@
.homepage-workbasket-action {
width: 100%;
}

.govuk-checkboxes__label:before {
background-color: white
}
31 changes: 16 additions & 15 deletions quotas/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,21 +794,22 @@ def test_sub_quota_update_form_valid(session_request_with_workbasket, sub_quota)
sub_quota_relation_type="EQ",
coefficient=1.5,
)

Copy link
Collaborator Author

@mattjamc mattjamc Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is unrelated to the ticket but it's a failing test from my last PR (which didn't fail before I merged it but I've fixed it now anyway)

form = forms.SubQuotaDefinitionAssociationUpdateForm(
instance=sub_quota,
request=session_request_with_workbasket,
sid=sub_quota.sid,
)
assert float(form.fields["coefficient"].initial) == association.coefficient
assert (
form.fields["relationship_type"].initial == association.sub_quota_relation_type
)
assert form.fields["measurement_unit"].initial == sub_quota.measurement_unit
assert form.fields["initial_volume"].initial == sub_quota.initial_volume
assert form.fields["volume"].initial == sub_quota.volume
assert form.fields["start_date"].initial == sub_quota.valid_between.lower
assert form.fields["end_date"].initial == sub_quota.valid_between.upper
with override_current_transaction(Transaction.objects.last()):
form = forms.SubQuotaDefinitionAssociationUpdateForm(
instance=sub_quota,
request=session_request_with_workbasket,
sid=sub_quota.sid,
)
assert float(form.fields["coefficient"].initial) == association.coefficient
assert (
form.fields["relationship_type"].initial
== association.sub_quota_relation_type
)
assert form.fields["measurement_unit"].initial == sub_quota.measurement_unit
assert form.fields["initial_volume"].initial == sub_quota.initial_volume
assert form.fields["volume"].initial == sub_quota.volume
assert form.fields["start_date"].initial == sub_quota.valid_between.lower
assert form.fields["end_date"].initial == sub_quota.valid_between.upper

data = {
"start_date_0": sub_quota.valid_between.lower.day,
Expand Down
Loading