Skip to content

Commit

Permalink
ICMSLST-1658 Sent EORI to CHIEF in correct field (RPA Trader ID).
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHolmes123 committed Aug 23, 2022
1 parent 6d1e29f commit e902567
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 20 deletions.
24 changes: 21 additions & 3 deletions mail/icms_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,32 @@ class AddressSerializer(serializers.Serializer):


class OrganisationSerializer(serializers.Serializer):
# TODO: ICMSLST-1658 Revisit turn / eori_number
# turn = serializers.CharField(max_length=17)
eori_number = serializers.CharField(max_length=17)

# "GB" + 12 or 15 digits.
eori_number = serializers.CharField(min_length=14, max_length=17)
name = serializers.CharField(max_length=80)
address = AddressSerializer()
start_date = serializers.DateField(required=False, allow_null=True)
end_date = serializers.DateField(required=False, allow_null=True)

def validate_eori_number(self, value: str) -> str:
"""Basic validation for EORI number.
https://www.tax.service.gov.uk/check-eori-number
"""

# This may need to be extended to include other prefixes (XI) in the future.
if not value.upper().startswith("GB"):
raise serializers.ValidationError("'eori_number' must start with 'GB' prefix")

# Example value: GB123456789012345
eori_number_length = len(value[2:])

if eori_number_length != 12 and eori_number_length != 15:
raise serializers.ValidationError("'eori_number' must start with 'GB' followed by 12 or 15 numbers")

return value


