Skip to content

Commit

Permalink
fully tested
Browse files Browse the repository at this point in the history
  • Loading branch information
jenriordan committed Aug 15, 2024
1 parent 6906288 commit 5f8a6ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
18 changes: 7 additions & 11 deletions django_app/apply_for_a_licence/views/views_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ class DeclarationView(BaseFormView):

def form_valid(self, form: DeclarationForm) -> HttpResponse:
cleaned_data = get_all_cleaned_data(self.request)
print(cleaned_data)
licence_object = Licence.objects
applicant_object = Applicant.objects
individual = None
business = None
recipient = Organisation.objects
is_individual = False
is_on_companies_house = False
is_third_party = False
Expand All @@ -73,16 +70,15 @@ def form_valid(self, form: DeclarationForm) -> HttpResponse:
if cleaned_data["start"]["who_do_you_want_the_licence_to_cover"] == "individual":
business_employing_individual = Organisation.objects

elif cleaned_data["is_the_business_registered_with_companies_house"].get("business_registered_on_companies_house", ""):
if (
cleaned_data["is_the_business_registered_with_companies_house"].get("business_registered_on_companies_house", "")
== "yes"
):
is_on_companies_house = True
business = Organisation.objects

elif cleaned_data["are_you_third_party"].get("are_you_applying_on_behalf_of_someone_else", ""):
if cleaned_data["are_you_third_party"].get("are_you_applying_on_behalf_of_someone_else", ""):
is_third_party = True

else:
business = Organisation.objects

with transaction.atomic():
save_object = SaveToDB(
self.request,
Expand All @@ -105,9 +101,9 @@ def form_valid(self, form: DeclarationForm) -> HttpResponse:
if business_employing_individual is not None:
save_object.save_business(business_employing_individual)
else:
save_object.save_business(business)
save_object.save_business(Organisation.objects)

save_object.save_recipient(recipient)
save_object.save_recipient(Organisation.objects)

if cleaned_data["upload_documents"]["document"]:
save_object.save_document(Document.objects)
Expand Down
70 changes: 34 additions & 36 deletions django_app/utils/save_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _get_user_verification(self) -> UserEmailVerification:
return user_email_verification

def save_applicant(self) -> Applicant:
# sole or named individuals journey
if self.is_individual:
if self.data["start"]["who_do_you_want_the_licence_to_cover"] == "individual":
if self.is_third_party:
Expand Down Expand Up @@ -84,16 +85,21 @@ def save_applicant(self) -> Applicant:
held_existing_licence=self.data["previous_licence"]["held_existing_licence"],
existing_licences=self.data["previous_licence"]["existing_licences"],
)
elif self.is_on_companies_house:
if self.data["do_you_know_the_registered_company_number"]["do_you_know_the_registered_company_number"] == "yes":
return self.applicant.create(
user_email_address=self.data["what_is_your_email"],
user_email_verification=self.email_verification,
full_name=self.data["do_you_know_the_registered_company_number"]["registered_company_name"],
type_of_relationship=TypeOfRelationshipChoices.business,
held_existing_licence=self.data["previous_licence"]["held_existing_licence"],
existing_licences=self.data["previous_licence"]["existing_licences"],
)

# business journey
elif (
self.is_on_companies_house
and self.data["do_you_know_the_registered_company_number"]["do_you_know_the_registered_company_number"] == "yes"
and not self.is_third_party
):
return self.applicant.create(
user_email_address=self.data["what_is_your_email"],
user_email_verification=self.email_verification,
full_name=self.data["do_you_know_the_registered_company_number"]["registered_company_name"],
type_of_relationship=TypeOfRelationshipChoices.business,
held_existing_licence=self.data["previous_licence"]["held_existing_licence"],
existing_licences=self.data["previous_licence"]["existing_licences"],
)
elif self.is_third_party:
return self.applicant.create(
user_email_address=self.data["what_is_your_email"],
Expand All @@ -105,7 +111,6 @@ def save_applicant(self) -> Applicant:
held_existing_licence=self.data["previous_licence"]["held_existing_licence"],
existing_licences=self.data["previous_licence"]["existing_licences"],
)

else:
return self.applicant.create(
user_email_address=self.data["what_is_your_email"],
Expand All @@ -132,11 +137,15 @@ def save_licence(self, applicant: Applicant) -> None:
service_activities=self.data["service_activities"]["service_activities"],
)

sanctions_regimes = []
if self.data["which_sanctions_regime"]:
sanctions_regimes = [self.data["which_sanctions_regime"]["which_sanctions_regime"]]

licence = self.licence.create(
applicant=applicant,
ground=ground,
business_registered_on_companies_house="No",
regimes=["test regime 1", "test regime 2", "test regime 3"],
business_registered_on_companies_house="Yes" if self.is_on_companies_house else "No",
regimes=sanctions_regimes,
services=services,
purpose_of_provision=self.data["purpose_of_provision"]["purpose_of_provision"],
)
Expand Down Expand Up @@ -183,29 +192,18 @@ def save_individual(self, individual: Individual) -> None:
def save_business(self, business: Organisation) -> None:
# named individuals employment details
if self.is_individual:
if self.is_on_companies_house:
business.create(
licence=self.licence,
name=self.data["do_you_know_the_registered_company_number"]["registered_company_name"],
do_you_know_the_registered_company_number="Yes",
registered_company_number=self.data["do_you_know_the_registered_company_number"]["registered_company_number"],
registered_office_address=self.data["do_you_know_the_registered_company_number"]["registered_office_address"],
type_of_relationship=TypeOfRelationshipChoices.named_individuals,
relationship_provider=self.data["relationship_provider_recipient"]["relationship"],
)
else:
business.create(
licence=self.licence,
name=self.data["business_employing_individual"]["name"],
do_you_know_the_registered_company_number="No",
address_line_1=self.data["business_employing_individual"]["address_line_1"],
address_line_2=self.data["business_employing_individual"]["address_line_2"],
address_line_3=self.data["business_employing_individual"]["address_line_3"],
address_line_4=self.data["business_employing_individual"]["address_line_4"],
country=self.data["business_employing_individual"]["country"],
type_of_relationship=TypeOfRelationshipChoices.named_individuals,
relationship_provider=self.data["relationship_provider_recipient"]["relationship"],
)
business.create(
licence=self.licence,
name=self.data["business_employing_individual"]["name"],
do_you_know_the_registered_company_number="No",
address_line_1=self.data["business_employing_individual"]["address_line_1"],
address_line_2=self.data["business_employing_individual"]["address_line_2"],
address_line_3=self.data["business_employing_individual"]["address_line_3"],
address_line_4=self.data["business_employing_individual"]["address_line_4"],
country=self.data["business_employing_individual"]["country"],
type_of_relationship=TypeOfRelationshipChoices.named_individuals,
relationship_provider=self.data["relationship_provider_recipient"]["relationship"],
)

# business journey company details
elif self.is_on_companies_house:
Expand Down

0 comments on commit 5f8a6ef

Please sign in to comment.