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

DST-951 - Save & Return - Second trio of views #190

Merged
merged 39 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2a79adb
business journey
Jan 24, 2025
d48cabb
alter delete view and fix tests
Jan 24, 2025
0b40543
updating individual views to save and return
Jan 27, 2025
099b5b6
yourself views
Jan 28, 2025
04b1370
fixing tests
Jan 28, 2025
f5695e5
fixing test
Jan 28, 2025
46bf959
Merge branch 'save-and-return' into DST-950
Jan 28, 2025
a2d18f0
Delete view requiers login
Jan 28, 2025
d29cea3
add formclass to delete view
Jan 29, 2025
3248548
updating migrations
Jan 29, 2025
279741c
removing print statements
Jan 29, 2025
ec1b475
modifiying uuid field migration
Jan 29, 2025
8a095ce
Adding default to uuid for migration
Jan 29, 2025
ad7bf8c
updating migrations again
Jan 29, 2025
0c56d9a
get uuid as primary key field
Jan 29, 2025
78cf7a3
updating to use id instead of uuid
Jan 29, 2025
9afc6bb
review comments
Jan 31, 2025
1590f9c
Updating yourself views
Jan 31, 2025
c5940aa
licence id object
Jan 31, 2025
4775a39
Making slow work
chris-pettinga Feb 4, 2025
89a1198
Finished merge and more work
chris-pettinga Feb 4, 2025
b3e9715
Merge branch 'save-and-return' into DST-951
chris-pettinga Feb 4, 2025
2a7b8d3
More fixes
chris-pettinga Feb 4, 2025
d3ba67c
migration fixing
chris-pettinga Feb 4, 2025
0eafb84
fixing tests
chris-pettinga Feb 4, 2025
0a1bb82
migrations
chris-pettinga Feb 4, 2025
a407f78
mypi
chris-pettinga Feb 4, 2025
170f432
fixing tests
chris-pettinga Feb 4, 2025
4a86ae7
fixing tests
chris-pettinga Feb 5, 2025
f2d3747
fixing tests
chris-pettinga Feb 5, 2025
048f788
fixing tests
chris-pettinga Feb 5, 2025
7d6bf48
fixing tests
chris-pettinga Feb 6, 2025
7161df3
fixing tests
chris-pettinga Feb 6, 2025
f8f2319
fixing tests
chris-pettinga Feb 6, 2025
5fdb79d
fixing tests
chris-pettinga Feb 6, 2025
33420c0
fixing FE tests
chris-pettinga Feb 6, 2025
c086886
Morgan comments
chris-pettinga Feb 10, 2025
1acd28f
fixing tests
chris-pettinga Feb 10, 2025
4f1021c
fixing tests
chris-pettinga Feb 11, 2025
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
5 changes: 5 additions & 0 deletions django_app/apply_for_a_licence/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ class TypeOfRelationshipChoices(models.TextChoices):
class StatusChoices(models.TextChoices):
draft = "draft", "Draft"
submitted = "submitted", "Submitted"


class WhereIsTheAddressChoices(models.TextChoices):
outside_uk = "outside-uk", "Outside the UK"
in_uk = "in-uk", "In the UK"
68 changes: 49 additions & 19 deletions django_app/apply_for_a_licence/forms/forms_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CompaniesHouse500Error,
CompaniesHouseException,
)
from apply_for_a_licence.models import Licence, Organisation
from apply_for_a_licence.models import Organisation
from core.forms.base_forms import (
BaseForm,
BaseModelForm,
Expand All @@ -30,8 +30,10 @@


class IsTheBusinessRegisteredWithCompaniesHouseForm(BaseModelForm):
save_and_return = True

class Meta:
model = Licence
model = Organisation
fields = ["business_registered_on_companies_house"]
widgets = {"business_registered_on_companies_house": forms.RadioSelect}
labels = {
Expand All @@ -47,18 +49,21 @@ class Meta:
def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
self.fields["business_registered_on_companies_house"].choices.pop(0)
self.fields["business_registered_on_companies_house"].required = True


class DoYouKnowTheRegisteredCompanyNumberForm(BaseModelForm):
save_and_return = True
hide_optional_label_fields = ["registered_company_number"]

registered_company_name = forms.CharField(required=False)
registered_office_address = forms.CharField(required=False)

class Meta:
model = Organisation
fields = ["do_you_know_the_registered_company_number", "registered_company_number"]
widgets = {"do_you_know_the_registered_company_number": forms.RadioSelect}
fields = ["do_you_know_the_registered_company_number", "registered_company_number", "name", "registered_office_address"]
widgets = {
"do_you_know_the_registered_company_number": forms.RadioSelect,
"name": forms.HiddenInput,
"registered_office_address": forms.HiddenInput,
}
labels = {
"do_you_know_the_registered_company_number": "Do you know the registered company number?",
"registered_company_number": "Registered company number",
Expand All @@ -74,7 +79,7 @@ class Meta:

def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)

self.fields["name"].required = False
# remove companies house 500 error if it exists
self.request.session.pop("company_details_500", None)
self.request.session.modified = True
Expand Down Expand Up @@ -124,7 +129,7 @@ def clean(self) -> dict[str, Any]:
try:
company_details = get_details_from_companies_house(registered_company_number)
cleaned_data["registered_company_number"] = company_details["company_number"]
cleaned_data["registered_company_name"] = company_details["company_name"]
cleaned_data["name"] = company_details["company_name"]
cleaned_data["registered_office_address"] = get_formatted_address(
company_details["registered_office_address"]
)
Expand Down Expand Up @@ -172,20 +177,28 @@ def __init__(self, *args: object, **kwargs: object) -> None:
)


class WhereIsTheBusinessLocatedForm(BaseForm):
where_is_the_address = forms.ChoiceField(
label="Where is the business located?",
choices=(
("in-uk", "In the UK"),
("outside-uk", "Outside the UK"),
),
widget=forms.RadioSelect,
error_messages={"required": "Select if the business is located in the UK or outside the UK"},
)
class WhereIsTheBusinessLocatedForm(BaseModelForm):
class Meta:
model = Organisation
fields = ("where_is_the_address",)
widgets = {
"where_is_the_address": forms.RadioSelect,
}
labels = {
"where_is_the_address": "Where is the business located?",
}
error_messages = {
"where_is_the_address": {"required": "Select if the business is located in the UK or outside the UK"},
}

def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
self.fields["where_is_the_address"].choices.pop(0)


class AddAUKBusinessForm(BaseUKBusinessDetailsForm):
form_h1_header = "Business details"
save_and_return = True

class Meta(BaseUKBusinessDetailsForm.Meta):
model = Organisation
Expand Down Expand Up @@ -231,6 +244,7 @@ def __init__(self, *args: object, **kwargs: object) -> None:

class AddANonUKBusinessForm(BaseNonUKBusinessDetailsForm):
form_h1_header = "Business details"
save_and_return = True

class Meta(BaseNonUKBusinessDetailsForm.Meta):
model = Organisation
Expand Down Expand Up @@ -298,3 +312,19 @@ def __init__(self, *args: object, **kwargs: object) -> None:
if self.request.method == "GET":
# we never want to bind/pre-fill this form, always fresh for the user
self.is_bound = False


class CheckCompanyDetailsForm(BaseModelForm):
class Meta:
model = Organisation
fields = ["name", "registered_company_number", "registered_office_address"]
widgets = {
"name": forms.HiddenInput,
"registered_company_number": forms.HiddenInput,
"registered_office_address": forms.HiddenInput,
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self.Meta.fields:
self.fields[field].required = False
51 changes: 21 additions & 30 deletions django_app/apply_for_a_licence/forms/forms_existing_licence.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from apply_for_a_licence.choices import WhoDoYouWantTheLicenceToCoverChoices
from apply_for_a_licence.models import Licence
from apply_for_a_licence.utils import get_cleaned_data_for_step
from core.forms.base_forms import BaseModelForm
from crispy_forms_gds.layout import (
ConditionalQuestion,
Expand Down Expand Up @@ -43,42 +43,33 @@ def __init__(self, *args: object, **kwargs: object) -> None:
"No",
)
)
self.held_existing_licence_label = (
"Have any of the businesses you've added held a licence before to provide "
"any sanctioned services or export any sanctioned goods?"
)

if start_view := get_cleaned_data_for_step(self.request, "start"):
if start_view.get("who_do_you_want_the_licence_to_cover") == "myself":
self.held_existing_licence_label = (
"Have you, or has anyone else you've added, held a licence before "
"to provide any sanctioned services or export any sanctioned goods?"
)
elif start_view.get("who_do_you_want_the_licence_to_cover") == "individual":
self.held_existing_licence_label = (
"Have any of the individuals you've added held a licence before to "
"provide any sanctioned services or export any sanctioned goods?"
)
self.fields["held_existing_licence"].label = self.held_existing_licence_label
start_view = get_cleaned_data_for_step(self.request, "start")

if start_view.get("who_do_you_want_the_licence_to_cover") == "business":
if self.instance.who_do_you_want_the_licence_to_cover == WhoDoYouWantTheLicenceToCoverChoices.myself:
self.fields["held_existing_licence"].label = (
"Have you, or has anyone else you've added, held a licence before "
"to provide any sanctioned services or export any sanctioned goods?"
)
self.fields["held_existing_licence"].error_messages["required"] = (
"Select yes if any of the businesses "
"have held a licence before to provide sanctioned services or export sanctioned goods"
"Select yes if you, or anyone else you've "
"added, has held a licence before to provide sanctioned "
"services or export sanctioned goods"
)
elif self.instance.who_do_you_want_the_licence_to_cover == WhoDoYouWantTheLicenceToCoverChoices.individual:
self.fields["held_existing_licence"].label = (
"Have any of the individuals you've added held a licence before to "
"provide any sanctioned services or export any sanctioned goods?"
)

elif start_view.get("who_do_you_want_the_licence_to_cover") == "individual":
self.fields["held_existing_licence"].error_messages["required"] = (
"Select yes if any of the individuals have held a licence before to "
"provide sanctioned services or export sanctioned goods"
)

elif start_view.get("who_do_you_want_the_licence_to_cover") == "myself":
elif self.instance.who_do_you_want_the_licence_to_cover == WhoDoYouWantTheLicenceToCoverChoices.business:
self.fields["held_existing_licence"].label = (
"Have any of the businesses you've added held a licence before to provide "
"any sanctioned services or export any sanctioned goods?"
)
self.fields["held_existing_licence"].error_messages["required"] = (
"Select yes if you, or anyone else you've "
"added, has held a licence before to provide sanctioned "
"services or export sanctioned goods"
"Select yes if any of the businesses "
"have held a licence before to provide sanctioned services or export sanctioned goods"
)

def clean(self) -> dict[str, Any]:
Expand Down
89 changes: 40 additions & 49 deletions django_app/apply_for_a_licence/forms/forms_grounds_purpose.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
from apply_for_a_licence import choices
from apply_for_a_licence.models import Licence
from apply_for_a_licence.utils import get_cleaned_data_for_step
from core.crispy_fields import get_field_with_label_id
from core.forms.base_forms import BaseForm, BaseModelForm
from core.forms.base_forms import BaseModelForm
from crispy_forms_gds.choices import Choice
from crispy_forms_gds.layout import Field, Fieldset, Layout
from django import forms


class LicensingGroundsForm(BaseForm):
licensing_grounds = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=choices.LicensingGroundsChoices.active_choices(),
required=True,
label="Select all that apply",
error_messages={
"invalid": "Select the licensing grounds or select I do not know",
},
)

