Skip to content

Commit

Permalink
TP2000-1596 Quotas - small fixes (#1365)
Browse files Browse the repository at this point in the history
* Fix delete association cancel button

* Include unapproved measures

* As at today and beyond
  • Loading branch information
mattjamc authored Dec 26, 2024
1 parent b791796 commit 24585b7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion quotas/jinja2/includes/quotas/tabs/sub_quotas.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% set actions_html %}
<a class="govuk-link" href="{{ object.sub_quota.get_association_edit_url() }}">Edit</a>
<br/>
<a class="govuk-link" href="{{ url('quota_association-ui-delete', args=[object.pk]) }}">Delete</a>
<a class="govuk-link" href="{{ object.get_url('delete') }}">Delete</a>
{% endset %}
{{ table_rows.append([
{"html": sub_quota_link},
Expand Down
6 changes: 0 additions & 6 deletions quotas/jinja2/quota-associations/delete.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,4 @@
{% call django_form(action="") %}
{{ crispy(form) }}
{% endcall %}

{{ govukButton({
"text": "Cancel",
"href": object.get_url(),
"classes": "govuk-button--secondary"
}) }}
{% endblock %}
27 changes: 27 additions & 0 deletions quotas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,33 @@ class QuotaAssociation(TrackedModel):
business_rules.SameMainAndSubQuota,
)

def get_url(self, action: str = "detail") -> Optional[str]:
"""
Generate a URL to a representation of the model in the webapp.
Custom for quota associations as they do not have a detail view or
typical list/edit views.
"""
if action == "edit":
url = self.sub_quota.get_association_edit_url()
return url
try:
if action == "create":
url = reverse("sub_quota_definitions-ui-create")
elif action == "delete":
url = reverse("quota_association-ui-delete", kwargs={"pk": self.pk})
else:
url = reverse(
"quota_definition-ui-list-filter",
kwargs={
"sid": self.main_quota.order_number.sid,
"quota_type": "quota_associations",
},
)
return url
except NoReverseMatch:
return None


class QuotaSuspension(TrackedModel, ValidityMixin):
"""Defines a suspension period for a quota."""
Expand Down
4 changes: 2 additions & 2 deletions quotas/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def get_context_data(self, *args, **kwargs):
order = "goods_nomenclature"

context["measures"] = (
Measure.objects.latest_approved()
Measure.objects.current()
.filter(order_number=self.object)
.as_at(date.today())
.as_at_today_and_beyond()
.order_by(order)
)
url_params = urlencode({"order_number": self.object.pk})
Expand Down

0 comments on commit 24585b7

Please sign in to comment.