示例#1
0
def check_dgii(rnc, ncf):  # pragma: no cover
    """Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the Dirección General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid.

    Returns a dict with the following structure::

        {
            'name': 'The registered name',
            'proof': 'Source of the information',
            'is_valid': '1',
            'validation_message': '',
            'rnc': '123456789',
            'ncf': 'A020010210100000005'
        }

    Will return None if the number is invalid or unknown."""
    from stdnum.do.rnc import compact as rnc_compact
    from stdnum.do.rnc import dgii_wsdl
    rnc = rnc_compact(rnc)
    ncf = compact(ncf)
    client = get_soap_client(dgii_wsdl)
    result = client.GetNCF(
        RNC=rnc,
        NCF=ncf,
        IMEI='')
    if result == '0':
        return
    return _convert_result(result)
示例#2
0
def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
    """Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the Dirección General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid. The timeout is in
    seconds.

    Returns a dict with the following structure::

        {
            'name': 'The registered name',
            'status': 'VIGENTE',
            'type': 'FACTURAS DE CREDITO FISCAL',
            'rnc': '123456789',
            'ncf': 'A020010210100000005',
            'validation_message': 'El NCF digitado es válido.',
        }

    Will return None if the number is invalid or unknown."""
    import requests
    try:
        from bs4 import BeautifulSoup
    except ImportError:
        from BeautifulSoup import BeautifulSoup
    from stdnum.do.rnc import compact as rnc_compact
    rnc = rnc_compact(rnc)
    ncf = compact(ncf)
    url = 'https://www.dgii.gov.do/app/WebApps/ConsultasWeb/consultas/ncf.aspx'
    headers = {
        'User-Agent': 'Mozilla/5.0 (python-stdnum)',
    }
    result = BeautifulSoup(
        requests.get(url, headers=headers, timeout=timeout).text)
    validation = result.find('input', {'name': '__EVENTVALIDATION'})['value']
    viewstate = result.find('input', {'name': '__VIEWSTATE'})['value']
    data = {
        '__EVENTVALIDATION': validation,
        '__VIEWSTATE': viewstate,
        'ctl00$cphMain$btnConsultar': 'Buscar',
        'ctl00$cphMain$txtNCF': ncf,
        'ctl00$cphMain$txtRNC': rnc,
    }
    result = BeautifulSoup(
        requests.post(url, headers=headers, data=data, timeout=timeout).text)
    results = result.find(id='ctl00_cphMain_pResultado')
    if results:
        data = {
            'validation_message':
            result.find(id='ctl00_cphMain_lblInformacion').get_text().strip(),
        }
        data.update(
            zip([
                x.get_text().strip().rstrip(':')
                for x in results.find_all('strong')
            ], [x.get_text().strip() for x in results.find_all('span')]))
        return _convert_result(data)
示例#3
0
文件: ncf.py 项目: adh/python-stdnum
def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
    """Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the Dirección General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid. The timeout is in
    seconds.

    Returns a dict with the following structure::

        {
            'name': 'The registered name',
            'status': 'VIGENTE',
            'type': 'FACTURAS DE CREDITO FISCAL',
            'rnc': '123456789',
            'ncf': 'A020010210100000005',
            'validation_message': 'El NCF digitado es válido.',
        }

    Will return None if the number is invalid or unknown."""
    import lxml.html
    import requests
    from stdnum.do.rnc import compact as rnc_compact
    rnc = rnc_compact(rnc)
    ncf = compact(ncf)
    url = 'https://www.dgii.gov.do/app/WebApps/ConsultasWeb/consultas/ncf.aspx'
    headers = {
        'User-Agent': 'Mozilla/5.0 (python-stdnum)',
    }
    # Get the page to pick up needed form parameters
    document = lxml.html.fromstring(
        requests.get(url, headers=headers, timeout=timeout).text)
    validation = document.find('.//input[@name="__EVENTVALIDATION"]').get(
        'value')
    viewstate = document.find('.//input[@name="__VIEWSTATE"]').get('value')
    data = {
        '__EVENTVALIDATION': validation,
        '__VIEWSTATE': viewstate,
        'ctl00$cphMain$btnConsultar': 'Buscar',
        'ctl00$cphMain$txtNCF': ncf,
        'ctl00$cphMain$txtRNC': rnc,
    }
    # Do the actual request
    document = lxml.html.fromstring(
        requests.post(url, headers=headers, data=data, timeout=timeout).text)
    result = document.find('.//div[@id="ctl00_cphMain_pResultado"]')
    if result is not None:
        data = {
            'validation_message':
            document.findtext(
                './/*[@id="ctl00_cphMain_lblInformacion"]').strip(),
        }
        data.update(
            zip([
                x.text.strip().rstrip(':') for x in result.findall('.//strong')
            ], [x.text.strip() for x in result.findall('.//span')]))
        return _convert_result(data)
