Exemplo n.º 1
0
def test_round_half_even():
    # https://www.w3.org/TR/xpath-functions-31/#func-round-half-to-even
    assert form.Amount(0.5).round(0).float() == 0.0
    assert form.Amount(1.5).round(0).float() == 2.0
    assert form.Amount(2.5).round(0).float() == 2.0
    assert form.Amount(3.567812e+3).round(2).float() == 3567.81e0
    assert form.Amount(4.7564e-3).round(2).float() == 0.0e0
Exemplo n.º 2
0
def test_allowance_charge_in_invoice_line(simple_invoice_without_lines):
    inv = copy.copy(simple_invoice_without_lines)
    inv.add_invoice_line(
        form.InvoiceLine(
            quantity=form.Quantity(1, '94'),
            description='producto facho',
            item=form.StandardItem(9999),
            price=form.Price(amount=form.Amount(100.0),
                             type_code='01',
                             type='x'),
            tax=form.TaxTotal(subtotals=[form.TaxSubTotal(percent=19.0, )]),
            allowance_charge=[
                form.AllowanceChargeAsDiscount(amount=form.Amount(10.0))
            ]))
    inv.calculate()

    # se aplico descuento
    assert inv.invoice_legal_monetary_total.line_extension_amount == form.Amount(
        90.0)

    xml = form_xml.DIANInvoiceXML(inv)

    with pytest.raises(AttributeError):
        assert xml.get_element_text(
            '/fe:Invoice/cac:AllowanceCharge/cbc:ID') == '1'
    xml.get_element_text(
        '/fe:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:ID') == '1'
    xml.get_element_text(
        '/fe:Invoice/cac:InvoiceLine/cac:AllowanceCharge/cbc:BaseAmount'
    ) == '100.0'
Exemplo n.º 3
0
def test_amount_equals():
    price1 = form.Amount(110.0)
    price2 = form.Amount(100 + 10.0)
    assert price1 == price2
    assert price1 == form.Amount(100) + form.Amount(10)
    assert price1 == form.Amount(10) * form.Amount(10) + form.Amount(10)
    assert form.Amount(110) == (form.Amount(1.10) * form.Amount(100))
Exemplo n.º 4
0
def test_invoice_line_quantity_without_taxes():
    line = form.InvoiceLine(quantity=form.Quantity(10, '94'),
                            description='',
                            item=form.StandardItem('test', 9999),
                            price=form.Price(amount=form.Amount(30.00),
                                             type_code='01',
                                             type='x'),
                            tax=form.TaxTotal(subtotals=[]))
    line.calculate()
    assert line.total_amount == form.Amount(300)
    assert line.tax_amount == form.Amount(0)
Exemplo n.º 5
0
def test_round():
    # Entre 0 y 5 Mantener el dígito menos significativo
    assert form.Amount(1.133).round(2) == form.Amount(1.13)
    # Entre 6 y 9 Incrementar el dígito menos significativo
    assert form.Amount(1.166).round(2) == form.Amount(1.17)
    # 5, y el segundo dígito siguiente al dígito menos significativo es cero o par Mantener el dígito menos significativo
    assert str(form.Amount(1.1542).round(2)) == str(form.Amount(1.15))
    # 5, y el segundo dígito siguiente al dígito menos significativo es impar Incrementar el dígito menos significativo
    assert str(form.Amount(1.1563).round(2)) == str(form.Amount(1.16))
Exemplo n.º 6
0
def simple_invoice():
    inv = form.NationalSalesInvoice()
    inv.set_period(datetime.now(), datetime.now())
    inv.set_issue(datetime.now())
    inv.set_ident('ABC123')
    inv.set_operation_type('10')
    inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), ' 1234'))
    inv.set_supplier(form.Party(
        name = 'facho-supplier',
        ident = form.PartyIdentification('123','', '31'),
        responsability_code = form.Responsability(['O-07']),
        responsability_regime_code = '48',
        organization_code = '1',
        address = form.Address(
            '', '', form.City('05001', 'Medellín'),
            form.Country('CO', 'Colombia'),
            form.CountrySubentity('05', 'Antioquia'))
    ))
    inv.set_customer(form.Party(
        name = 'facho-customer',
        ident = form.PartyIdentification('321','', '31'),
        responsability_code = form.Responsability(['O-07']),
        responsability_regime_code = '48',
        organization_code = '1',
        address = form.Address(
            '', '', form.City('05001', 'Medellín'),
            form.Country('CO', 'Colombia'),
            form.CountrySubentity('05', 'Antioquia'))
    ))
    inv.add_invoice_line(form.InvoiceLine(
        quantity = form.Quantity(1, '94'),
        description = 'producto facho',
        item = form.StandardItem( 9999),
        price = form.Price(form.Amount(100.0), '01', ''),
        tax = form.TaxTotal(
            tax_amount = form.Amount(0.0),
            taxable_amount = form.Amount(0.0),
            subtotals = [
                form.TaxSubTotal(
                    percent = 19.0,
                )
            ]
        )
    ))
    return inv
