8000 Add support for Montenegro TIN · unho/python-stdnum@7e827c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e827c5

Browse files
committed
Add support for Montenegro TIN
Closes arthurdejong#223.
1 parent 2907676 commit 7e827c5

File tree

3 files changed

+423
-0
lines changed

3 files changed

+423
-0
lines changed

stdnum/me/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
# 02110-1301 USA
2020

2121
"""Collection of Montenegro numbers."""
22+
23+
# provide aliases
24+
from stdnum.me import pib as vat # noqa: F401

stdnum/me/pib.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# pib.py - functions for handling Montenegro PIB numbers
2+
# coding: utf-8
3+
#
4+
# Copyright (C) 2022 Leandro Regueiro
5+
#
6+
# This library is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
#
11+
# This library is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with this library; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19+
# 02110-1301 USA
20+
21+
"""PIB (Poreski Identifikacioni Broj, Montenegro tax number).
22+
23+
This number consists of 8 digits.
24+
25+
More information:
26+
27+
* http://www.pretraga.crps.me:8083/
28+
* https://www.vatify.eu/montenegro-vat-number.html
29+
30+
>>> validate('02655284')
31+
'02655284'
32+
>>> validate('12345')
33+
Traceback (most recent call last):
34+
...
35+
InvalidLength: ...
36+
>>> validate('12345XYZ')
37+
Traceback (most recent call last):
38+
...
39+
InvalidFormat: ...
40+
>>> format('02655284')
41+
'02655284'
42+
"""
43+
44+
from stdnum.exceptions import *
45+
from stdnum.util import clean, isdigits
46+
47+
48+
def compact(number):
49+
"""Convert the number to the minimal representation.
50+
51+
This strips the number of any valid separators and removes surrounding
52+
whitespace.
53+
"""
54+
return clean(number, ' ')
55+
56+
57+
def validate(number):
58+
"""Check if the number is a valid Montenegro PIB number.
59+
60+
This checks the length and formatting.
61+
"""
62+
number = compact(number)
63+
if len(number) != 8:
64+
raise InvalidLength()
65+
if not isdigits(number):
66+
raise InvalidFormat()
67+
return number
68+
69+
70+
def is_valid(number):
71+
"""Check if the number is a valid Montenegro PIB number."""
72+
try:
73+
return bool(validate(number))
74+
except ValidationError:
75+
return False
76+
77+
78+
def format(number):
79+
"""Reformat the number to the standard presentation format."""
80+
return compact(number)

0 commit comments

Comments
 (0)
0