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-1475-Edit-sub-quotas #1287

Merged
merged 81 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
3c6aac6
duplicating definitions form wizard
CPrich905 Jul 12, 2024
7d41939
Merge branch 'master' into TP2000-1371-implement-new-sub-quotas-journey
CPrich905 Jul 12, 2024
d9ec511
temp conflict resolution - check
CPrich905 Jul 12, 2024
bb47f6d
initial journey working; todo: debug sub-quotas view page; todo: big …
CPrich905 Aug 1, 2024
2731e9e
adding validity checks to Quota Association edit form; some tidying up
CPrich905 Aug 6, 2024
8801bcd
conforming main/sub-quota language; removing comments; adding measure…
CPrich905 Aug 8, 2024
086c75e
alinging styles
CPrich905 Aug 8, 2024
830461d
adding form reset button
CPrich905 Aug 12, 2024
b12bf89
pause
CPrich905 Aug 12, 2024
f6cb103
tests: get_cleaned_data_for_step, get_form_kwargs, edit view renders
CPrich905 Aug 20, 2024
c5541ab
Merge branch 'master' into TP2000-1371-implement-new-sub-quotas-journey
CPrich905 Aug 20, 2024
1f5a43f
refactored business rule validations to business_rules.py; tests; notes
CPrich905 Aug 23, 2024
15397fd
correcting parent_definition to main_definition; squashing migrations
CPrich905 Aug 23, 2024
5e56572
correcting parent_definition to main_definition; squashing migrations
CPrich905 Aug 23, 2024
feb9519
Merge branch 'master' into TP2000-1371-implement-new-sub-quotas-journey
CPrich905 Aug 23, 2024
f517a6d
adding check for definition data status; tidying up
CPrich905 Aug 23, 2024
a45e364
formatting
CPrich905 Aug 23, 2024
e51e678
adding tests for business rules; TODO: re-check QA5 requirements
CPrich905 Aug 23, 2024
712afe1
fixing test
CPrich905 Aug 23, 2024
e87c200
- fixes linting
TomMacca Aug 23, 2024
acaa955
updates to QA5 checks - in progress
CPrich905 Aug 27, 2024
67b47ba
fixing and testing QA5
CPrich905 Aug 27, 2024
7a2b08d
test for QA6
CPrich905 Aug 27, 2024
6f40bc7
tests
CPrich905 Aug 27, 2024
29e6b29
removing comments
CPrich905 Aug 27, 2024
24d6707
date formatter
CPrich905 Aug 28, 2024
4954653
adding initial volume; adding breadcrumbs
CPrich905 Aug 28, 2024
0d73a9d
responding to PR comments
CPrich905 Aug 28, 2024
8cfc148
adding button group; cleaning up set_duplicate_definitions
CPrich905 Aug 29, 2024
52190d1
PR comments pt 2
CPrich905 Aug 29, 2024
face382
Merge branch 'master' into TP2000-1371-implement-new-sub-quotas-journey
CPrich905 Aug 29, 2024
c9efaf1
responding to PR comments 3
CPrich905 Aug 29, 2024
4a10669
corrected title
CPrich905 Aug 30, 2024
90bbbb3
Replace radio buttons for tabs
mattjamc Aug 30, 2024
947171f
Add test and match figma design
mattjamc Aug 30, 2024
1aef997
response to Pauls CR pt 1
CPrich905 Sep 2, 2024
786d88b
factoring out of business rules checks to avoid duplication
CPrich905 Sep 3, 2024
8b8eaf8
removing model, using session
CPrich905 Sep 4, 2024
762a072
Merge branch 'TP2000-1371-implement-new-sub-quotas-origin' into TP200…
mattjamc Sep 4, 2024
f961b0f
wizard file
CPrich905 Sep 4, 2024
e8ebded
Merge branch 'TP2000-1371-implement-new-sub-quotas-journey' of github…
mattjamc Sep 4, 2024
32fb4db
tests for forms using session
CPrich905 Sep 4, 2024
1fa5751
black formatting
CPrich905 Sep 4, 2024
1962e48
adding tests for session use; correcting sid to pk
CPrich905 Sep 5, 2024
338205e
removing model & migration
CPrich905 Sep 5, 2024
eff32cf
Merge branch 'master' into TP2000-1371-implement-new-sub-quotas-journey
CPrich905 Sep 9, 2024
fc61fef
fixing test params
CPrich905 Sep 9, 2024
34aa4c7
Basic functioning sub quota edit form
mattjamc Sep 9, 2024
69986db
Merge branch 'TP2000-1371-implement-new-sub-quotas-journey' of github…
mattjamc Sep 9, 2024
e2a7d89
Add helper for latest version of object
mattjamc Sep 10, 2024
c768d02
adding validation to require at least one definition to be selected
CPrich905 Sep 11, 2024
3d6a391
copy changes from chat with Ash; removed storage_name from update form
CPrich905 Sep 11, 2024
98a659e
Merge branch 'TP2000-1371-implement-new-sub-quotas-journey' of github…
mattjamc Sep 11, 2024
589d17b
Swapped main_quota for get_main_definition for consistency
mattjamc Sep 12, 2024
d823193
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 12, 2024
ecf85ae
Merge branch 'master' into TP2000-1468-amend-view-definition-periods
mattjamc Sep 12, 2024
788f5d9
Content updates
mattjamc Sep 12, 2024
3914e33
Make sub-quotas heading consistent
mattjamc Sep 12, 2024
fffe636
black
mattjamc Sep 12, 2024
ea8235f
Merge branch 'TP2000-1468-amend-view-definition-periods' of github.co…
mattjamc Sep 13, 2024
628d11b
Undo some for compatibility with create journey
mattjamc Sep 13, 2024
a0f09f6
Tidy up to match master
mattjamc Sep 16, 2024
e7ddbba
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 16, 2024
e6cd886
Ensure correct association selection
mattjamc Sep 16, 2024
56c6d03
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 16, 2024
80d3e86
Merge branch 'TP2000-1475-edit-sub-quotas' of github.com:uktrade/tama…
mattjamc Sep 16, 2024
262c246
Use latest version up to transaction
mattjamc Sep 17, 2024
e0815e3
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 17, 2024
98bb7ab
Tidy up
mattjamc Sep 18, 2024
13cdb59
Form tests not working
mattjamc Sep 18, 2024
198a450
Merge branch 'TP2000-1475-edit-sub-quotas' of github.com:uktrade/tama…
mattjamc Sep 18, 2024
e6104dd
Form tests done
mattjamc Sep 19, 2024
b90d35e
View tests
mattjamc Sep 19, 2024
2a13195
Test sub-quota edit url
mattjamc Sep 20, 2024
37dfe6f
Add test for get_association_edit_url
mattjamc Sep 20, 2024
875ea67
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 20, 2024
15f3892
Edie PR comments
mattjamc Sep 25, 2024
847b17e
Merge branch 'TP2000-1475-edit-sub-quotas' of github.com:uktrade/tama…
mattjamc Sep 25, 2024
aaa947a
Hyphen sub-quotas
mattjamc Sep 26, 2024
86f6f8f
Change to current, fix association bug
mattjamc Sep 26, 2024
7a62e12
Merge branch 'master' into TP2000-1475-edit-sub-quotas
mattjamc Sep 26, 2024
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/business_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def validate(self, quota_definition):
class QuotaAssociationMustReferToANonDeletedSubQuota(
PreventDeletingLinkedQuotaDefinitions,
):
"""A Quota Association must refer to a non-deleted sub quota."""
"""A Quota Association must refer to a non-deleted sub-quota."""