Exemplo n.º 7
0
def test_amount_truncate():
    assert form.Amount(1.1569).truncate_as_string(2) == '1.15'
    assert form.Amount(587.0700).truncate_as_string(2) == '587.07'
    assert form.Amount(14705.8800).truncate_as_string(2) == '14705.88'
    assert form.Amount(9423.7000).truncate_as_string(2) == '9423.70'
    assert form.Amount(10084.03).truncate_as_string(2) == '10084.03'
    assert form.Amount(10000.02245).truncate_as_string(2) == '10000.02'
    assert form.Amount(10000.02357).truncate_as_string(2) == '10000.02'
Exemplo n.º 8
0
def test_FAU14():
    inv = form.NationalSalesInvoice()
    inv.add_invoice_line(
        form.InvoiceLine(
            quantity=form.Quantity(1, '94'),
            description='producto facho',
            item=form.StandardItem(9999),
            price=form.Price(amount=form.Amount(100.0),
                             type_code='01',
                             type='x'),
            tax=form.TaxTotal(subtotals=[form.TaxSubTotal(percent=19.0, )])))
    inv.add_allowance_charge(form.AllowanceCharge(amount=form.Amount(19.0)))
    inv.add_prepaid_payment(form.PrePaidPayment(paid_amount=form.Amount(50.0)))
    inv.calculate()

    wants = form.Amount(119.0 + 19.0 - 50.0)

    assert inv.invoice_legal_monetary_total.payable_amount == wants, "got %s want %s" % (
        inv.invoice_legal_monetary_total.payable_amount, wants)
Exemplo n.º 9
0
def test_invoice_legalmonetary():
    inv = form.NationalSalesInvoice()
    inv.add_invoice_line(
        form.InvoiceLine(
            quantity=form.Quantity(1, '94'),
            description='producto facho',
            item=form.StandardItem(9999),
            price=form.Price(amount=form.Amount(100.0),
                             type_code='01',
                             type='x'),
            tax=form.TaxTotal(subtotals=[form.TaxSubTotal(percent=19.0, )])))
    inv.calculate()
    assert inv.invoice_legal_monetary_total.line_extension_amount == form.Amount(
        100.0)
    assert inv.invoice_legal_monetary_total.tax_exclusive_amount == form.Amount(
        100.0)
    assert inv.invoice_legal_monetary_total.tax_inclusive_amount == form.Amount(
        119.0)
    assert inv.invoice_legal_monetary_total.charge_total_amount == form.Amount(
        0.0)
Exemplo n.º 10
0
def test_allowance_charge_in_invoice(simple_invoice_without_lines):
    inv = copy.copy(simple_invoice_without_lines)
    inv.add_invoice_line(
        form.InvoiceLine(
            quantity=form.Quantity(1, '94'),
            description='producto facho',
            item=form.StandardItem(9999),
            price=form.Price(amount=form.Amount(100.0),
                             type_code='01',
                             type='x'),
            tax=form.TaxTotal(subtotals=[form.TaxSubTotal(percent=19.0, )])))
    inv.add_allowance_charge(form.AllowanceCharge(amount=form.Amount(19.0)))
    inv.calculate()

    xml = form_xml.DIANInvoiceXML(inv)
    assert xml.get_element_text('./cac:AllowanceCharge/cbc:ID') == '1'
    assert xml.get_element_text(
        './cac:AllowanceCharge/cbc:ChargeIndicator') == 'true'
    assert xml.get_element_text('./cac:AllowanceCharge/cbc:Amount') == '19.0'
    assert xml.get_element_text(
        './cac:AllowanceCharge/cbc:BaseAmount') == '100.0'
Exemplo n.º 11
0
def test_amount_positive():
    with pytest.raises(ValueError):
        form.Amount(-1.0)
