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-1537 Bulk create QuotaDefinitionPeriods #1320

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

CPrich905
Copy link
Collaborator

@CPrich905 CPrich905 commented Nov 11, 2024

TP2000-1537 Bulk create QuotaDefinitionPeriods

Why

  • Currently QuotaDefinitionPeriods can only be created one by one
  • A Quota may cover a significant period of time and creating definition periods to cover the duration of the quota may require a significant amount of repetitions through this journey.

What

Following the figma design linked on the ticket and [here](Single and multiple journeys), this PR

  • utilises a Django form wizard to bulk create QuotaDefinitionPeriods, and
  • implements some design changes to the journey for creating a single QuotaDefinitionPeriod

There are four stages to the journey:
Beginning the journey from the Edit Workbasket View
image

  1. Start, outlining the information the users will need to have available and collecting the QuotaOrderNumber the QuotaDefinitionPeriods are to be built with.
image
  1. Enter the definition information. This collects the information required to build a QuotaDefinitionPeriod object, as well as the number of definition periods to be created, and the frequency with which they will be duplicated (Once, Annually, Twice-yearly, Quarterly, Custom)
image
  1. Review page. Here, the user can review the details that for an individual QuotaDefinitionPeriod via a collapsible info box, or edit any that require changing via the Edit link. On submit and the QuotaDefinitionPeriods are created and the user is taken to a standard success page.
image

On success, the user is redirected to a standard success page with Next steps and Further actions
image

Design changes:

  1. removing the accordion sections
  2. updates to default and help text for various widgets
  3. changes to the submit buttons/back links - these are now passed as args from the view, enabling us to reuse the QuotaDefinitionCreateForm for updating the bulk created definitions
  4. reorganisation of the Actions panel on the Quotas page
  5. adding help/info text to the journey for creating a single QuotaDefinitionPeriod
  6. adding a custom widget that allows the use of a suffix on a Decimal input field
image

@CPrich905 CPrich905 marked this pull request as ready for review December 20, 2024 15:50
@CPrich905 CPrich905 requested a review from a team as a code owner December 20, 2024 15:50
Copy link
Collaborator

@mattjamc mattjamc left a comment

Choose a reason for hiding this comment

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

Looks good! Just some small comments

</h1>
<p class="govuk-body">
You can create up to 20 quota definition periods for the same quota order number.
Subsequent periodswill be calculated from the first date range entered and the data will be duplicated across all definition periods.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a space

super().__init__(*args, **kwargs)
self.init_layout()
self.init_layout(self.request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does self.request get used in init_layout()?


# Set these as the default values
self.fields["quota_critical"].initial = False
self.fields["end_date"].help_text = ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Help text saying end date is optional is removed here but it is still optional as far as the code realises - a user not inputting an end date will need to be handled as the ValidityPeriodForm currently allows that

cleaned_data = super().clean()
for field in self.required_fields:
if field not in cleaned_data:
raise ValidationError(f"A value for {field} must be provided")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these not handled by the fields having required=True? This just adds a second error message for the same thing e.g. both [Enter the number of definition periods to create] and [A value for instance_count must be provided]



def serialize_definition_data(definition):
# Serializes data and returns a JSON dict that can be saved to session
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would these comments be better as docstrings if describing what the function does

<li><a class="govuk-link" href="{{ url('quota_definition-ui-create', args=[object.sid]) }}">Create definition period</a></li>
<strong class="govuk-heading-xs">Create quota data</strong>
<li><a class="govuk-link" href="{{ url('quota_definition-ui-create', args=[object.sid]) }}?order_number={{object.order_number}}">Create definition period</a></li>
<li><a class="govuk-link" href="{{ url('quota_definition-ui-bulk-create', args=[object.sid]) }}">The bulk creator</a></li>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the name but I have a feeling it wouldn't pass the GDS naming conventions - is it clear what is being bulk created here? (Seems obvious to us)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

@@ -156,9 +156,14 @@ class Meta:
"maximum_precision",
]

order_number = forms.ModelChoiceField(
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reason for adding this field in? What was happening before to get the order number?

Copy link
Collaborator

@mattjamc mattjamc Dec 30, 2024

Choose a reason for hiding this comment

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

I seem to be getting an error in this form that order number doesn't have a value when I submit but can't figure out why as you are assigning it an initial value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed the error, but do double check it's working for you as well!
As discussed on Teams, there was an issue testing this due to inherited forms using transaction.atomic. This was fixed by passing in the quota_order_number in the query string and then extracting it here. The error you encountered was that, while the initial value was being set, the order_number widget was still showing as missing a value (this error doesn't occur on the bulk creator).
The fix for this was to check if an empty value for the order_number widget is in the form.errors when form.clean() is called, assign the value of cleaned_data['order_number'] as the quota_order_number and then remove the error.

</span>
</h1>
<p class="govuk-body">You can create one new quota definition period using this form. Alternatively, you can <a class="govuk-link" href="{{ url('quota_definition-ui-bulk-create') }}">create multiple quota definition periods</a> for a chose quota order number.</p>
{% call django_form() %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

chosen*

{% block breadcrumb %}
{{ breadcrumbs(request, [
{"text": "Find and edit quotas", "href": url("quota-ui-list")},
{"text": "Quota order number", "href": url("quota-ui-detail", args=[view.kwargs.sid]) ~ "#definitions"},
{"text": "Quota order number", "href": url("quota-ui-detail", args=[quota_sid]) ~ "#definitions"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Appreciate it was already like that but I'm not sure #definitions is a real anchor tag for that page. Maybe #definition-details or none at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants