Example #1
0
def lookup_vat_by_phone_number(phone_number=None, country_code=None):
    # exception is a statutory VAT exception,
    # *not* a Python error!
    (rate, country,
     exception) = vat_moss.phone_number.calculate_rate(u(phone_number),
                                                       u(country_code))
    return rate
Example #2
0
def lookup_vat_by_phone_number(phone_number=None, country_code=None):
    # exception is a statutory VAT exception,
    # *not* a Python error!
    (rate,
     country,
     exception) = vat_moss.phone_number.calculate_rate(u(phone_number),
                                                       u(country_code))
    return rate
Example #3
0
def lookup_vat_by_city(country_code=None, postcode=None, city=None):
    # exception is a statutory VAT exception,
    # *not* a Python error!
    (rate,
     country,
     exception) = vat_moss.billing_address.calculate_rate(u(country_code),
                                                          u(postcode),
                                                          u(city))
    return rate
Example #4
0
def lookup_vat_by_vatin(country_code, vatin, company_name):
    # We already validated the VATIN through a form validator;
    # additional validation errors here shouldn't happen.
    (vatin_country,
     vatin_normalized,
     vatin_company) = vat_moss.id.validate(u(vatin))

    # Does the VATIN match the country we've been given?
    if vatin_country != country_code:
        raise CountryInvalidForVATINException(vatin,
                                              country_code)

    # Does the VATIN match the company name we've been given?
    #
    # This is effectively a case-insensitive startswith(), but the
    # regex should really be configurable.
    regex = "^%s" % vatin_company
    if not re.search(regex, company_name, re.I):
        raise NonMatchingVATINException(vatin,
                                        company_name)

    # We have a verified VATIN and it matches the company
    # name. Is the country the same as the store country?
    if country_code == settings.VAT_MOSS_STORE_COUNTRY_CODE:
        raise VATINCountrySameAsStoreException(vatin,
                                               country_code)

    # We have a verified, foreign VATIN. Reverse charge applies.
    return D('0.00')
Example #5
0
def lookup_vat_by_vatin(country_code, vatin, company_name):
    # We already validated the VATIN through a form validator;
    # additional validation errors here shouldn't happen.
    (vatin_country, vatin_normalized,
     vatin_company) = vat_moss.id.validate(u(vatin))

    # Does the VATIN match the country we've been given?
    if vatin_country != country_code:
        raise CountryInvalidForVATINException(vatin, country_code)

    # Does the VATIN match the company name we've been given?
    #
    # This is effectively a case-insensitive startswith(), but the
    # regex should really be configurable.
    regex = "^%s" % vatin_company
    if not re.search(regex, company_name, re.I):
        raise NonMatchingVATINException(vatin, company_name)

    # We have a verified VATIN and it matches the company
    # name. Is the country the same as the store country?
    if country_code == settings.VAT_MOSS_STORE_COUNTRY_CODE:
        raise VATINCountrySameAsStoreException(vatin, country_code)

    # We have a verified, foreign VATIN. Reverse charge applies.
    return D('0.00')
Example #6
0
def lookup_vat_by_vatin(country_code, vatin, company_name):
    # We already validated the VATIN through a form validator;
    # additional validation errors here shouldn't happen.
    (vatin_country,
     vatin_normalized,
     vatin_company) = vat_moss.id.validate(u(vatin))

    # Does the VATIN match the country we've been given?
    if vatin_country != country_code:
        message = _("VATIN %s is not from %s" % (vatin,
                                                 country_code))
        raise VATAssessmentException(message)

    # Does the VATIN match the company name we've been given?
    #
    # This is effectively a case-insensitive startswith(), but the
    # regex should really be configurable.
    regex = "^%s" % vatin_company
    if not re.search(regex, company_name, re.I):
        raise NonMatchingVATINException(vatin,
                                        company_name)
    # We have a verified VATIN and it matches the company
    # name. Reverse charge applies.
    #
    return D('0.00')
Example #7
0
def lookup_vat_by_vatin(country_code, vatin, company_name):
    # We already validated the VATIN through a form validator;
    # additional validation errors here shouldn't happen.
    (vatin_country, vatin_normalized,
     vatin_company) = vat_moss.id.validate(u(vatin))

    # Does the VATIN match the country we've been given?
    if vatin_country != country_code:
        message = _("VATIN %s is not from %s" % (vatin, country_code))
        raise VATAssessmentException(message)

    # Does the VATIN match the company name we've been given?
    #
    # This is effectively a case-insensitive startswith(), but the
    # regex should really be configurable.
    regex = "^%s" % vatin_company
    if not re.search(regex, company_name, re.I):
        raise NonMatchingVATINException(vatin, company_name)
    # We have a verified VATIN and it matches the company
    # name. Reverse charge applies.
    #
    return D('0.00')
Example #8
0
    def validate_vatin(self, value):
        """Validate a VATIN and check that it exists.

        :raises:
            ValidationError wrapping one of the following errors from
            vat_moss.id:
                ValueError - If the is not a string or is not in the
                format of two characters plus an identifier
                InvalidError - If the VAT ID is not valid
                WebServiceUnavailableError - If the VIES VAT ID
                service is unable to process the request - this is
                fairly common
                WebServiceError - If there was an error parsing the
                response from the server - usually this means
                something changed in the webservice
                urllib.error.URLError/urllib2.URLError - If there is
                an issue communicating with VIES or data.brreg.no
        """
        # vat_moss expects that all strings are unicode, so force it
        # here.
        try:
            vat_moss.id.validate(u(value))
        except Exception as e:
            raise ValidationError(_(str(e)))
Example #9
0
    def validate_vatin(self, value):
        """Validate a VATIN and check that it exists.

        :raises:
            ValidationError wrapping one of the following errors from
            vat_moss.id:
                ValueError - If the is not a string or is not in the
                format of two characters plus an identifier
                InvalidError - If the VAT ID is not valid
                WebServiceUnavailableError - If the VIES VAT ID
                service is unable to process the request - this is
                fairly common
                WebServiceError - If there was an error parsing the
                response from the server - usually this means
                something changed in the webservice
                urllib.error.URLError/urllib2.URLError - If there is
                an issue communicating with VIES or data.brreg.no
        """
        # vat_moss expects that all strings are unicode, so force it
        # here.
        try:
            vat_moss.id.validate(u(value))
        except Exception as e:
            raise ValidationError(_(str(e)))
Example #10
0
def lookup_vat_by_city(country_code=None, postcode=None, city=None):
    # exception is a statutory VAT exception,
    # *not* a Python error!
    (rate, country, exception) = vat_moss.billing_address.calculate_rate(
        u(country_code), u(postcode), u(city))
    return rate