class GoodSerializer(serializers.Serializer):
description = serializers.CharField(max_length=2000)
Expand Down
2 changes: 1 addition & 1 deletion mail/libraries/lite_to_edifact_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def generate_lines_for_icms_licence(licence: LicencePayload) -> Iterable[chiefty
trader_address = trader.get("address")

yield chieftypes.Trader(
turn=trader.get("eori_number"),
rpa_trader_id=trader.get("eori_number"),
start_date=get_date_field(trader, "start_date"),
end_date=get_date_field(trader, "end_date"),
name=trader.get("name"),
Expand Down
4 changes: 2 additions & 2 deletions mail/tests/files/icms/icms_chief_licence_data_file_fa_dfl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
1\fileHeader\ILBDOTI\CHIEF\licenceData\202201011011\1\N
2\licence\IMA/2022/00002\insert\GBSIL1111111C\SIL\I\20220114\20220714
3\trader\665544332211\\\\DFL Organisation\line_1\line_2\line_3\line_4\\S881ZZ
3\trader\\GB665544332211000\\\DFL Organisation\line_1\line_2\line_3\line_4\\S881ZZ
4\country\US\\O
5\restrictions\Sample restrictions
6\line\1\\\\\Sample goods description\O\\\\\\\\\\
7\end\licence\6
8\licence\IMA/2022/00003\insert\GBSIL9089278D\SIL\I\20220114\20220714
9\trader\665544332211\\\\DFL Organisation\line_1\line_2\line_3\line_4\\S881ZZ
9\trader\\GB665544332211000\\\DFL Organisation\line_1\line_2\line_3\line_4\\S881ZZ
10\country\US\\O
11\restrictions\Sample restrictions
12\line\1\\\\\Sample goods description 2\O\\\\\\\\\\
Expand Down
2 changes: 1 addition & 1 deletion mail/tests/files/icms/icms_chief_licence_data_file_fa_oil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1\fileHeader\ILBDOTI\CHIEF\licenceData\202201011011\1\N
2\licence\IMA/2022/00001\insert\GBOIL2222222C\OIL\I\20220606\20250530
3\trader\112233445566\\\\org name\line_1\line_2\line_3\line_4\line_5\S118ZZ
3\trader\\GB112233445566000\\\org name\line_1\line_2\line_3\line_4\line_5\S118ZZ
4\country\\G001\O
5\restrictions\Some restrictions.|| Some more restrictions
6\line\1\\\\\Firearms, component parts thereof, or ammunition of any applicable commodity code, other than those falling under Section 5 of the Firearms Act 1968 as amended.\O\\\\\\\\\\
Expand Down
2 changes: 1 addition & 1 deletion mail/tests/files/icms/icms_chief_licence_data_file_fa_sil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1\fileHeader\ILBDOTI\CHIEF\licenceData\202201011011\1\N
2\licence\IMA/2022/00003\insert\GBSIL3333333H\SIL\I\20220629\20241229
3\trader\123456654321\\\\SIL Organisation\line_1\line_2\line_3\\\S227ZZ
3\trader\\GB123456654321000\\\SIL Organisation\line_1\line_2\line_3\\\S227ZZ
4\country\US\\O
5\restrictions\Sample restrictions
6\line\1\\\\\Sample goods description 1\Q\\030\\1\\\\\\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1\fileHeader\ILBDOTI\CHIEF\licenceData\202201011011\1\N
2\licence\IMA/2022/00004\insert\GBSAN4444444A\SAN\I\20220629\20241229
3\trader\112233445566\\\\Sanction Organisation\line_1\line_2\line_3\\\S227ZZ
3\trader\\GB112233445566000\\\Sanction Organisation\line_1\line_2\line_3\\\S227ZZ
4\country\RU\\O
5\restrictions\
6\line\1\7214993100\\\\\Q\\023\\26710\\\\\\
Expand Down
8 changes: 4 additions & 4 deletions mail/tests/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def setUp(self) -> None:
"start_date": "2022-06-06",
"end_date": "2025-05-30",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "org name",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_generate_icms_licence_file(self):
class TestBuildICMSLicenceDataFADFL(testcases.TestCase):
def setUp(self) -> None:
org_data = {
"eori_number": "665544332211",
"eori_number": "GB665544332211000",
"name": "DFL Organisation",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_generate_icms_licence_file(self):
class TestBuildICMSLicenceDataFASIL(testcases.TestCase):
def setUp(self) -> None:
org_data = {
"eori_number": "123456654321",
"eori_number": "GB123456654321000",
"name": "SIL Organisation",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_generate_icms_licence_file(self):
class TestBuildICMSLicenceDataSanction(testcases.TestCase):
def setUp(self) -> None:
org_data = {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "Sanction Organisation",
"address": {
"line_1": "line_1",
Expand Down
4 changes: 2 additions & 2 deletions mail/tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_icms_send_email_to_hmrc_fa_oil_e2e(self):
"start_date": "2022-06-06",
"end_date": "2025-05-30",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "org name",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_icms_send_email_to_hmrc_fa_dfl_e2e(self):
self.client.get(reverse("mail:set_all_to_reply_sent"))

org_data = {
"eori_number": "665544332211",
"eori_number": "GB665544332211000",
"name": "DFL Organisation",
"address": {
"line_1": "line_1",
Expand Down
31 changes: 26 additions & 5 deletions mail/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

from django.test import TestCase, override_settings
from parameterized import parameterized
from rest_framework.exceptions import ErrorDetail

from mail import icms_serializers
Expand Down Expand Up @@ -278,7 +279,7 @@ def test_valid_fa_oil_payload(self):
"start_date": "2022-06-06",
"end_date": "2025-05-30",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "org name",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -325,7 +326,7 @@ def test_at_least_one_country_field_is_set(self):
"start_date": "2022-06-06",
"end_date": "2025-05-30",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "org name",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -368,7 +369,7 @@ def test_valid_fa_dfl_payload(self):
"start_date": "2022-06-06",
"end_date": "2025-05-30",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "org name",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -453,6 +454,26 @@ def test_valid_sanction_payload(self):
for key in data.keys():
self.assertIn(key, serializer.validated_data)

@parameterized.expand(
[
("Prefix missing", "00000000000000", "'eori_number' must start with 'GB' prefix"),
("EORI too short", "GB00000", "Ensure this field has at least 14 characters."),
("EORI too long", "GB00000000000000000", "Ensure this field has no more than 17 characters."),
(
"EORI length not 12 or 15",
"GB0000000000000",
"'eori_number' must start with 'GB' followed by 12 or 15 numbers",
),
]
)
def test_eori_number_errors(self, name, eori, expected_error):
data = {"eori_number": eori}

serializer = icms_serializers.OrganisationSerializer(data=data)
self.assertFalse(serializer.is_valid())

self.assertEqual(str(serializer.errors["eori_number"][0]), expected_error, f"{name} test failed")


def get_valid_fa_sil_payload():
goods = [
Expand All @@ -473,7 +494,7 @@ def get_valid_fa_sil_payload():
"start_date": "2022-06-29",
"end_date": "2024-12-29",
"organisation": {
"eori_number": "123456654321",
"eori_number": "GB123456654321000",
"name": "SIL Organisation",
"address": {
"line_1": "line_1",
Expand Down Expand Up @@ -506,7 +527,7 @@ def get_valid_sanctions_payload():
"start_date": "2022-06-29",
"end_date": "2024-12-29",
"organisation": {
"eori_number": "112233445566",
"eori_number": "GB112233445566000",
"name": "Sanction Organisation",
"address": {
"line_1": "line_1",
Expand Down

0 comments on commit e902567

Please sign in to comment.