{"id":13469324,"url":"https://github.com/codingjoe/django-vies","last_synced_at":"2025-05-06T16:39:45.058Z","repository":{"id":13313243,"uuid":"15999779","full_name":"codingjoe/django-vies","owner":"codingjoe","description":"European VIES VAT field for django based on","archived":false,"fork":false,"pushed_at":"2025-05-02T09:20:31.000Z","size":193,"stargazers_count":46,"open_issues_count":2,"forks_count":30,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-02T10:30:54.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://djangosnippets.org/snippets/1512/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codingjoe.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-01-17T13:02:52.000Z","updated_at":"2025-05-02T09:20:34.000Z","dependencies_parsed_at":"2024-06-11T21:46:06.849Z","dependency_job_id":"f50658be-5c20-4c3b-b1fc-3369ad4af22f","html_url":"https://github.com/codingjoe/django-vies","commit_stats":{"total_commits":277,"total_committers":24,"mean_commits":"11.541666666666666","dds":0.6101083032490975,"last_synced_commit":"159c1e88b199285d7d4e6597fe3f50e070b4faba"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingjoe%2Fdjango-vies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingjoe%2Fdjango-vies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingjoe%2Fdjango-vies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingjoe%2Fdjango-vies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codingjoe","download_url":"https://codeload.github.com/codingjoe/django-vies/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252722001,"owners_count":21793940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:33.555Z","updated_at":"2025-05-06T16:39:45.038Z","avatar_url":"https://github.com/codingjoe.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"===========\nDjango-VIES\n===========\n\nValidate and store VAT Information Exchange System (VIES) data in Django.\n\nInstallation\n------------\n\n.. code:: shell\n\n    python3 -m pip install django-vies\n\nUsage\n-----\n\n``VATINField`` for models\n\n.. code:: python\n\n    from django.db import models\n    from vies.models import VATINField\n\n    class Company(models.Model):\n        name = models.CharField(max_length=100)\n        vat = VATINField(blank=True, null=True)\n\n``VATIN`` wrapper class, allows access to result.\n\n.. code:: python\n\n    \u003e\u003e\u003e from vies.types import VATIN\n    \u003e\u003e\u003e vat = VATIN('LU', '26375245')\n    \u003e\u003e\u003e vat.is_valid()\n    True\n    \u003e\u003e\u003e vat.data\n    {\n        'countryCode': 'LU',\n        'vatNumber': '26375245',\n        'requestDate': datetime.date(2020, 4, 13),\n        'valid': True,\n        'name': 'AMAZON EUROPE CORE S.A R.L.',\n        'address': '38, AVENUE JOHN F. KENNEDY\\nL-1855  LUXEMBOURG'\n    }\n\n\nYou can also use the classmethod ``VATIN.from_str`` to create ``VATIN``\nfrom ``str``.\n\n.. code:: python\n\n    \u003e\u003e\u003e from vies.types import VATIN\n    \u003e\u003e\u003e vat = VATIN.from_str('LU26375245')\n    \u003e\u003e\u003e vat.is_valid()\n    True\n\nThe VIES API endpoint can be very unreliable and seems to have an IP based access limit.\nTherefore the ``VATINField`` does NOT perform API based validation by default. It needs\nto be explicitly turned on or performed in a separate task.\n\ne.g.\n\n.. code:: python\n\n    from vies.models import VATINField\n    from vies.validators import VATINValidator\n\n\n    class Company(models.Model):\n        name = models.CharField(max_length=100)\n        vat = VATINField(validators=[VATINValidator(verify=True, validate=True)])\n\n``validate=True`` will tell the validator to validate against the VIES API.\n``verify`` is enabled on by default and will only verify that the VATIN matches the country's specifications.\n\nIt is recommended to perform VIES API validation inside an asynchronous task.\n\ne.g. using celery\n\n.. code:: python\n\n    from celery import shared_task\n    from vies.models import VATINField\n    from vies.types import VATIN\n    from django.core.exceptions import ValidationError\n\n\n    class Company(models.Model):\n        name = models.CharField(max_length=100)\n        vat = VATINField()\n        vat_is_valid = models.BooleanField(default=False)\n\n        def __init__(self, *args, **kwargs):\n            super(Company, self).__init__(*args, **kwargs)\n            self.__vat = self.vat\n\n        def save(self, *args, **kwargs):\n            if self.__vat != self.vat:\n                validate_vat_field.delay(self.pk)\n            super(Company, self).save(*args, **kwargs)\n            self.__vat = self.vat\n\n        def refresh_from_db(self, *args, **kwargs)\n            super(Company, self).refresh_from_db(*args, **kwargs)\n            self.__vat = self.vat\n\n\n    @shared_task\n    def validate_vat_field(company_id):\n        company = Company.objects.get(pk=company_id)\n        vat = VATIN.from_str(company.vat)\n        try:\n            vat.validate()\n        except ValidationError:\n            company.vat_is_valid = False\n        else:\n            company.vat_is_valid = True\n        finally:\n            company.save(update_fields=['vat_is_valid'])\n\nYou 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**.\n\nTranslations\n------------\n\nFeel free to contribute translations, it's simple!\n\n.. code:: shell\n\n    cd vies\n    django-admin makemessages -l $YOUR_COUNTRY_CODE\n\nJust edit the generated PO file. Pull-Requests are welcome!\n\n\nLicense\n-------\nThe MIT License (MIT)\n\nCopyright (c) 2014-2016 Johannes Hoppe\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingjoe%2Fdjango-vies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodingjoe%2Fdjango-vies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingjoe%2Fdjango-vies/lists"}