Skip to content

Add support for Faroe Islands TIN #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions stdnum/fo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# __init__.py - collection of Faroe Islands numbers
# coding: utf-8
#
# Copyright (C) 2022 Leandro Regueiro
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

"""Collection of Faroe Islands numbers."""

# provide aliases
from stdnum.fo import vn as vat # noqa: F401
87 changes: 87 additions & 0 deletions stdnum/fo/vn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# vn.py - functions for handling Faroe Islands V-number numbers
# coding: utf-8
#
# Copyright (C) 2022 Leandro Regueiro
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

"""V-number (Faroe Islands tax number).

In the Faroe Islands the legal persons TIN equals the V number issued by the
Faroese Tax Administration.

It is a consecutive number.

More information:

* https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Faroe-islands-TIN.pdf

>>> validate('623857')
'623857'
>>> validate('602 590')
'602590'
>>> validate('1234')
Traceback (most recent call last):
...
InvalidLength: ...
>>> validate('12345X')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> format('602 590')
'602590'
""" # noqa: E501

from stdnum.exceptions import *
from stdnum.util import clean, isdigits


def compact(number):
"""Convert the number to the minimal representation.

This strips the number of any valid separators and removes surrounding
whitespace.
"""
number = clean(number, ' -.').upper().strip()
if number.startswith('FO'):
return number[2:]
return number


def validate(number):
"""Check if the number is a valid Faroe Islands V-number number.

This checks the length and formatting.
"""
number = compact(number)
if len(number) != 6:
raise InvalidLength()
if not isdigits(number):
raise InvalidFormat()
return number


def is_valid(number):
"""Check if the number is a valid Faroe Islands V-number number."""
try:
return bool(validate(number))
except ValidationError:
return False


def format(number):
"""Reformat the number to the standard presentation format."""
return compact(number)
172 changes: 172 additions & 0 deletions tests/test_fo_vn.doctest
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
test_fo_vn.doctest - more detailed doctests for stdnum.fo.vn module

Copyright (C) 2022 Leandro Regueiro

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA


This file contains more detailed doctests for the stdnum.fo.vn module. It
tries to test more corner cases and detailed functionality that is not really
useful as module documentation.

>>> from stdnum.fo import vn


Tests for some corner cases.

>>> vn.validate('623857')
'623857'
>>> vn.validate('602 590')
'602590'
>>> vn.validate('563.609')
'563609'
>>> vn.validate('FO384941')
'384941'
>>> vn.format('623857')
'623857'
>>> vn.format('602 590')
'602590'
>>> vn.format('33 28 28')
'332828'
>>> vn.format('563.609')
'563609'
>>> vn.format('FO384941')
'384941'
>>> vn.validate('12345')
Traceback (most recent call last):
...
InvalidLength: ...
>>> vn.validate('12345X')
Traceback (most recent call last):
...
InvalidFormat: ...


These have been found online and should all be valid numbers.

>>> numbers = '''
...
... 602 590
... 616 923
... 557 692
... 568 597
... 568 031
... 605 174
... 623857
... 323853
... 323853
... 549118
... 330833
... 345490
... 589306
... 537.535
... 563.609
... 478 865
... 537.543
... 463000
... 55 16 00
... 345334
... 403369
... 630713
... 369497
... 623016
... 636568
... 322407
... 538485
... 452432
... 339849
... 489042
... 328871
... 324213
... 552569
... 575712
... 328944
... 504572
... 322059
... 308382
... 502855
... 554375
... 33 28 28
... 606294
... 309273
... 353477
... 617105
... 539813
... 328863
... 321079
... 607436
... 401900
... 550558
... 569682
... 637114
... 628980
... 522821
... 427888
... 401900
... 355216
... 619558
... 437.115
... 603937
... 355186
... 476897
... 366161
... 620092
... 546.089
... 551.023
... 408638
... 498.289
... 601470
... 587974
... 641154
... 636223
... 488135
... 619388
... 625485
... 627976
... 576174
... 576174
... 403687
... 401900
... 625590
... 374989
... 623792
... 623385
... 585335
... 331538
... 613606
... 597570
... 589.810
... FO384941
... 559679
... 443921
... 617121
... 620785
... 638722
... 550612
... 509078
... 344338
... 579319
... 602221
... 516244
... 33 28 28
... 379778
... 604097
... 578 509
... 519324
...
... '''
>>> [x for x in numbers.splitlines() if x and not vn.is_valid(x)]
[]