These are chat archives for codingjoe/django-vies

4th
Jan 2016
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:29
Hi
Johannes Hoppe
@codingjoe
Jan 04 2016 13:29
hi @takis how you doing
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:30
Hi, I'm doing fine thank you :-) How are you?
I've got a question regarding the handling of countries outside of the European union. A customer has got 99% European customers, and 1 Swiss customer. I wanted to replace the purely CharField vat field in my customer model with django-vies' field, but I'm not sure how I would be able to handle the Swiss customer.
Initially, I figured, I'd try adding support for Swiss VAT numbers, but I'm not sure if non-European VAT numbers are "welcome"
In the sense that django-vies might be intended to handle only European numbers and validate them using the VIES webservice.
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:36
I figured I could add support by only using regexes to validate that the number is in the correct format. For me, that would do, as it would at least allow me to enter the Swiss customer to the database
Johannes Hoppe
@codingjoe
Jan 04 2016 13:37
ok, first let me start with saying Swiss is European, but not in the EU ;) By default this wont work, as the field currently validates agains VIES. So what you could do is inherit your own field an overwrite some methods. Basically handle the CH case yourself
let me look up what you would need to do, wait a sec
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:37
Oops, apologies my mistake, in fact I have lived there for a while :-D
Johannes Hoppe
@codingjoe
Jan 04 2016 13:39
haha, no offence taken, I’m german so I don’t care :P
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:39
Ah! :-D
I live near the German border actually, about 5km from Germany and 35km from Aachen.
Johannes Hoppe
@codingjoe
Jan 04 2016 13:41
ok in form field:
```python
def compress(value_list):
whoa, sorry, didn’t want to hit enter
wait a second
class MyVATField(VATINField):
    def compress(self, data_list):
        try:
            return super(MyVATField, self).compress(data_list)
        except ValidationError as e:
            if e.code = ‘invalid_country_code’:
                country_code, numer = data_list
                if country_code == ‘CH’:
                    pass  # Your code
this should do the tick with fiel validation, now all you need to do is to add CH to the country code choices.
Johannes Hoppe
@codingjoe
Jan 04 2016 13:46
Which is simple, just do
myfield = MyVATField(choices= VIES_COUNTRY_CHOICES+(‘CH’,))
@takis I hope that does the trick for you, let me know if you have a problem
Panagiotis H.M. Issaris
@takis
Jan 04 2016 13:49
@codingjoe Thanks!
Should that last bit not be: + [('CH','')]
@codingjoe I'll try later this evening (as my customer suggested to just drop the customer :-/ so I cannot spend time on it here on location). But, I'll try and let you know if it worked. Thanks again for your time and super quick response!
Johannes Hoppe
@codingjoe
Jan 04 2016 13:58
No problem. Greetings from Thailand
Panagiotis H.M. Issaris
@takis
Jan 04 2016 14:00
Ah nice! For a holiday or for work if I may ask?
Panagiotis H.M. Issaris
@takis
Jan 04 2016 14:32
@codingjoe Another thing I was wondering about: What is the recommended method to migrate a CharField to a VATINField?
I had initially tried just migrating, but this failed due to the non-standard format the VAT numbers were stored in here. The prefix were missing, and so django-vies interpreted the first two characters as a country code. I decided and have just finished writing data migrations, to convert all VAT numbers to the standard form.
But, what if the webservice validation fails?
Johannes Hoppe
@codingjoe
Jan 04 2016 14:45
That doesn't need to run and I hardly advice not running it in a migration. It's too many requests. It will take forever and eventually the firewall will block you.
To be honest this part deserves some overhauling, it should be split into two validators. I currently don't use it myself so I haven't had any interest in improving it so far. Sorry
But for now, a data migration should be fine. Validation is only on form level anyways. If a user updates a profile and the number was wrong he should update it anyways
Panagiotis H.M. Issaris
@takis
Jan 04 2016 14:53
Ah, so the VIES validation does not run during such a migration by default? That's great because that's what I'd feared, that I would get blocked by sending out to many requests to the webservice.
Oh, sorry, for asking again, I see you already answered that,
As you said, the forms are doing the webservice validation.
Johannes Hoppe
@codingjoe
Jan 04 2016 14:58
Yes correct, feel free to as many questions as you like. I'm on vacation I got lots of time ;)
Panagiotis H.M. Issaris
@takis
Jan 04 2016 15:12
Ah thanks a lot! :-)