Swiss VAT numbers: invalid VAT number

In the Party configuration for the company, I tried to insert a real Swiss VAT number and selected the type “VAT”

It complains:

Invalid VAT number "CHE-123.456.789" on party "foo"

If I change the type of the number to nothing, it accepts the number

Swiss VAT numbers have the format demonstrated above, CHE-123.456.789

As a workaround, I put the VAT number in the company footer for reports.

This is expected, when no type is set any validation is done.

We use python-stdnum for VAT numbers validation.
You should report the issue there. They are very nice people which accept contributions from anyone :wink:

They have the file stdnum/ch/vat.py. It last changed in version 1.7. I have version 1.10 on my system.

Before I report the issue there, is there any logging about this error from Tryton?

I tested python-stdnum from the command line:

$ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from stdnum.ch import vat
>>> vat.validate('CHE-xxx.yyy.zzz MWST')
'CHExxxyyyzzzMWST'

The validation is successful according to their examples.

The same VAT number in Tryton gives the error.

Ohh, i just realized that you are using the “VAT” type from 5.0 series which only included EU VAT.

You have two options here:

  • Upgrade to newer series which include more identifier types and you will be able to select the Swiss VAT.
  • Prefix your identifier with the country code (I guess it is CH)

Note that the second will only work if Swiss is from Eureopean Unnion, which I’m not sure