Exemplo n.º 12
0
def invoice():
    # factura de venta nacional
    inv = form.Invoice('01')
    # asignar periodo de facturacion
    inv.set_period(datetime.now(), datetime.now())
    # asignar fecha de emision de la factura
    inv.set_issue(datetime.now())
    # asignar prefijo y numero del documento
    inv.set_ident('SETP990000008')
    # asignar tipo de operacion ver DIAN:6.1.5
    inv.set_operation_type('10')
    inv.set_supplier(
        form.Party(
            legal_name='Nombre registrado de la empresa',
            name='Nombre comercial o él mismo nombre registrado',
            ident=form.PartyIdentification('nit_empresa',
                                           'digito_verificación', '31'),
            # obligaciones del contribuyente ver DIAN:FAK26
            responsability_code=form.Responsability(['O-07', 'O-14', 'O-48']),
            # ver DIAN:FAJ28
            responsability_regime_code='48',
            # tipo de organizacion juridica ver DIAN:6.2.3
            organization_code='1',
            email="*****@*****.**",
            address=form.Address('', '', form.City('05001', 'Medellín'),
                                 form.Country('CO', 'Colombia'),
                                 form.CountrySubentity('05', 'Antioquia')),
        ))
    #Tercero a quien se le factura
    inv.set_customer(
        form.Party(
            legal_name='consumidor final',
            name='consumidor final',
            ident=form.PartyIdentification('222222222222', '', '13'),
            responsability_code=form.Responsability(['R-99-PN']),
            responsability_regime_code='49',
            organization_code='2',
            email="consumidor_final0final.final",
            address=form.Address('', '', form.City('05001', 'Medellín'),
                                 form.Country('CO', 'Colombia'),
                                 form.CountrySubentity('05', 'Antioquia')),
            #tax_scheme = form.TaxScheme('01', 'IVA')
        ))
    # asignar metodo de pago
    inv.set_payment_mean(
        form.PaymentMean(
            # metodo de pago ver DIAN:3.4.1
            id='1',
            # codigo correspondiente al medio de pago ver DIAN:3.4.2
            code='20',
            # fecha de vencimiento de la factura
            due_at=datetime.now(),
            # identificador numerico
            payment_id='2'))
    # adicionar una linea al documento
    inv.add_invoice_line(
        form.InvoiceLine(
            quantity=form.Quantity(int(20.5), '94'),
            # item general de codigo 999
            description='productO3',
            item=form.StandardItem('test', 9999),
            price=form.Price(
                # precio base del item (sin iva)
                amount=form.Amount(200.00),
                # ver DIAN:6.3.5.1
                type_code='01',
                type='x'),
            tax=form.TaxTotal(subtotals=[
                form.TaxSubTotal(percent=19.00, scheme=form.TaxScheme('01'))
            ])))
    return inv
Exemplo n.º 13
0
    code = '10',
    # fecha de vencimiento de la factura
    due_at = datetime.now(),
    
    # identificador numerico
    payment_id = '1'
))
# adicionar una linea al documento
inv.add_invoice_line(form.InvoiceLine(
    quantity = form.Quantity(1, '94'),
    description = 'producto facho',
    # item general de codigo 999
    item = form.StandardItem('test', 9999),
    price = form.Price(
        # precio base del tiem
        amount = form.Amount(100.00),
        # ver DIAN:6.3.5.1
        type_code = '01',
        type = 'x'
    ),
    tax = form.TaxTotal(
        subtotals = [
            form.TaxSubTotal(
                percent = 19.00,
            )
        ]
    )
))

# refrescar valores de la factura
inv.calculate()
Exemplo n.º 14
0
def test_quantity():
    quantity1 = form.Quantity(10, '94')
    assert quantity1 * form.Amount(3) == form.Amount(30)
Exemplo n.º 15
0
def test_allowancecharge_as_discount():
    discount = form.AllowanceChargeAsDiscount(amount=form.Amount(1000.0))
    assert discount.isDiscount() == True
Exemplo n.º 16
0
def test_amount_format():
    assert str(round(form.Amount(1.1569),2)) == '1.16'
Exemplo n.º 17
0
    simple_invoice.calculate()
    xml_invoice = DIANDebitNoteXML(simple_invoice)

    cude_extension = fe.DianXMLExtensionCUDE(
        simple_invoice,
        '10201',
        tipo_ambiente = fe.AMBIENTE_PRUEBAS,
    )
    build_vars = cude_extension.buildVars()
    assert build_vars['NumFac'] == 'ND1001'
    assert build_vars['FecFac'] == '2019-01-18'
    assert build_vars['HoraFac'] == '10:58:00-05:00'
    assert build_vars['ValorBruto'] == form.Amount(30_000)
    assert build_vars['NitOFE'] == '900197264'
    assert build_vars['NumAdq'] == '10254102'
    assert build_vars['ValorImpuestoPara']['01'] == form.Amount(0)
    assert build_vars['ValorImpuestoPara']['04'] == form.Amount(2400)
    assert build_vars['ValorImpuestoPara']['03'] == form.Amount(0)
    assert build_vars['ValorTotalPagar'] == form.Amount(32400)
    assert build_vars['Software-PIN'] == '10201'
    assert build_vars['TipoAmb'] == 2


    cude_composicion =  "".join(cude_extension.formatVars())
    assert cude_composicion == 'ND10012019-01-1810:58:00-05:0030000.00010.00042400.00030.0032400.0090019726410254102102012'

    xml_invoice.add_extension(cude_extension)
    cude = xml_invoice.get_element_text('/fe:DebitNote/cbc:UUID')
    assert cude == '3fa73a86d57d9341c536afde1f85c4efd9d4591c2c22bce4dfb0e6b0d2e83b8f047a8bde7098292e9d2493e60d1c31da'