iconfinder / pyvat Goto Github PK
View Code? Open in Web Editor NEWVAT validation for Python
License: Other
VAT validation for Python
License: Other
Seems as of today the VIES service has changed their XML response format.
pyvat.check_vat_number("DK12345678")
ValueError: expected response XML root element to be a SOAP envelope
The XML appears to be missing the soap:Envelope
which the current implementation expects:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><ns2:checkVatResponse xmlns:ns2="urn:ec.europa.eu:taxud:vies:services:checkVat:types"><ns2:countryCode>DK</ns2:countryCode><ns2:vatNumber></ns2:vatNumber><ns2:requestDate>2022-08-12+02:00</ns2:requestDate><ns2:valid>false</ns2:valid><ns2:name>---</ns2:name><ns2:address>---</ns2:address></ns2:checkVatResponse></env:Body></env:Envelope>
As far as I can see from the code, it does not implement the VAT rate change from Germany (DE), which was 16% in 2020: https://www.avalara.com/vatlive/en/vat-news/german-vat-rate-returns-to-19--1-jan-2021.html
Is there any concept / rules in the code base you'd like us to apply in case we were patching the module to support varying rates over time?
File "/opt/hostedtoolcache/Python/3.7.14/x64/lib/python3.7/site-packages/pyvat/__init__.py", line 212, in check_vat_number
country_code)
File "/opt/hostedtoolcache/Python/3.7.14/x64/lib/python3.7/site-packages/pyvat/registries.py", line 136, in check_vat_number
raise ServerError(fault_code)
pyvat.exceptions.ServerError: ServerError: MS_UNAVAILABLE
Hi, I am getting this error from a few days. Can someone confirm this problem?
Hi,
pyvat.is_vat_number_format_valid("ATU76127777") => is True
pyvat.is_vat_number_format_valid("76127777", country_code="AT") => is False but should be also True
I could private a fix if the maintainer except that this is a bug.
Valid VAT numbers for Croatia don't seem to be valid according to your libraries.
I have tried to track down this issue. It looks like pyvat.VAT_NUMBER_EXPRESSIONS['hr']
is not set.
We might send you a pull request for this if you're ok.
======================================================================
1) ERROR: check_vat_number('..', country_code='..')
----------------------------------------------------------------------
Traceback (most recent call last):
tests/test_validators.py line 257 in test_dk__country_code
check_vat_number(vat_number, country_code)
pyvat/__init__.py line 212 in check_vat_number
country_code)
pyvat/registries.py line 133 in check_vat_number
raise ServerError(fault_code)
ServerError: ServerError: MS_MAX_CONCURRENT_REQ
-------------------- >> begin captured logging << --------------------
urllib3.connectionpool: DEBUG: Starting new HTTP connection (1): ec.europa.eu:80
urllib3.connectionpool: DEBUG: http://ec.europa.eu:80 "POST /taxation_customs/vies/services/checkVatService HTTP/1.1" 200 None
--------------------- >> end captured logging << ---------------------
-----------------------------------------------------------------------------
Hi,
I tried validating this VAT code for Finland: '12345678--' and it returned True, even though it contains two dashes in the end (which is not ok).
Maybe you could add this to the test tests/test_validators.py for FI (Finland):
('12345678--', False),
Not sure if this is intended behaviour, but with the UK leaving the EU and the recent changes using the PyVAT to check for vat numbers in the GB now throws and error:
NotImplementedError: cannot determine VAT charge for a sale of item <ItemType.generic_electronic_service: 2> between <pyvat.Party: country code = GB, is business = True> and <pyvat.Party: country code = GB, is business = True>
This is with Pyvat v1.3.7.
Is the library no longer supporting GB vat?
Hello there and thanks for developing this great package!
Brexit will be finalised on December 31, 2020.
Are there any plans to remove UK from a list of EU countries? Or better yet, configure it to stay there until Dec 31?
Thank you!
We (ungleich.ch) are interested in using this module with residency in CH. Basically the rule set that applies is:
I believe that CH as a non-EU country could become a sample of a standard case for trading from outside the EU, as I suspect that ruleset for other countries are very similar.
Are you open for integrating non-EU rules into this module, too?
To prevent locking if server is not responding for some time, can you add support for timeout
argument for requests
response = requests.post(
self.CHECK_VAT_SERVICE_URL,
data=request_data.encode('utf-8'),
headers={
'Content-Type': 'text/xml; charset=utf-8',
}
)
https://requests.readthedocs.io/en/master/user/advanced/#timeouts
for compatibility, you can set default value = None
Hey,
It looks like your pip package is not updated, it's the 1.3.1 version from 2014, with the old VAT rates.
Would it be possible to update it?
Isle of Man (country code: IM
) share its VAT registry with the UK. Same thing for Monaco (country code: MC
), which is sharing its registry with France.
These exceptions are not supported by pyvat
:
>>> from pyvat import is_vat_number_format_valid
>>> print is_vat_number_format_valid('GB 000 8920 15', 'IM')
None
>>> print is_vat_number_format_valid('FR 12 0000 4520 2', 'MC')
None
Here I expect is_vat_number_format_valid()
method to return True
in the two example above, as if the query was performed against the canonical country:
>>> print is_vat_number_format_valid('FR 12 0000 4520 2', 'FR')
True
>>> print is_vat_number_format_valid('GB 000 8920 15', 'GB')
True
Hello folks,
I am not sure what would be the best way to contact the maintainers of the package, but I want to let you know that I am creating an RPM package with pyvat
which will be called python3-pyvat
. I created a ticket in bugzilla for this https://bugzilla.redhat.com/show_bug.cgi?id=2109069 and it will eventually be available for Fedora.
There is not much action need from your side other than reading through this message and possibly advertising the availability in Fedora when that happens. Also, if you see any issues with having pyvat
packaged please let me know slightly_smiling_face
Cheers
Some companies that have no physical establishment in EU are still subject to VAT and the EU provide them a VAT number starting with "EU", e.g. : EU372041333 for OpenAI
Would it be possible to add support for this kind of VAT number ?
Last version is 29 Dec 2014
I have 36,000 VATs that I need to verify. I split the data into chunks of 100 with a time gap of 2 seconds. Even then, I am encountering the error ServerError: MS_MAX_CONCURRENT_REQ.
How do I get around this?
The latest version on PyPI
is 1.3.1
released back in 2014. But, I see there have been several improvements since then. Are you guys planning on releasing the newest version to PyPI?
According to the documentation, the return value of check_vat_number is either True, False or None.
Actually, it returns a VatNumberCheckResult object.
according to ebook VAT has changed in 2019 and seems not inline with the values given by pyvat?
am-I right?
Unittests might fail if the VIES registry API is down. This happened to me in the last few weeks.
To prevent this failure, I mocked registries responses with the code:
import unittest
import arrow
from httmock import all_requests, response, HTTMock
try:
from lxml import etree
except ImportError:
from xml.etree import ElementTree as etree
from pyvat import check_vat_number, is_vat_number_format_valid
class TestVIES(unittest.TestCase):
@all_requests
def mock_registry_response(self, url, request):
""" Mock VIES registry responses. """
# Parse request
soap_query = etree.fromstring(request.body)
VAT_NS = '{urn:ec.europa.eu:taxud:vies:services:checkVat:types}'
country_code = soap_query.find('.//{}countryCode'.format(VAT_NS)).text
vat_number = soap_query.find('.//{}vatNumber'.format(VAT_NS)).text
# Check VAT number
assert is_vat_number_format_valid(vat_number, country_code) is True
# Normalize parsed values
country_code = country_code.strip().upper()
vat_number = ''.join([c for c in vat_number if c.isalnum()]).upper()
# Build-up response
request_date = arrow.now().format('YYYY-MM-DDZZ')
company_name = 'ICONFINDER ApS'
company_address = 'Pilestr\xe6de 43 2\n1112 K\xf8benhavn K'
content = \
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/' \
'envelope/"><soap:Body><checkVatResponse xmlns="urn:ec.europ' \
'a.eu:taxud:vies:services:checkVat:types"><countryCode>{}</c' \
'ountryCode><vatNumber>{}</vatNumber><requestDate>{}</reques' \
'tDate><valid>true</valid><name>{}</name><address>{}</addres' \
's></checkVatResponse></soap:Body></soap:Envelope>'.format(
country_code, vat_number, request_date, company_name,
company_address)
headers = {'Content-Type': 'text/xml'}
return response(200, content, headers, None, 5, request)
def test_vies_response_parsing(self):
with HTTMock(self.mock_registry_response):
results = check_vat_number('DK 33 77 94 37', 'DK')
self.assertEqual(results.business_name, 'ICONFINDER ApS')
self.assertEqual(
results.business_address,
'Pilestr\xe6de 43 2\n1112 K\xf8benhavn K')
Feel free to reuse it in pyvat
if appropriate.
Hi,
before I am going to start a new fork I wanted to ask if this package is maintained by anyone?
As the doc says "Currently only supports determination of the VAT charge for telecommunications, broadcasting and electronic services in the EU." I expected to get the right vat rate doing:
import pyvat
import datetime
pyvat.get_sale_vat_charge(datetime.datetime.now(), pyvat.ItemType.generic_electronic_service, pyvat.Party("DK", True), pyvat.Party("DK", False))
but I'm getting:
NotImplementedError: cannot determine VAT charge for a sale of item ItemType.generic_electronic_service: 2 between pyvat.Party: country code = DK, is business = False and pyvat.Party: country code = DK, is business = True
shouldn't I get a valid VAT charge for this case?
You probably got the news, starting January 1st, 2015, all european businesses have to upgrade the VAT scheme on customer invoices. See: http://ec.europa.eu/taxation_customs/taxation/vat/how_vat_works/telecom/index_en.htm
Is pyvat
the right place to manage VAT rates ?
Hi,
getting this error from time to time. What can we do?
response = pyvat.check_vat_number(self.ustid)
File "/usr/local/lib/python3.9/site-packages/pyvat/__init__.py", line 211, in check_vat_number
return VAT_REGISTRIES[country_code].check_vat_number(vat_number,
File "/usr/local/lib/python3.9/site-packages/pyvat/registries.py", line 136, in check_vat_number
raise ServerError(fault_code)
pyvat.exceptions.ServerError: ServerError: MS_MAX_CONCURRENT_REQ
The library connects to the vat validation API via http only.
This of course has some performance benefits over https, but is less secure.
In my opinion the user of the library should be able to decide whether to use http or https.
Https should be the default, though.
We're getting the following errors for our that use pyvat
on our CI server, but I'm unable to reproduce the failure locally. However, before even figuring out why VIES service is returning server error, the error thrown below seems to originate in wrongly used super
call, though I don't see what exactly is wrong there
File "/home/runner/.local/lib/python2.7/site-packages/pyvat/__init__.py", line 212, in check_vat_number
country_code)
File "/home/runner/.local/lib/python2.7/site-packages/pyvat/registries.py", line 133, in check_vat_number
raise ServerError(fault_code)
File "/home/runner/.local/lib/python2.7/site-packages/pyvat/exceptions.py", line 3, in __init__
super().__init__("ServerError: {}".format(fault_code))
TypeError: super() takes at least 1 argument (0 given)
Any idea what's happening here?
pycountry version is not pinned, so the new release is breaking pyvat
Here is list of changes: https://bitbucket.org/flyingcircus/pycountry/src/default/HISTORY.txt
See PR #14 for fix
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.