Skip to content

Commit

Permalink
Chris - Bugfix - 2024-12-18 (#277)
Browse files Browse the repository at this point in the history
Fixing issue with previously submitted reports that created
Organisations with registered_office_address but not address lines
  • Loading branch information
chris-pettinga authored Dec 19, 2024
1 parent 000a535 commit e965ac5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions django_app/report_a_suspected_breach/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from django.contrib.postgres.fields import ArrayField
from django.contrib.sessions.models import Session
from django.db import models, transaction
from django.forms import model_to_dict
from django_chunk_upload_handlers.clam_av import validate_virus_check_result
from django_countries.fields import CountryField
from report_a_suspected_breach.form_step_conditions import (
show_about_the_supplier_page,
show_check_company_details_page_condition,
show_name_and_business_you_work_for_page,
)
from utils.address_formatter import get_formatted_address
from utils.s3 import get_all_session_files, store_document_in_permanent_bucket

from .choices import ReporterProfessionalRelationshipChoices, TypeOfRelationshipChoices
Expand Down Expand Up @@ -208,6 +210,14 @@ def save_person_or_company(
registered_company_number = models.CharField(max_length=20, null=True, blank=True)
registered_office_address = models.CharField(null=True, blank=True)

def get_readable_address(self) -> str:
"""Returns a formatted address string for the address fields of this model instance."""
if self.registered_office_address:
# If we have registered_office_address, use that instead of the address fields
return self.registered_office_address
else:
return get_formatted_address(model_to_dict(self))


class UploadedDocument(BaseModel):
file = models.FileField(
Expand Down
6 changes: 2 additions & 4 deletions django_app/utils/breach_report.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Any

from django.forms.models import model_to_dict
from report_a_suspected_breach.choices import TypeOfRelationshipChoices
from report_a_suspected_breach.models import Breach, PersonOrCompany
from utils.address_formatter import get_formatted_address


def get_breach_context_data(breach: Breach) -> dict[str, Any]:
Expand All @@ -14,15 +12,15 @@ def get_breach_context_data(breach: Breach) -> dict[str, Any]:
if breacher := PersonOrCompany.objects.filter(
breach_id=breach.id, type_of_relationship=TypeOfRelationshipChoices.breacher
).first():
breacher_address = get_formatted_address(model_to_dict(breacher))
breacher_address = breacher.get_readable_address()
breach_context["breacher"] = breacher
breach_context["breacher_address"] = breacher_address

# Supplier
if supplier := PersonOrCompany.objects.filter(
breach_id=breach.id, type_of_relationship=TypeOfRelationshipChoices.supplier
).first():
supplier_address = get_formatted_address(model_to_dict(supplier))
supplier_address = supplier.get_readable_address()
breach_context["supplier"] = supplier
breach_context["supplier_address"] = supplier_address

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from tests.factories import BreacherPersonOrCompanyFactory


def test_readable_address(breach_object):
company = BreacherPersonOrCompanyFactory(
registered_office_address="12 test road, coventry, GL123, United Kingdom",
address_line_1="DO NOT SHOW",
address_line_2="DO NOT SHOW",
breach=breach_object,
)
assert company.get_readable_address() == "12 test road, coventry, GL123, United Kingdom"

company = BreacherPersonOrCompanyFactory(
registered_office_address=None, address_line_1="12 test road", address_line_2="coventry", breach=breach_object
)
assert company.get_readable_address() == "12 test road,\n coventry"

0 comments on commit e965ac5

Please sign in to comment.