|
1 | 1 | # pvn.py - functions for handling Latvian PVN (VAT) numbers |
2 | 2 | # coding: utf-8 |
3 | 3 | # |
4 | | -# Copyright (C) 2012-2019 Arthur de Jong |
| 4 | +# Copyright (C) 2012-2026 Arthur de Jong |
5 | 5 | # |
6 | 6 | # This library is free software; you can redistribute it and/or |
7 | 7 | # modify it under the terms of the GNU Lesser General Public |
|
23 | 23 | The PVN is a 11-digit number that can either be a reference to a legal |
24 | 24 | entity (in which case the first digit > 3) or a natural person (in which |
25 | 25 | case it should be the same as the personal code (personas kods)). Personal |
26 | | -codes start with 6 digits to denote the birth date in the form ddmmyy. |
| 26 | +codes start "32". Older personal codes start with 6 digits to denote the birth |
| 27 | +date in the form ddmmyy. |
| 28 | +
|
| 29 | +More information: |
| 30 | +
|
| 31 | +* https://en.wikipedia.org/wiki/National_identification_number#Latvia |
27 | 32 |
|
28 | 33 | >>> validate('LV 4000 3521 600') |
29 | 34 | '40003521600' |
30 | 35 | >>> validate('40003521601') # invalid check digit |
31 | 36 | Traceback (most recent call last): |
32 | 37 | ... |
33 | 38 | InvalidChecksum: ... |
34 | | ->>> validate('161175-19997') # personal code |
| 39 | +>>> validate('161175-19997') # personal code, old format |
35 | 40 | '16117519997' |
36 | 41 | >>> validate('161375-19997') # invalid date |
37 | 42 | Traceback (most recent call last): |
38 | 43 | ... |
39 | 44 | InvalidComponent: ... |
| 45 | +>>> validate('328673-00679') # personal code, new format |
| 46 | +'32867300679' |
| 47 | +>>> validate('328673-00677') # personal code, new format |
| 48 | +Traceback (most recent call last): |
| 49 | + ... |
| 50 | +InvalidChecksum: ... |
40 | 51 | """ |
41 | 52 |
|
42 | 53 | from __future__ import annotations |
@@ -101,6 +112,10 @@ def validate(number: str) -> str: |
101 | 112 | # legal entity |
102 | 113 | if checksum(number) != 3: |
103 | 114 | raise InvalidChecksum() |
| 115 | + elif number.startswith('32'): |
| 116 | + # personal code without a date of birth (issued from July 2017 onwards) |
| 117 | + if calc_check_digit_pers(number[:-1]) != number[-1]: |
| 118 | + raise InvalidChecksum() |
104 | 119 | else: |
105 | 120 | # natural resident, check if birth date is valid |
106 | 121 | get_birth_date(number) |
|
0 commit comments