class Meta:
model = Licence
fields = ["licensing_grounds"]
class BaseLicensingGroundsForm(BaseModelForm):
field_name: str | None = None

class Media:
js = ["apply_for_a_licence/javascript/licensing_grounds.js"]

def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
services = self.get_services()
error_messages = self.fields["licensing_grounds"].error_messages
self.checkbox_choices = self.fields["licensing_grounds"].choices

# setting the labels and widgets
self.fields[self.field_name].label = "Select all that apply"

self.checkbox_choices = choices.LicensingGroundsChoices.active_choices()
# Create the 'or' divider between the last choice and I do not know
last_actual_licensing_ground_value = self.checkbox_choices[-3][0]
last_actual_licensing_ground_label = self.checkbox_choices[-3][1]
assert last_actual_licensing_ground_value == choices.LicensingGroundsChoices.food.value
self.checkbox_choices[-3] = Choice(
value=last_actual_licensing_ground_value,
label=last_actual_licensing_ground_label,
divider="or",
)
self.fields[self.field_name].choices = self.checkbox_choices

if self.instance.professional_or_business_services:
if choices.ProfessionalOrBusinessServicesChoices.legal_advisory in self.instance.professional_or_business_services:
self.fields[self.field_name].error_messages = {
"required": "Select which licensing grounds describe the purpose of the relevant "
"activity for which the legal advice is being given, or select none of these, "
"or select I do not know"
}
else:
self.fields[self.field_name].error_messages = {
"required": "Select which licensing grounds describe your purpose for providing"
" the sanctioned services, or select none of these, or select I do not know"
}