示例#4
0
def check_dgii(rnc, ncf, timeout=30):  # pragma: no cover
    """Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the Dirección General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid. The timeout is in
    seconds.

    Returns a dict with the following structure::

        {
            'name': 'The registered name',
            'status': 'VIGENTE',
            'type': 'FACTURAS DE CREDITO FISCAL',
            'rnc': '123456789',
            'ncf': 'A020010210100000005',
            'validation_message': 'El NCF digitado es válido.',
        }

    Will return None if the number is invalid or unknown."""
    import requests
    try:
        from bs4 import BeautifulSoup
    except ImportError:
        from BeautifulSoup import BeautifulSoup
    from stdnum.do.rnc import compact as rnc_compact
    rnc = rnc_compact(rnc)
    ncf = compact(ncf)
    url = 'https://www.dgii.gov.do/app/WebApps/ConsultasWeb/consultas/ncf.aspx'
    headers = {
        'User-Agent': 'Mozilla/5.0 (python-stdnum)',
    }
    data = {
        '__EVENTVALIDATION': '/wEWBAKh8pDuCgK+9LSUBQLfnOXIDAKErv7SBhjZB34//pbvvJzrbkFCGGPRElcd',
        '__VIEWSTATE': '/wEPDwUJNTM1NDc0MDQ5ZGRCFUYoDcVRgzEntcKfSuvPnC2VhA==',
        'ctl00$cphMain$btnConsultar': 'Consultar',
        'ctl00$cphMain$txtNCF': ncf,
        'ctl00$cphMain$txtRNC': rnc,
    }
    result = BeautifulSoup(
        requests.post(url, headers=headers, data=data, timeout=timeout).text)
    results = result.find(id='ctl00_cphMain_pResultado')
    if results:
        data = {
            'validation_message': result.find(id='ctl00_cphMain_lblInformacion').get_text().strip(),
        }
        data.update(zip(
            [x.get_text().strip().rstrip(':') for x in results.find_all('strong')],
            [x.get_text().strip() for x in results.find_all('span')]))
        return _convert_result(data)
示例#5
0
def check_dgii(rnc,
               ncf,
               buyer_rnc=None,
               security_code=None,
               timeout=30):  # pragma: no cover
    """Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the Dirección General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid. The timeout is in
    seconds.

    Returns a dict with the following structure::
        For a NCF
        {
            'name': 'The registered name',
            'status': 'VIGENTE',
            'type': 'FACTURAS DE CREDITO FISCAL',
            'rnc': '123456789',
            'ncf': 'A020010210100000005',
            'validation_message': 'El NCF digitado es válido.',
        }
        For an ECNF
        {
            'rnc_issuing': '1234567890123',
            'rnc_buyer': '123456789',
            'encf': 'E300000000000',
            'security_code': '1+2kP3',
            'status': 'Aceptado',
            'total': '2203.50',
            'total_itbis': '305.10',
            'issuing_date': '2020-03-25',
            'signature_date': '2020-03-22',
            'validation_message': 'Aceptado',
        }

    Will return None if the number is invalid or unknown."""
    import lxml.html
    import requests
    from stdnum.do.rnc import compact as rnc_compact
    rnc = rnc_compact(rnc)
    ncf = compact(ncf)

    if buyer_rnc:
        buyer_rnc = rnc_compact(buyer_rnc)
    url = 'https://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/ncf.aspx'
    session = requests.Session()
    session.headers.update({
        'User-Agent': 'Mozilla/5.0 (python-stdnum)',
    })
    # Get the page to pick up needed form parameters
    document = lxml.html.fromstring(session.get(url, timeout=timeout).text)
    validation = document.find('.//input[@name="__EVENTVALIDATION"]').get(
        'value')
    viewstate = document.find('.//input[@name="__VIEWSTATE"]').get('value')
    data = {
        '__EVENTVALIDATION': validation,
        '__VIEWSTATE': viewstate,
        'ctl00$cphMain$btnConsultar': 'Buscar',
        'ctl00$cphMain$txtNCF': ncf,
        'ctl00$cphMain$txtRNC': rnc,
    }
    if ncf[0] == 'E':
        data['ctl00$cphMain$txtRncComprador'] = buyer_rnc
        data['ctl00$cphMain$txtCodigoSeg'] = security_code
    # Do the actual request
    document = lxml.html.fromstring(
        session.post(url, data=data, timeout=timeout).text)
    result_path = './/div[@id="cphMain_PResultadoFE"]' if ncf[
        0] == 'E' else './/div[@id="cphMain_pResultado"]'
    result = document.find(result_path)
    if result is not None:
        lbl_path = './/*[@id="cphMain_lblEstadoFe"]' if ncf[
            0] == 'E' else './/*[@id="cphMain_lblInformacion"]'
        data = {
            'validation_message': document.findtext(lbl_path).strip(),
        }
        data.update(
            zip([x.text.strip() for x in result.findall('.//th') if x.text], [
                x.text.strip() for x in result.findall('.//td/span') if x.text
            ]))
        return _convert_result(data)