Beispiel #1
0
def test_invoicesimple_build(simple_invoice):
    xml = DIANInvoiceXML(simple_invoice)

    supplier_name = xml.get_element_text('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name')
    assert supplier_name == simple_invoice.invoice_supplier.name

    customer_name = xml.get_element_text('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyName/cbc:Name')
    assert customer_name == simple_invoice.invoice_customer.name
Beispiel #2
0
def test_query_billing_reference(simple_invoice):
    xml = DIANInvoiceXML(simple_invoice)
    cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
    xml.add_extension(cufe_extension)
    out = xml.tostring()

    reference = query.billing_reference(out, form.BillingReference)
    assert isinstance(reference, form.BillingReference)
    assert reference.ident != ''
    assert reference.uuid != ''
    assert reference.date != ''
Beispiel #3
0
def test_invoicesimple_zip(simple_invoice):
    xml_invoice = DIANInvoiceXML(simple_invoice)

    zipdata = io.BytesIO()
    with fe.DianZIP(zipdata) as dianzip:
        name_invoice = dianzip.add_invoice_xml(simple_invoice.invoice_ident, str(xml_invoice))

    # el zip ademas de archivar debe comprimir los archivos
    # de lo contrario la DIAN lo rechaza
    with zipfile.ZipFile(zipdata) as dianzip:
        dianzip.testzip()
        for zipinfo in dianzip.infolist():
            assert zipinfo.compress_type == zipfile.ZIP_DEFLATED, "se espera el zip comprimido"

    with zipfile.ZipFile(zipdata) as dianzip:
        xml_data = dianzip.open(name_invoice).read().decode('utf-8')
        assert xml_data == str(xml_invoice)
Beispiel #4
0
def test_invoicesimple_xml_signed(monkeypatch, simple_invoice):
    xml = DIANInvoiceXML(simple_invoice)

    signer = fe.DianXMLExtensionSigner('./tests/example.p12')

    print(xml.tostring())
    with monkeypatch.context() as m:
        import helpers
        helpers.mock_urlopen(m)
        xml.add_extension(signer)

    elem = xml.get_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent/ds:Signature')
    assert elem.text is not None
Beispiel #5
0
def test_invoice_invoice_type_code(simple_invoice):
    xml_invoice = DIANInvoiceXML(simple_invoice)
    id_ = xml_invoice.get_element_text('/fe:Invoice/cbc:InvoiceTypeCode', format_=int)
    assert id_ == 1
Beispiel #6
0
def test_invoice_profileexecutionid(simple_invoice):
    xml_invoice = DIANInvoiceXML(simple_invoice)
    cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
    xml_invoice.add_extension(cufe_extension)
    id_ = xml_invoice.get_element_text('/fe:Invoice/cbc:ProfileExecutionID', format_=int)
    assert id_ == 2
Beispiel #7
0
def test_invoice_line_count_numeric(simple_invoice):
    xml_invoice = DIANInvoiceXML(simple_invoice)
    count = xml_invoice.get_element_text('/fe:Invoice/cbc:LineCountNumeric', format_=int)
    assert count == len(simple_invoice.invoice_lines)
Beispiel #8
0
def test_bug_cbcid_empty_on_invoice_line(simple_invoice):
    xml_invoice = DIANInvoiceXML(simple_invoice)
    cbc_id = xml_invoice.get_element_text('/fe:Invoice/cac:InvoiceLine[1]/cbc:ID', format_=int)
    assert cbc_id == 1
Beispiel #9
0
def test_invoicesimple_build_with_cufe(simple_invoice):
    xml = DIANInvoiceXML(simple_invoice)
    cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
    xml.add_extension(cufe_extension)
    cufe = xml.get_element_text('/fe:Invoice/cbc:UUID')
    assert cufe != ''
Beispiel #10
0
    simple_invoice.invoice_customer.ident = form.PartyIdentification('800199436', '5', '31')
    simple_invoice.add_invoice_line(form.InvoiceLine(
        quantity = form.Quantity(1.00, '94'),
        description = 'producto',
        item = form.StandardItem(111),
        price = form.Price(form.Amount(1_500_000), '01', ''),
        tax = form.TaxTotal(
            subtotals = [
                form.TaxSubTotal(
                    scheme = form.TaxScheme('01'),
                    percent = 19.0
                )])
    ))

    simple_invoice.calculate()
    xml_invoice = DIANInvoiceXML(simple_invoice)

    cufe_extension = fe.DianXMLExtensionCUFE(
        simple_invoice,
        tipo_ambiente = fe.AMBIENTE_PRODUCCION,
        clave_tecnica = '693ff6f2a553c3646a063436fd4dd9ded0311471'
    )
    formatVars = cufe_extension.formatVars()
    #NumFac
    assert formatVars[0] == '323200000129', "NumFac"
    #FecFac
    assert formatVars[1] == '2019-01-16', "FecFac"
    #HoraFac
    assert formatVars[2] == '10:53:10-05:00', "HoraFac"
    #ValorBruto
    assert formatVars[3] == '1500000.00', "ValorBruto"