Validate and store VAT Information Exchange System (VIES) data in Django.
Project description
Documentation |
Issues |
Changelog |
Funding 💚
Django-VIES
Validate and store VAT Information Exchange System (VIES) data in Django.
Installation
python3 -m pip install django-vies
Usage
VATINField for models
from django.db import models
from vies.models import VATINField
class Company(models.Model):
name = models.CharField(max_length=100)
vat = VATINField(blank=True, null=True)
VATIN wrapper class, allows access to result.
>>> from vies.types import VATIN
>>> vat = VATIN('LU', '26375245')
>>> vat.is_valid()
True
>>> vat.data
{
'countryCode': 'LU',
'vatNumber': '26375245',
'requestDate': datetime.date(2020, 4, 13),
'valid': True,
'name': 'AMAZON EUROPE CORE S.A R.L.',
'address': '38, AVENUE JOHN F. KENNEDY\nL-1855 LUXEMBOURG'
}
You can also use the classmethod VATIN.from_str to create VATIN from
str.
>>> from vies.types import VATIN
>>> vat = VATIN.from_str('LU26375245')
>>> vat.is_valid()
True
The VIES API endpoint can be very unreliable and seems to have an IP
based access limit. Therefore the VATINField does NOT perform API
based validation by default. It needs to be explicitly turned on or
performed in a separate task.
e.g.
from vies.models import VATINField
from vies.validators import VATINValidator
class Company(models.Model):
name = models.CharField(max_length=100)
vat = VATINField(validators=[VATINValidator(verify=True, validate=True)])
validate=True will tell the validator to validate against the VIES
API. verify is enabled on by default and will only verify that the
VATIN matches the country's specifications.
It is recommended to perform VIES API validation inside an asynchronous task.
e.g. using celery
from celery import shared_task
from vies.models import VATINField
from vies.types import VATIN
from django.core.exceptions import ValidationError
class Company(models.Model):
name = models.CharField(max_length=100)
vat = VATINField()
vat_is_valid = models.BooleanField(default=False)
def __init__(self, *args, **kwargs):
super(Company, self).__init__(*args, **kwargs)
self.__vat = self.vat
def save(self, *args, **kwargs):
if self.__vat != self.vat:
validate_vat_field.delay(self.pk)
super(Company, self).save(*args, **kwargs)
self.__vat = self.vat
def refresh_from_db(self, *args, **kwargs):
super(Company, self).refresh_from_db(*args, **kwargs)
self.__vat = self.vat
@shared_task
def validate_vat_field(company_id):
company = Company.objects.get(pk=company_id)
vat = VATIN.from_str(company.vat)
try:
vat.validate()
except ValidationError:
company.vat_is_valid = False
else:
company.vat_is_valid = True
finally:
company.save(update_fields=["vat_is_valid"])
You can also use
celery.current_app.send_task('validate_vat_field', kwargs={"company_id": self.pk})
to call asynchronous task to avoid circular import errors.
Translations
Feel free to contribute translations, it's simple!
cd vies
django-admin makemessages -l $YOUR_COUNTRY_CODE
Just edit the generated PO file. Pull-Requests are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_vies-6.3.0.tar.gz.
File metadata
- Download URL: django_vies-6.3.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
126ab6d81275ec73218a710a0e019080c3f0f52c61a0a9925aa914ff46289c23
|
|
| MD5 |
4e915210b54dc9606c6e19b5d6b1f2e2
|
|
| BLAKE2b-256 |
72a0bf52e65cd4cf4b32ff68185e08186decb0bd967062350d17d05f0d92d708
|
Provenance
The following attestation bundles were made for django_vies-6.3.0.tar.gz:
Publisher:
release.yml on codingjoe/django-vies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_vies-6.3.0.tar.gz -
Subject digest:
126ab6d81275ec73218a710a0e019080c3f0f52c61a0a9925aa914ff46289c23 - Sigstore transparency entry: 911208435
- Sigstore integration time:
-
Permalink:
codingjoe/django-vies@ee3e9ad71a59d1bcb4d190e876743344c1b95573 -
Branch / Tag:
refs/tags/6.3.0 - Owner: https://github.com/codingjoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee3e9ad71a59d1bcb4d190e876743344c1b95573 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_vies-6.3.0-py3-none-any.whl.
File metadata
- Download URL: django_vies-6.3.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d86ce43e7023e6ee69b0fbcc87ae04f0eb5eff8e3c3b959481fc34889f793a46
|
|
| MD5 |
a8d779f3957be83d6c8a701dbf57afd4
|
|
| BLAKE2b-256 |
45f26e737ecb042b73a2e9bd30ee792c8dd0d881f8d26ed2ae0d0700dd2ba6b4
|
Provenance
The following attestation bundles were made for django_vies-6.3.0-py3-none-any.whl:
Publisher:
release.yml on codingjoe/django-vies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_vies-6.3.0-py3-none-any.whl -
Subject digest:
d86ce43e7023e6ee69b0fbcc87ae04f0eb5eff8e3c3b959481fc34889f793a46 - Sigstore transparency entry: 911208467
- Sigstore integration time:
-
Permalink:
codingjoe/django-vies@ee3e9ad71a59d1bcb4d190e876743344c1b95573 -
Branch / Tag:
refs/tags/6.3.0 - Owner: https://github.com/codingjoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee3e9ad71a59d1bcb4d190e876743344c1b95573 -
Trigger Event:
release
-
Statement type: