Skip to content
Snippets Groups Projects
Commit 4505dad3 authored by Marte Fossum's avatar Marte Fossum
Browse files

Add support for SO numbers

parent bdcd09d5
No related branches found
No related tags found
1 merge request!351Add support for SO numbers
Pipeline #160265 passed
This commit is part of merge request !351. Comments created here will be created in the context of that merge request.
......@@ -14,10 +14,36 @@ def camel_to_snake(s: str) -> str:
def is_valid_id_number(input_digits: str) -> bool:
"""
Checks whether the input represents a valid national ID number (fødselsnummer) or a valid D-number.
Checks whether the input represents a valid national ID number (fødselsnummer), a valid D-number
or a valid SO-number.
"""
is_dnumber = int(input_digits[0:1]) >= 4
return is_valid_norwegian_national_id_number(input_digits, is_dnumber)
return is_valid_norwegian_national_id_number(
input_digits, is_dnumber
) or is_valid_so_number(input_digits)
def is_valid_so_number(input_digits: str) -> bool:
"""
Checks if SO numbers are allowed and if so, check that it is valid.
"""
if not settings.ALLOW_SO_NUMBERS:
return False
SO_NUMBER = False
day, month, year, pnr = (
input_digits[0:2],
int(input_digits[2:4]),
input_digits[4:6],
input_digits[6:],
)
if pnr[0] != "1":
return False
if month > 50:
SO_NUMBER = True
month -= 50
input_digits = day + str(month) + year + pnr
return SO_NUMBER and _check_birthdate(input_digits, is_dnumber=False)
def is_valid_norwegian_national_id_number(input_digits: str, is_dnumber: bool) -> bool:
......
......@@ -352,3 +352,5 @@ IGA_CLIENT = {
"url": "http://example.com/cerebrum/",
"headers": {"X-Gravitee-Api-Key": "<KEY>"},
}
ALLOW_SO_NUMBERS = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment