diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2017-03-19 15:28:27 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2017-03-25 11:47:25 +0100 |
commit | c957318aacacf6496e7fef6198f6b9e791552b70 (patch) | |
tree | cecc4099152dfc8862b4ae62da45821448d9f80c /stdnum/mc/tva.py | |
parent | 5b4385732f6b7d7b5959e742881e20d63ec58183 (diff) |
Add support for Monaco VAT number
The number uses the French TVA number but, unlike normal French VAT
numbers, they are not valid French SIREN numbers.
See https://github.com/arthurdejong/python-stdnum/issues/46
Diffstat (limited to 'stdnum/mc/tva.py')
-rw-r--r-- | stdnum/mc/tva.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/stdnum/mc/tva.py b/stdnum/mc/tva.py new file mode 100644 index 0000000..dacf803 --- /dev/null +++ b/stdnum/mc/tva.py @@ -0,0 +1,63 @@ +# tva.py - functions for handling Monacan TVA numbers +# coding: utf-8 +# +# Copyright (C) 2017 Arthur de Jong +# +# 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 + +"""n° TVA (taxe sur la valeur ajoutée, Monacan VAT number). + +For VAT purposes Monaco is treated as territory of France. The number is +also validated the same as the French TVA, except that it is not based on +a French SIREN. + +>>> compact('53 0000 04605') +'FR53000004605' +>>> validate('53 0000 04605') +'FR53000004605' +>>> validate('FR 61 954 506 077') # French numbers are invalid +Traceback (most recent call last): + ... +InvalidComponent: ... +""" + +from stdnum.exceptions import * +from stdnum.util import clean +from stdnum.fr import tva + + +def compact(number): + """Convert the number to the minimal representation. This strips the + number of any valid separators and removes surrounding whitespace.""" + return 'FR' + tva.compact(number) + + +def validate(number): + """Checks to see if the number provided is a valid VAT number. This + checks the length, formatting and check digit.""" + number = tva.validate(number) + if number[2:5] != '000': + raise InvalidComponent() + return 'FR' + number + + +def is_valid(number): + """Checks to see if the number provided is a valid VAT number. This + checks the length, formatting and check digit.""" + try: + return bool(validate(number)) + except ValidationError: + return False |