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-1596 Quotas - small fixes #1365

Merged
merged 5 commits into from
Dec 26, 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
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
Loading