Example #1
0
 def test_form_clean_raises_error_on_invalid_tax(self):
     """
     BillingInfo form should allow only valid tax numbers.
     Form should return the error if it is not
     """
     billing_info = BillingInfo.objects.first()
     country = vatnumber.countries()[0]
     data = {
         'user': billing_info.user,
         'country': country,
         'street': billing_info.street,
         'name': billing_info.name,
         'zipcode': billing_info.zipcode,
         'city': billing_info.city,
         'tax_number': country+billing_info.tax_number,
     }
     form = BillingInfoForm(data=data)
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 1)
Example #2
0
    def clean_tax_number(tax_number, country):
        tax_number = re.sub(r'[^A-Z0-9]', '', tax_number.upper())
        if tax_number and country:

            if country in vatnumber.countries():
                number = tax_number
                if tax_number.startswith(country):
                    number = tax_number[len(country):]

                if not vatnumber.check_vat(country + number):
                    #           This is a proper solution to bind ValidationError to a Field but it is not
                    #           working due to django bug :(
                    #                    errors = defaultdict(list)
                    #                    errors['tax_number'].append(_('VAT ID is not correct'))
                    #                    raise ValidationError(errors)
                    raise ValidationError(_('VAT ID is not correct'))

            return tax_number
        else:
            return ''
Example #3
0
    def clean_tax_number(tax_number, country):
        tax_number = re.sub(r'[^A-Z0-9]', '', tax_number.upper())
        if tax_number and country:

            if country in vatnumber.countries():
                number = tax_number
                if tax_number.startswith(country):
                    number = tax_number[len(country):]

                if not vatnumber.check_vat(country + number):
                    #           This is a proper solution to bind ValidationError to a Field but it is not
                    #           working due to django bug :(
                    #                    errors = defaultdict(list)
                    #                    errors['tax_number'].append(_('VAT ID is not correct'))
                    #                    raise ValidationError(errors)
                    raise ValidationError(_('VAT ID is not correct'))

            return tax_number
        else:
            return ''
Example #4
0
from trytond.transaction import Transaction
from trytond.pool import Pool

__all__ = [
    'Party', 'PartyCategory', 'CheckVIESNoResult', 'CheckVIESResult',
    'CheckVIES'
]

logger = logging.getLogger(__name__)

HAS_VATNUMBER = False
VAT_COUNTRIES = [('', '')]
try:
    import vatnumber
    HAS_VATNUMBER = True
    for country in vatnumber.countries():
        VAT_COUNTRIES.append((country, country))
except ImportError:
    logger.warning(
        'Unable to import vatnumber. VAT number validation disabled.',
        exc_info=True)

STATES = {
    'readonly': ~Eval('active', True),
}
DEPENDS = ['active']


class Party(ModelSQL, ModelView):
    "Party"
    __name__ = 'party.party'
Example #5
0
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateTransition, StateView, Button
from trytond.pyson import Bool, Eval
from trytond.transaction import Transaction
from trytond.pool import Pool

__all__ = ['Party', 'PartyCategory', 'CheckVIESNoResult', 'CheckVIESResult',
           'CheckVIES']

HAS_VATNUMBER = False
VAT_COUNTRIES = [('', '')]
try:
    import vatnumber
    HAS_VATNUMBER = True
    for country in vatnumber.countries():
        VAT_COUNTRIES.append((country, country))
except ImportError:
    logging.getLogger('party').warning(
            'Unable to import vatnumber. VAT number validation disabled.')

STATES = {
    'readonly': ~Eval('active', True),
}
DEPENDS = ['active']


class Party(ModelSQL, ModelView):
    "Party"
    __name__ = 'party.party'
Example #6
0
 def test_countries(self):
     '''
     Test countries
     '''
     vatnumber.countries()
Example #7
0
 def test_countries(self):
     '''
     Test countries
     '''
     vatnumber.countries()