Skip to content

Commit

Permalink
Merge pull request #5912 from uktrade/feature/CLS2-1173-add-address-f…
Browse files Browse the repository at this point in the history
…ields-from-company-to-serializer

Add address fields to company serialiser
  • Loading branch information
santoshdasa12345 authored Jan 22, 2025
2 parents 64bde80 + dbb8878 commit 5675321
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
13 changes: 12 additions & 1 deletion datahub/investment/project/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,18 @@ class IProjectSerializer(PermittedFieldsModelSerializer, NoteAwareModelSerialize
required=False,
allow_null=True,
)
investor_company = NestedRelatedField(Company, required=True, allow_null=False)
investor_company = NestedRelatedField(
Company,
[
'name',
'address_1',
'address_2',
'address_town',
'address_postcode',
],
required=True,
allow_null=False,
)
investor_company_country = NestedRelatedField(meta_models.Country, read_only=True)
investor_type = NestedRelatedField(InvestorType, required=False, allow_null=True)
intermediate_company = NestedRelatedField(Company, required=False, allow_null=True)
Expand Down
25 changes: 25 additions & 0 deletions datahub/investment/project/test/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,28 @@ def test_country_investment_originates_from(self):
assert str(
serializer.validated_data['country_investment_originates_from'],
) == constants.Country.argentina.value.name

def test_investor_company_required_fields(self):
"""Tests require fields for investor_company"""
project = InvestmentProjectFactory()
serializer = IProjectSerializer(project)
assert serializer.data['investor_company']['id'] == str(project.investor_company.id)
assert (
serializer.data['investor_company']['name'] == project.investor_company.name
)
assert (
serializer.data['investor_company']['address_1']
== project.investor_company.address_1
)
assert (
serializer.data['investor_company']['address_2']
== project.investor_company.address_2
)
assert (
serializer.data['investor_company']['address_town']
== project.investor_company.address_town
)
assert (
serializer.data['investor_company']['address_postcode']
== project.investor_company.address_postcode
)
4 changes: 4 additions & 0 deletions datahub/investment/project/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ def test_get_project_success(self):
assert response_data['investor_company'] == {
'id': str(investor_company.id),
'name': investor_company.name,
'address_1': investor_company.address_1,
'address_2': investor_company.address_2,
'address_postcode': investor_company.address_postcode,
'address_town': investor_company.address_town,
}
assert response_data['investor_company_country'] == {
'id': str(investor_company.address_country.id),
Expand Down

0 comments on commit 5675321

Please sign in to comment.