コード例 #1
0
    def test_validator_greece(self):
        validator = VATNumberValidator(eu_only=True)
        self.assertRaises(ValidationError, validator, 'GR123456789')
        validator('EL123456789')

        validator = VATNumberValidator(countries=['GR'])
        self.assertRaises(ValidationError, validator, 'GR123456789')
        validator('EL123456789')

        validator = VATNumberValidator(countries=['EL'])
        self.assertRaises(ValidationError, validator, 'GR123456789')
        validator('EL123456789')
コード例 #2
0
    def test_vies_check_validator_native(self):
        validator = VATNumberValidator(vies_check=True)
        validator._check_vies = validator._check_vies_native

        validator('DE114103379')
        with self.assertRaises(ValidationError) as context_manager:
            validator('DE999999999')
            # Check if the validation succeeded due to a SUDS error.
            # You should be wary of skipped tests because of this, but the service may also be unavailable at the time.
            if validator._wsdl_exception is not None:
                print("Native WSDL test skipped due to connection failure")
                self.skipTest("Native WSDL client failed")
        self.assertEqual(context_manager.exception.messages, ['This VAT number does not exist.'])
コード例 #3
0
    def test_vies_check_validator_native(self):
        validator = VATNumberValidator(vies_check=True)
        validator._check_vies = validator._check_vies_native

        validator('DE114103379')
        try:
            with self.assertRaises(ValidationError) as context_manager:
                validator('DE999999999')
            self.assertEqual(context_manager.exception.messages,
                             ['This VAT number does not exist.'])
        except AssertionError:
            # Check if the validation succeeded due to a SUDS error.
            # You should be wary of skipped tests because of this, but the service may also be unavailable at the time.
            if validator._wsdl_exception is not None:
                print("Native WSDL test skipped due to connection failure")
                self.skipTest("Native WSDL client failed")
            else:
                raise
コード例 #4
0
    def get_tax_rate(cls, vat_id, customer_country, supplier_country=None):
        if not supplier_country:
            supplier_country = cls.get_supplier_country_code()

        if not cls.is_in_EU(supplier_country):
            raise ImproperlyConfigured(
                "EUTaxationPolicy requires that supplier country is in EU")

        if vat_id in EMPTY_VALUES:
            # We don't know VAT ID

            if customer_country in EMPTY_VALUES:
                # We don't know VAT ID or country
                return cls.get_default_tax(supplier_country)

            # Customer is not a company, we know his country

            if cls.is_in_EU(customer_country):
                # Customer (private person) is from a EU
                # He must pay full VAT of our country
                return cls.get_default_tax(supplier_country)
            else:
                # Customer (private person) is not from EU
                # charge back
                return None

        # Customer is company, we know country and VAT ID

        if customer_country.upper() == supplier_country.upper():
            # Company is from the same country as supplier
            # Normal tax
            return cls.get_default_tax(supplier_country)

        if not cls.is_in_EU(customer_country):
            # Company is not from EU
            # Charge back
            return None

        # Company is from other EU country
        use_vies_validator = getattr(settings, 'INVOICING_USE_VIES_VALIDATOR',
                                     True)

        if not use_vies_validator:
            # trust VAT ID is correct
            # Charge back
            return None

        try:
            # verify VAT ID in VIES
            VATNumberValidator(eu_only=True, vies_check=True)(vat_id)

            # Company is registered in VIES
            # Charge back
            return None
        except ValidationError:
            return cls.get_default_tax(supplier_country)
コード例 #5
0
    def test_validator(self):
        validator = VATNumberValidator()

        # Our validator does not allow formatting characters, so check we do not pass it in.
        for iban, cleaned in self.valid.items():
            if iban == cleaned:
                validator(iban)
            else:
                validator(cleaned)
                self.assertRaises(ValidationError, validator, iban)

        for iban, message in self.invalid.items():
            self.assertRaisesMessage(ValidationError, message[0], validator,
                                     iban)
コード例 #6
0
 def test_validator_eu_only(self):
     validator = VATNumberValidator(eu_only=True)
     validator('CY12345678A')