lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.0-22-gdd309e4

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.0-22-gdd309e4



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  dd309e4e2279a1c648546f9417c3f624ccbd6f21 (commit)
       via  23882e231dd5c1c6c41fd627e63842ef2784a788 (commit)
      from  eac4d634d6e1170cf79484b5df02dd12c9be9eab (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=dd309e4e2279a1c648546f9417c3f624ccbd6f21

commit dd309e4e2279a1c648546f9417c3f624ccbd6f21
Author: Tomas Thor Jonsson <benregn@gmail.com>
Date:   Fri Oct 24 13:25:30 2014 +0200

    Add support for SE orgnr
    
    This also delegates some of the validation for the Swedish VAT module to
    the orgnr module.

diff --git a/stdnum/se/vat.py b/stdnum/se/orgnr.py
similarity index 54%
copy from stdnum/se/vat.py
copy to stdnum/se/orgnr.py
index 88a73ac..339f624 100644
--- a/stdnum/se/vat.py
+++ b/stdnum/se/orgnr.py
@@ -1,7 +1,8 @@
-# vat.py - functions for handling Swedish VAT numbers
+# orgnr.py - functions for handling Swedish organisation numbers
 # coding: utf-8
 #
-# Copyright (C) 2012, 2013 Arthur de Jong
+# Copyright (C) 2012-2015 Arthur de Jong
+# Copyright (C) 2014 Tomas Thor Jonsson
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -18,18 +19,21 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""VAT (Moms, Mervärdesskatt, Swedish VAT number).
+"""Orgnr (Organisationsnummer, Swedish company number).
 
-The Momsregistreringsnummer is used for VAT (Moms, Mervärdesskatt)
-purposes and consists of 12 digits of which the last two should be 01. The
-first 10 digits should have a valid Luhn checksum.
+The Orgnr (Organisationsnummer) is the national number to identify Swedish
+companies and consists of 10 digits. These are the first 10 digits in the
+Swedish VAT number, i.e. it's the VAT number without the 'SE' in front and
+the '01' at the end.
 
->>> validate('SE 123456789701')
-'123456789701'
->>> validate('123456789101')  # invalid check digits
+>>> validate('1234567897')
+'1234567897'
+>>> validate('1234567891')  # invalid check digits
 Traceback (most recent call last):
     ...
 InvalidChecksum: ...
+>>> format('123456-7897')
+'123456-7897'
 """
 
 from stdnum import luhn
@@ -40,28 +44,30 @@ from stdnum.util import clean
 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('SE'):
-        number = number[2:]
-    return number
+    return clean(number, ' -.').strip()
 
 
 def validate(number):
-    """Checks to see if the number provided is a valid VAT number. This
-    checks the length, formatting and check digit."""
+    """Checks to see if the number provided is a valid number. This checks
+    the length, formatting and check digit."""
     number = compact(number)
-    if not number.isdigit() or number[-2:] != '01':
+    if not number.isdigit():
         raise InvalidFormat()
-    if len(number) != 12:
+    if len(number) != 10:
         raise InvalidLength()
-    luhn.validate(number[:-2])
-    return number
+    return luhn.validate(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."""
+    """Checks to see if the number provided is a valid number. This checks
+    the length, formatting and check digit."""
     try:
         return bool(validate(number))
     except ValidationError:
         return False
+
+
+def format(number):
+    """Reformat the number to the standard format."""
+    number = compact(number)
+    return number[:6] + '-' + number[6:]
diff --git a/stdnum/se/vat.py b/stdnum/se/vat.py
index 88a73ac..3868828 100644
--- a/stdnum/se/vat.py
+++ b/stdnum/se/vat.py
@@ -20,9 +20,9 @@
 
 """VAT (Moms, Mervärdesskatt, Swedish VAT number).
 
-The Momsregistreringsnummer is used for VAT (Moms, Mervärdesskatt)
-purposes and consists of 12 digits of which the last two should be 01. The
-first 10 digits should have a valid Luhn checksum.
+The Momsregistreringsnummer is used for VAT (Moms, Mervärdesskatt) purposes
+and consists of 12 digits of which the last two should be 01. The first 10
+digits should have a valid Luhn checksum.
 
 >>> validate('SE 123456789701')
 '123456789701'
@@ -32,8 +32,8 @@ Traceback (most recent call last):
 InvalidChecksum: ...
 """
 
-from stdnum import luhn
 from stdnum.exceptions import *
+from stdnum.se import orgnr
 from stdnum.util import clean
 
 
@@ -52,9 +52,7 @@ def validate(number):
     number = compact(number)
     if not number.isdigit() or number[-2:] != '01':
         raise InvalidFormat()
-    if len(number) != 12:
-        raise InvalidLength()
-    luhn.validate(number[:-2])
+    orgnr.validate(number[:-2])
     return number
 
 

http://arthurdejong.org/git/python-stdnum/commit/?id=23882e231dd5c1c6c41fd627e63842ef2784a788

commit 23882e231dd5c1c6c41fd627e63842ef2784a788
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Apr 27 12:32:30 2015 +0200

    Add extra tests for the stdnum.ec.ruc module
    
    These numbers were found in various online sources.

diff --git a/tests/test_ec_ruc.doctest b/tests/test_ec_ruc.doctest
index 2f1065f..1bdaebf 100644
--- a/tests/test_ec_ruc.doctest
+++ b/tests/test_ec_ruc.doctest
@@ -1,7 +1,7 @@
 test_ec_ruc.doctest - more detailed doctests for stdnum.ec.ruc module
 
 Copyright (C) 2014 Jonathan Finlay
-Copyright (C) 2014 Arthur de Jong
+Copyright (C) 2014-2015 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
@@ -56,25 +56,173 @@ Normal natural RUC values (third digit less than 6) that 
should just work.
 Normal public RUC values (third digit is 6) that should just work.
 
 >>> numbers = '''
+... 0160000510001
 ... 0160001910001
+... 0160002210001
+... 0160037780001
+... 0260000250001
+... 0260000330001
+... 0260000760001
 ... 0260001060001
+... 0260001140001
+... 0360000230001
+... 0360000580001
 ... 0360001040001
+... 0360016230001
+... 0360023950001
+... 0460000130001
+... 0460000210001
+... 0460000560001
+... 0460000640001
+... 0460000720001
+... 0460001020001
+... 0460014860001
+... 0460020670001
+... 0460022020001
+... 0460022100001
+... 0460022370001
+... 0460023930001
+... 0460024310001
+... 0460024660001
+... 0460024740001
+... 0460026010001
+... 0460027250001
+... 0560000380001
 ... 0560000540001
+... 0560000700001
 ... 0660000280001
+... 0660000520001
 ... 0660000600001
+... 0660000790001
 ... 0660000870001
+... 0660000950001
+... 0660001090001
+... 0660001680001
+... 0660820400001
+... 0660828140001
+... 0660831360001
+... 0760000180001
+... 0760000260001
+... 0760000340001
+... 0760000850001
+... 0760000930001
+... 0760001070001
+... 0760001150001
+... 0760001230001
+... 0760001310001
+... 0760001900001
+... 0760033270001
+... 0860000160001
+... 0860000240001
+... 0860013300001
+... 0860014460001
+... 0860017480001
+... 0860019260001
+... 0860019500001
+... 0860032440001
+... 0960000490001
+... 0960000730001
+... 0960001700001
+... 0960005290001
+... 0960006420001
 ... 0968529830001
+... 0968566440001
+... 1060000180001
+... 1060000260001
+... 1060000340001
 ... 1060000420001
+... 1060000500001
 ... 1060000690001
+... 1060000770001
 ... 1060008080001
+... 1060014480001
+... 1060016930001
+... 1060018040001
+... 1060019520001
+... 1060021420001
 ... 1060024600001
+... 1160000670001
+... 1160000750001
+... 1160001130001
+... 1160001480001
+... 1160008140001
+... 1160028840001
+... 1160037400001
+... 1160039880001
+... 1160836120001
+... 1260000140001
+... 1260000220001
+... 1260000300001
+... 1260000490001
+... 1260000730001
+... 1260001700001
+... 1260001890001
+... 1260002000001
+... 1260002190001
+... 1260006340001
+... 1260006770001
+... 1260033820001
+... 1360000200001
+... 1360000390001
+... 1360000470001
 ... 1360000630001
+... 1360000710001
+... 1360001520001
+... 1360001600001
+... 1360001790001
+... 1360001870001
+... 1360002840001
+... 1360003300001
+... 1360014850001
+... 1360024570001
+... 1360029100001
+... 1360047940001
+... 1360052350001
+... 1360052430001
+... 1360055100001
+... 1360059280001
+... 1460000290001
+... 1460000370001
 ... 1560000780001
+... 1560001160001
+... 1560001240001
+... 1660000680001
+... 1660011020001
+... 1660012930001
+... 1760000150001
 ... 1760001040001
 ... 1760001550001
+... 1760003920001
+... 1760004060001
+... 1760004650001
 ... 1760009880001
+... 1760013560001
 ... 1768007390001
+... 1768022510001
+... 1768034600001
+... 1768045130001
+... 1768048820001
+... 1768085430001
+... 1768102970001
+... 1768119510001
+... 1768123380001
+... 1768133340001
 ... 1768152130001
+... 1768153450001
+... 1768155660001
+... 1860000130001
+... 1860000210001
+... 1860000480001
+... 1860000720001
+... 1860000800001
+... 1860000990001
+... 1860001020001
+... 1860001100001
+... 1865011360001
+... 1960001190001
+... 2060000150001
+... 2060000230001
+... 2160000480001
 ... 2160011760001
 ... '''
 >>> [x for x in numbers.splitlines() if x and not ruc.is_valid(x)]
@@ -84,25 +232,61 @@ Normal public RUC values (third digit is 6) that should 
just work.
 Normal juridical RUC values (third digit is 9) that should just work.
 
 >>> numbers = '''
+... 0190115798001
 ... 0190155722001
+... 0290001269001
+... 0290003288001
+... 0390027923001
+... 0490001883001
 ... 0490002669001
 ... 0590041920001
+... 0590052000001
+... 0690045389001
+... 0790015002001
 ... 0790024656001
 ... 0990138850001
+... 0990247536001
+... 0990459444001
+... 0991189432001
+... 0991208291001
+... 0991445854001
 ... 0992397535001
+... 0992563834001
+... 1090033456001
+... 1090109487001
 ... 1190015110001
+... 1190068389001
+... 1390001920001
 ... 1390007791001
+... 1390013678001
 ... 1390089410001
 ... 1390091474001
+... 1690012606001
 ... 1790011674001
+... 1790023508001
+... 1790045668001
 ... 1790085783001
+... 1790093204001
 ... 1790325083001
+... 1790451801001
+... 1790501469001
+... 1790517454001
+... 1790567699001
+... 1790834670001
+... 1791240448001
+... 1791280156001
 ... 1791280172001
+... 1791708040001
 ... 1791714350001
+... 1791891465001
+... 1791942167001
 ... 1792060346001
+... 1792079411001
 ... 1792141869001
+... 1792147638001
 ... 1792373255001
 ... 1890001323001
+... 1890003628001
 ... 1890037646001
 ... '''
 >>> [x for x in numbers.splitlines() if x and not ruc.is_valid(x)]

-----------------------------------------------------------------------

Summary of changes:
 stdnum/{be/vat.py => se/orgnr.py} |   54 ++++++-----
 stdnum/se/vat.py                  |   12 +--
 tests/test_ec_ruc.doctest         |  186 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 216 insertions(+), 36 deletions(-)
 copy stdnum/{be/vat.py => se/orgnr.py} (59%)


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/