sid_prefix = "sub_quota__"

Expand Down
60 changes: 59 additions & 1 deletion quotas/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date

from crispy_forms_gds.helper import FormHelper
from crispy_forms_gds.layout import HTML
from crispy_forms_gds.layout import Accordion
Expand Down Expand Up @@ -1110,6 +1112,9 @@ def clean(self):
class SubQuotaDefinitionsUpdatesForm(
ValidityPeriodForm,
):
"""Form used to edit duplicated sub-quota definitions and associations as
part of the sub-quota create journey."""

class Meta:
model = models.QuotaDefinition
fields = [
Expand Down Expand Up @@ -1162,6 +1167,7 @@ class Meta:
)

measurement_unit = forms.ModelChoiceField(
label="Measurement unit",
queryset=MeasurementUnit.objects.current().order_by("code"),
error_messages={"required": "Select the measurement unit"},
)
Expand Down Expand Up @@ -1223,7 +1229,7 @@ def clean(self):
main_definition_valid_between=original_definition.valid_between,
):
raise ValidationError(
"QA2: Validity period for sub quota must be within the "
"QA2: Validity period for sub-quota must be within the "
"validity period of the main quota",
)

Expand Down Expand Up @@ -1337,3 +1343,55 @@ def init_layout(self, request):
),
),
)


class SubQuotaDefinitionAssociationUpdateForm(SubQuotaDefinitionsUpdatesForm):
"""Form used to update sub-quota definitions and associations as part of the
edit sub-quotas journey."""

def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
self.workbasket = self.request.user.current_workbasket
sub_quota_definition_sid = kwargs.pop("sid")
ValidityPeriodForm.__init__(self, *args, **kwargs)
self.sub_quota = models.QuotaDefinition.objects.current().get(
sid=sub_quota_definition_sid,
)
self.init_fields()
self.set_initial_data()
self.init_layout(self.request)

def set_initial_data(self):
association = models.QuotaAssociation.objects.current().get(
sub_quota__sid=self.sub_quota.sid,
)
self.original_definition = association.main_quota
fields = self.fields
fields["relationship_type"].initial = association.sub_quota_relation_type
fields["coefficient"].initial = association.coefficient
fields["measurement_unit"].initial = self.sub_quota.measurement_unit
fields["initial_volume"].initial = self.sub_quota.initial_volume
fields["volume"].initial = self.sub_quota.volume
fields["start_date"].initial = self.sub_quota.valid_between.lower
fields["end_date"].initial = self.sub_quota.valid_between.upper

def init_fields(self):
super().init_fields()
if self.sub_quota.valid_between.lower <= date.today():
self.fields["coefficient"].disabled = True
self.fields["relationship_type"].disabled = True
self.fields["start_date"].disabled = True
self.fields["initial_volume"].disabled = True
self.fields["volume"].disabled = True
self.fields["measurement_unit"].disabled = True


class QuotaAssociationEdit(forms.ModelForm):
class Meta:
model = models.QuotaAssociation
fields = [
"sub_quota_relation_type",
"coefficient",
"main_quota",
"sub_quota",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends "common/confirm_update.jinja" %}
{% from "components/breadcrumbs.jinja" import breadcrumbs %}


{% set page_title = "Sub-quota definition and association updated" %}

{% block breadcrumb %}
{{ breadcrumbs(request, [
{"text": "Find and edit quotas", "href": url("quota-ui-list")},
{"text": "Quota " ~ association.main_quota.order_number, "href": association.main_quota.order_number.get_url()},
{"text": "Quota " ~ association.main_quota.order_number ~ " - Data", "href": url("quota_definition-ui-list", kwargs={"sid":association.main_quota.order_number.sid})},
{"text": page_title},
])
}}
{% endblock %}


{% block panel %}
{{ govukPanel({
"titleText": "Sub-" ~ object._meta.verbose_name ~ ": " ~ object|string,
"text": "Sub-" ~ object._meta.verbose_name ~ ": " ~ object|string ~ " and association have been updated in workbasket " ~ request.user.current_workbasket.pk,
"classes": "govuk-!-margin-bottom-7"
}) }}
{% endblock %}

{% block button_group %}
{{ govukButton({
"text": "View workbasket summary",
"href": url("workbaskets:current-workbasket"),
"classes": "govuk-button"
}) }}
{{ govukButton({
"text": "Return to main quota",
"href": association.main_quota.order_number.get_url(),
"classes": "govuk-button--secondary"
}) }}
{% endblock %}

{% block actions %}
<li><a class="govuk-link" href="{{ object.order_number.get_url() }}">View this sub-quota definition's quota order number</a></li>
<li><a href="{{ object.order_number.get_url('list') }}">Find and edit quotas</a></li>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends "layouts/form.jinja" %}
{% from "components/breadcrumbs.jinja" import breadcrumbs %}

{% from "components/table/macro.njk" import govukTable %}

{% set page_title = "Update sub-quota definition and association" %}

{% block content %}
<h2 class="govuk-heading">Main quota definition details</h2>
{% set main_definition = view.get_main_definition() %}
Expand Down
13 changes: 9 additions & 4 deletions quotas/jinja2/quotas/tables/sub_quotas.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
{% set sub_quota_link -%}
<a class="govuk-link" href="{{ url('quota-ui-detail', args=[object.sub_quota.order_number.sid]) }}">{{ object.sub_quota.order_number.order_number }}</a>
{% endset %}
{% set edit_link -%}
<a class="govuk-link" href="{{ object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).get_association_edit_url() }}">Edit</a>
{% endset %}
{{ table_rows.append([
{"text": definition_link },
{"text": sub_quota_link },
{"text": "{:%d %b %Y}".format(object.sub_quota.valid_between.lower) },
{"text": "{:%d %b %Y}".format(object.sub_quota.valid_between.upper) if object.sub_quota.valid_between.upper else "-"},
{"text": "{:%d %b %Y}".format(object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.lower) },
{"text": "{:%d %b %Y}".format(object.sub_quota.version_at(request.user.current_workbasket.transactions.last()).valid_between.upper) if object.sub_quota.valid_between.upper else "-"},
{"text": object.get_sub_quota_relation_type_display() },
{"text": object.coefficient },
{"text": edit_link },
]) or "" }}
{% endfor %}

{{ govukTable({
"head": [
{"text": "Quota definition sid"},
{"text": "Sub quota order number"},
{"text": "Sub-quota order number"},
{"text": "Start date"},
{"text": "End date"},
{"text": "Relation type"},
{"text": "Coefficient"},
{"text": "Actions"},
],
"rows": table_rows
}) }}
{% else %}
<p class="govuk-body">There are no sub quotas for this quota order number.</p>
<p class="govuk-body">There are no sub-quotas for this quota order number.</p>
{% endif %}
20 changes: 20 additions & 0 deletions quotas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,26 @@ def get_url(self, action: str = "detail") -> Optional[str]:
def slugify_model_name(cls):
return cls._meta.verbose_name.replace(" ", "_")

def get_association_edit_url(self):
"""Get the edit url for the sub-quota definition and association edit
journey by checking if it has been updated in an 'EDITING' status
workbasket."""
url = "sub_quota_definition-edit"
try:
if self.transaction.workbasket.status == WorkflowStatus.EDITING:
# There is no edit-create journey for quota definitions so edits of a
# newly created object will add a new update object to the workbasket
if self.update_type == UpdateType.UPDATE:
url += "-update"

url = reverse(
url,
kwargs={"sid": self.sid},
)
return url
except NoReverseMatch:
return None


class QuotaAssociation(TrackedModel):
"""The quota association defines the relation between quota and sub-
Expand Down
Loading
Loading