Skip to content

Commit

Permalink
Merge pull request #5507 from uktrade/feature/add-legacy-fields-to-ex…
Browse files Browse the repository at this point in the history
…port-win-serializer

Add legacy fields win Export win serializers.
  • Loading branch information
elcct authored Jul 9, 2024
2 parents 4eac9a4 + 8b71207 commit 0a030e5
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
34 changes: 34 additions & 0 deletions datahub/export_win/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from rest_framework.serializers import (
BooleanField,
CharField,
DateTimeField,
ModelSerializer,
SerializerMethodField,
Expand Down Expand Up @@ -70,11 +71,16 @@ class WinAdviserSerializer(ModelSerializer):
team_type = NestedRelatedField(TeamType)
hq_team = NestedRelatedField(HQTeamRegionOrPost)

# legacy field
name = CharField(read_only=True)

class Meta:
model = WinAdviser
fields = (
'id',
'adviser',
# legacy field
'name',
'team_type',
'hq_team',
'location',
Expand Down Expand Up @@ -163,6 +169,17 @@ class WinSerializer(ModelSerializer):
complete = BooleanField(read_only=True)
first_sent = DateTimeField(read_only=True)
last_sent = DateTimeField(read_only=True)
migrated_on = DateTimeField(read_only=True)

# legacy fields
company_name = CharField(read_only=True)
customer_name = CharField(read_only=True)
customer_job_title = CharField(read_only=True)
customer_email_address = CharField(read_only=True)
lead_officer_name = CharField(read_only=True)
lead_officer_email_address = CharField(read_only=True)
adviser_name = CharField(read_only=True)
adviser_email_address = CharField(read_only=True)

company_export = NestedRelatedField(
CompanyExport,
Expand All @@ -175,10 +192,22 @@ class Meta:
fields = (
'id',
'adviser',
# legacy field
'adviser_name',
# legacy field
'adviser_email_address',
'advisers',
'breakdowns',
'company',
# legacy field
'company_name',
'company_contacts',
# legacy field
'customer_name',
# legacy field
'customer_job_title',
# legacy field
'customer_email_address',
'complete',
'customer_location',
'business_type',
Expand All @@ -204,6 +233,10 @@ class Meta:
'is_personally_confirmed',
'is_line_manager_confirmed',
'lead_officer',
# legacy field
'lead_officer_name',
# legacy field
'lead_officer_email_address',
'team_type',
'hq_team',
'business_potential',
Expand All @@ -221,6 +254,7 @@ class Meta:
'company_export',
'first_sent',
'last_sent',
'migrated_on',
)

def create(self, validated_data):
Expand Down
91 changes: 91 additions & 0 deletions datahub/export_win/test/test_win_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,16 @@ def test_get(self):
'last_name': win.adviser.last_name,
'name': win.adviser.name,
},
# legacy field
'adviser_name': win.adviser_name,
# legacy field
'adviser_email_address': win.adviser_email_address,
'company': {
'id': str(win.company.id),
'name': win.company.name,
},
# legacy field
'company_name': win.company_name,
'country': {
'id': str(win.country.id),
'name': win.country.name,
Expand All @@ -217,6 +223,12 @@ def test_get(self):
'email': contact.email,
},
],
# legacy field
'customer_name': win.customer_name,
# legacy field
'customer_email_address': win.customer_email_address,
# legacy field
'customer_job_title': win.customer_job_title,
'audit': win.audit,
'business_potential': {
'id': str(win.business_potential.id),
Expand Down Expand Up @@ -259,8 +271,13 @@ def test_get(self):
'last_name': win.lead_officer.last_name,
'name': win.lead_officer.name,
},
# legacy field
'lead_officer_name': win.lead_officer_name,
# legacy field
'lead_officer_email_address': win.lead_officer_email_address,
'location': win.location,
'modified_on': format_date_or_datetime(win.modified_on),
'migrated_on': format_date_or_datetime(win.migrated_on),
'name_of_customer': win.name_of_customer,
'name_of_customer_confidential': win.name_of_customer_confidential,
'name_of_export': win.name_of_export,
Expand Down Expand Up @@ -727,7 +744,13 @@ def test_create_win_required_only(self, mock_export_win_serializer_notify):
'last_name': win.adviser.last_name,
'name': win.adviser.name,
},
# legacy field
'adviser_name': win.adviser_name,
# legacy field
'adviser_email_address': win.adviser_email_address,
'company': {'id': str(win.company_id), 'name': win.company.name},
# legacy field
'company_name': win.company_name,
'country': {'id': str(win.country_id), 'name': win.country.name},
'associated_programme': [
{
Expand All @@ -742,6 +765,12 @@ def test_create_win_required_only(self, mock_export_win_serializer_notify):
'email': contact.email,
},
],
# legacy field
'customer_name': win.customer_name,
# legacy field
'customer_email_address': win.customer_email_address,
# legacy field
'customer_job_title': win.customer_job_title,
'audit': win.audit,
'business_potential': {
'id': str(win.business_potential_id),
Expand Down Expand Up @@ -808,8 +837,13 @@ def test_create_win_required_only(self, mock_export_win_serializer_notify):
'last_name': win.lead_officer.last_name,
'name': win.lead_officer.name,
},
# legacy field
'lead_officer_name': win.lead_officer_name,
# legacy field
'lead_officer_email_address': win.lead_officer_email_address,
'location': win.location,
'modified_on': format_date_or_datetime(win.modified_on),
'migrated_on': format_date_or_datetime(win.migrated_on),
'name_of_customer': win.name_of_customer,
'name_of_customer_confidential': win.name_of_customer_confidential,
'name_of_export': win.name_of_export,
Expand Down Expand Up @@ -983,10 +1017,16 @@ def test_create_win_all_fields(self, mock_export_win_serializer_notify):
'last_name': win.adviser.last_name,
'name': win.adviser.name,
},
# legacy field
'adviser_name': win.adviser_name,
# legacy field
'adviser_email_address': win.adviser_email_address,
'company': {
'id': str(win.company_id),
'name': win.company.name,
},
# legacy field
'company_name': win.company_name,
'country': {
'id': str(win.country_id),
'name': win.country.name,
Expand All @@ -1004,6 +1044,12 @@ def test_create_win_all_fields(self, mock_export_win_serializer_notify):
'email': contact.email,
},
],
# legacy field
'customer_name': win.customer_name,
# legacy field
'customer_email_address': win.customer_email_address,
# legacy field
'customer_job_title': win.customer_job_title,
'audit': win.audit,
'business_potential': {
'id': str(win.business_potential_id),
Expand Down Expand Up @@ -1070,8 +1116,13 @@ def test_create_win_all_fields(self, mock_export_win_serializer_notify):
'last_name': win.lead_officer.last_name,
'name': win.lead_officer.name,
},
# legacy field
'lead_officer_name': win.lead_officer_name,
# legacy field
'lead_officer_email_address': win.lead_officer_email_address,
'location': win.location,
'modified_on': format_date_or_datetime(win.modified_on),
'migrated_on': format_date_or_datetime(win.migrated_on),
'name_of_customer': win.name_of_customer,
'name_of_customer_confidential': win.name_of_customer_confidential,
'name_of_export': win.name_of_export,
Expand Down Expand Up @@ -1104,6 +1155,8 @@ def test_create_win_all_fields(self, mock_export_win_serializer_notify):
'last_name': win_adviser.adviser.last_name,
'name': win_adviser.adviser.name,
},
# legacy field
'name': win_adviser.name,
'location': win_adviser.location,
'team_type': {
'id': str(win_adviser.team_type.id),
Expand Down Expand Up @@ -1376,10 +1429,16 @@ def test_update_win_all_fields(self):
'last_name': adviser.last_name,
'name': adviser.name,
},
# legacy field
'adviser_name': win.adviser_name,
# legacy field
'adviser_email_address': win.adviser_email_address,
'company': {
'id': str(company.id),
'name': company.name,
},
# legacy field
'company_name': win.company_name,
'country': {
'id': str(CountryConstant.canada.value.id),
'name': CountryConstant.canada.value.name,
Expand All @@ -1397,6 +1456,12 @@ def test_update_win_all_fields(self):
'email': contact.email,
},
],
# legacy field
'customer_name': win.customer_name,
# legacy field
'customer_email_address': win.customer_email_address,
# legacy field
'customer_job_title': win.customer_job_title,
'audit': win.audit,
'business_potential': {
'id': str(win.business_potential_id),
Expand Down Expand Up @@ -1466,8 +1531,13 @@ def test_update_win_all_fields(self):
'last_name': lead_officer.last_name,
'name': lead_officer.name,
},
# legacy field
'lead_officer_name': win.lead_officer_name,
# legacy field
'lead_officer_email_address': win.lead_officer_email_address,
'location': 'Park',
'modified_on': format_date_or_datetime(win.modified_on),
'migrated_on': format_date_or_datetime(win.migrated_on),
'name_of_customer': win.name_of_customer,
'name_of_customer_confidential': win.name_of_customer_confidential,
'name_of_export': win.name_of_export,
Expand Down Expand Up @@ -1500,6 +1570,8 @@ def test_update_win_all_fields(self):
'last_name': win_adviser.adviser.last_name,
'name': win_adviser.adviser.name,
},
# legacy field
'name': win_adviser.name,
'location': win_adviser.location,
'team_type': {
'id': str(win_adviser.team_type.id),
Expand Down Expand Up @@ -1590,10 +1662,16 @@ def test_doesnt_update_related_fields_when_not_supplied(self):
'last_name': win.adviser.last_name,
'name': win.adviser.name,
},
# legacy field
'adviser_name': win.adviser_name,
# legacy field
'adviser_email_address': win.adviser_email_address,
'company': {
'id': str(win.company.id),
'name': win.company.name,
},
# legacy field
'company_name': win.company_name,
'country': {
'id': str(win.country.id),
'name': win.country.name,
Expand All @@ -1611,6 +1689,12 @@ def test_doesnt_update_related_fields_when_not_supplied(self):
'email': contact.email,
},
],
# legacy field
'customer_name': win.customer_name,
# legacy field
'customer_email_address': win.customer_email_address,
# legacy field
'customer_job_title': win.customer_job_title,
'audit': win.audit,
'business_potential': {
'id': str(win.business_potential.id),
Expand Down Expand Up @@ -1653,8 +1737,13 @@ def test_doesnt_update_related_fields_when_not_supplied(self):
'last_name': win.lead_officer.last_name,
'name': win.lead_officer.name,
},
# legacy field
'lead_officer_name': win.lead_officer_name,
# legacy field
'lead_officer_email_address': win.lead_officer_email_address,
'location': win.location,
'modified_on': format_date_or_datetime(win.modified_on),
'migrated_on': format_date_or_datetime(win.migrated_on),
'name_of_customer': win.name_of_customer,
'name_of_customer_confidential': win.name_of_customer_confidential,
'name_of_export': win.name_of_export,
Expand Down Expand Up @@ -1689,6 +1778,8 @@ def test_doesnt_update_related_fields_when_not_supplied(self):
'last_name': win_adviser.adviser.last_name,
'name': win_adviser.adviser.name,
},
# legacy field
'name': win_adviser.name,
'location': win_adviser.location,
'team_type': {
'id': str(win_adviser.team_type.id),
Expand Down

0 comments on commit 0a030e5

Please sign in to comment.