self.fields["licensing_grounds"].choices = self.checkbox_choices
self.helper.layout = Layout(
Fieldset(
get_field_with_label_id("licensing_grounds", field_method=Field.checkboxes, label_id="checkbox"),
get_field_with_label_id(self.field_name, field_method=Field.checkboxes, label_id="checkbox"),
aria_describedby="checkbox",
)
)

if "legal_advisory" in services:
self.fields["licensing_grounds"].error_messages = error_messages | {
"required": "Select which licensing grounds describe the purpose of the relevant activity for which the legal "
"advice is being given, or select none of these, or select I do not know"
}
else:
self.fields["licensing_grounds"].error_messages = error_messages | {
"required": "Select which licensing grounds describe your purpose for providing"
" the sanctioned services, or select none of these, or select I do not know"
}

def get_services(self):
return get_cleaned_data_for_step(self.request, "professional_or_business_services").get(
"professional_or_business_services", []
)
class LicensingGroundsForm(BaseLicensingGroundsForm):
field_name = "licensing_grounds"

def get_licensing_grounds_display(self):
display = []
for licensing_ground in self.cleaned_data["licensing_grounds"]:
display += [dict(self.fields["licensing_grounds"].choices)[licensing_ground]]
display = ",\n\n".join(display)
return display
class Meta:
model = Licence
fields = ["licensing_grounds"]
widgets = {
"licensing_grounds": forms.CheckboxSelectMultiple,
}


class LicensingGroundsLegalAdvisoryForm(LicensingGroundsForm):
def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
self.fields["licensing_grounds"].error_messages = self.fields["licensing_grounds"].error_messages | {
"required": "Select which licensing grounds describe your purpose for providing "
"the sanctioned services (excluding legal advisory), or select none of these, or select I do not know"
}
class LicensingGroundsLegalAdvisoryForm(BaseLicensingGroundsForm):
field_name = "licensing_grounds_legal_advisory"

self.fields["licensing_grounds"].choices = self.checkbox_choices
class Meta(LicensingGroundsForm.Meta):
model = Licence
fields = ["licensing_grounds_legal_advisory"]
widgets = {
"licensing_grounds_legal_advisory": forms.CheckboxSelectMultiple,
}


class PurposeOfProvisionForm(BaseModelForm):
Expand Down
6 changes: 4 additions & 2 deletions django_app/apply_for_a_licence/forms/forms_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class AddAnIndividualForm(BaseModelForm):
form_h1_header = "Add an individual"

save_and_return = True
nationality = forms.CharField(widget=forms.HiddenInput, required=False)

class Meta:
Expand Down Expand Up @@ -79,6 +79,7 @@ def __init__(self, *args: object, **kwargs: object) -> None:


class BusinessEmployingIndividualForm(BaseBusinessDetailsForm):
save_and_return = True

class Meta(BaseBusinessDetailsForm.Meta):
model = Organisation
Expand All @@ -99,7 +100,6 @@ class Meta(BaseBusinessDetailsForm.Meta):

def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)

self.fields["country"].required = True
self.fields["country"].empty_label = "Select country"
self.fields["address_line_1"].error_messages["required"] = "Enter address line 1"
Expand Down Expand Up @@ -127,6 +127,7 @@ def __init__(self, *args: object, **kwargs: object) -> None:

class IndividualUKAddressForm(BaseUKBusinessDetailsForm):
form_h1_header = "What is the individual's home address?"
save_and_return = True

class Meta(BaseUKBusinessDetailsForm.Meta):
model = Individual
Expand Down Expand Up @@ -160,6 +161,7 @@ def __init__(self, *args, **kwargs):

class IndividualNonUKAddressForm(BaseNonUKBusinessDetailsForm):
form_h1_header = "What is the individual's home address?"
save_and_return = True

class Meta(BaseNonUKBusinessDetailsForm.Meta):
model = Individual
Expand Down
Loading