Skip to content
/ facho Public
forked from bit4bit/facho

Facturacion Electronica Colombia

License

Notifications You must be signed in to change notification settings

bryamzxz/facho

 
 

Repository files navigation

Facho

Facho Logo

Facho es una libreria Python open-source para facturacion electronica en Colombia (DIAN).

Implementa el estandar UBL 2.1 y XAdES-EPES para la generacion de facturas electronicas, notas credito/debito, documentos soporte, facturas de exportacion, documentos POS y facturas de contingencia segun el Anexo Tecnico de la DIAN.

Caracteristicas

  • Generacion de Facturas Electronicas de Venta (tipo 01)
  • Facturas de Exportacion (tipo 02)
  • Facturas de Contingencia (tipo 04)
  • Documentos Soporte (tipo 05)
  • Documentos Equivalentes POS (tipo 20)
  • Notas Credito (tipo 91) y Notas Debito (tipo 92)
  • ApplicationResponse (eventos DIAN)
  • Firma digital XAdES-EPES con politica DIAN v2
  • Calculo automatico de CUFE/CUDE (SHA-384)
  • Cliente para servicios web DIAN (habilitacion y produccion)
  • CLI para generacion y envio de documentos

Compatibilidad

  • Anexo Tecnico de Factura Electronica de Venta v1.9 (Resolucion 000165/2023)
  • Python 3.9, 3.10, 3.11, 3.12

Estructura del Proyecto

facho/                            # Paquete legacy (facho.fe)
├── __init__.py
└── fe/
    ├── builders/                 # Constructores XML UBL 2.1
    │   ├── invoice_builder.py        # InvoiceBuilder, Party, Address
    │   ├── credit_note_builder.py    # CreditNoteBuilder
    │   ├── debit_note_builder.py     # DebitNoteBuilder
    │   ├── export_invoice_builder.py # ExportInvoiceBuilder
    │   ├── pos_document_builder.py   # PosDocumentBuilder
    │   ├── contingency_invoice_builder.py
    │   ├── support_document_builder.py
    │   ├── constants.py              # Constantes DIAN
    │   ├── cufe.py                   # CUFE/CUDE
    │   ├── taxes.py                  # Impuestos
    │   ├── validators.py             # Validaciones
    │   ├── exceptions.py             # Excepciones
    │   ├── allowance_charge.py       # Cargos/descuentos
    │   └── soap_client.py            # Cliente SOAP
    ├── signing/                  # Firma digital
    │   ├── xades.py                  # XAdESSigner
    │   ├── certificate.py            # Certificados PKCS#12
    │   └── utils.py
    ├── client/                   # Cliente DIAN
    │   ├── dian_simple.py            # DianSimpleClient
    │   └── tracker.py                # Tracking de documentos
    └── data/dian/                # Datos estaticos DIAN
        ├── codelists/                # Listas de codigos (.gc)
        └── XSD/                      # Esquemas XML

dian_fe/                          # Paquete modular (recomendado)
├── __init__.py                   # Exportaciones publicas (v1.0.0)
├── config.py                     # Configuracion y constantes
├── utils.py                      # CUFE, CUDE, DV, hashes
├── certificate.py                # Certificados PKCS#12
├── xades_signer.py               # Firma XAdES-EPES
├── xml_builder.py                # Generacion XML (todos los builders)
├── dian_client.py                # Cliente SOAP DIAN
├── tracker.py                    # Tracking de documentos
└── cli.py                        # Linea de comandos

Instalacion

# Desde GitHub
pip install git+https://github.com/bryamzxz/facho

# Desde codigo fuente
git clone https://github.com/bryamzxz/facho
cd facho
pip install -e .

# Con dependencias de desarrollo
pip install -e ".[dev]"

Uso Rapido

Ejemplo basico usando el paquete modular dian_fe (recomendado):

from dian_fe import (
    InvoiceBuilder, InvoiceConfig, Party, Address, InvoiceLine,
    XAdESSigner, DianClient
)

# Configuracion
config = InvoiceConfig(
    software_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    software_pin='12345',
    technical_key='clave_tecnica_dian',
    nit='900123456',
    company_name='MI EMPRESA SAS',
    resolution_number='18760000001',
    resolution_date='2024-01-01',
    resolution_end_date='2026-12-31',
    prefix='SETP',
    range_from='990000001',
    range_to='995000000',
    environment='2'  # 1=Produccion, 2=Habilitacion
)

# Proveedor (emisor)
supplier = Party(
    nit='900123456',
    name='MI EMPRESA SAS',
    legal_name='MI EMPRESA SAS',
    organization_code='1',  # Persona Juridica
    tax_level_code='O-07;O-09',
    address=Address(
        city_code='05001',
        city_name='Medellin',
        postal_zone='050001',
        country_subentity='Antioquia',
        country_subentity_code='05',
        address_line='Calle 123 #45-67'
    )
)

# Cliente (adquiriente)
customer = Party(
    nit='1234567890',
    name='CLIENTE EJEMPLO',
    legal_name='CLIENTE EJEMPLO',
    organization_code='2',  # Persona Natural
    tax_level_code='R-99-PN',
    scheme_name='13',  # Cedula
    address=Address(
        city_code='11001',
        city_name='Bogota',
        postal_zone='110111',
        country_subentity='Bogota D.C.',
        country_subentity_code='11',
        address_line='Carrera 10 #20-30'
    )
)

# Lineas de factura
lines = [
    InvoiceLine(
        description='Producto de ejemplo',
        quantity=1,
        unit_code='94',
        unit_price=100000.00,
        tax_percent=19.0
    )
]

# Crear factura
builder = InvoiceBuilder(config)
xml = builder.build(
    number='SETP990003033',
    issue_date='2026-01-08',
    issue_time='10:30:00-05:00',
    supplier=supplier,
    customer=customer,
    lines=lines
)

# Firmar
signer = XAdESSigner.from_pkcs12('certificado.p12', 'password')
signed_xml = signer.sign(xml)

# Guardar
with open('factura_firmada.xml', 'wb') as f:
    f.write(signed_xml)

Linea de Comandos (CLI)

# Ver ayuda
facho --help

# Generar factura desde especificacion Python
facho generate invoice.py

# Firmar documento XML
facho sign documento.xml --key certificado.p12 --password clave

# Enviar a DIAN
facho send documento.xml --env habilitacion

Tipos de Documentos Soportados

Documento Codigo Builder CustomizationID UUID
Factura de Venta 01 InvoiceBuilder 10 CUFE-SHA384
Factura de Exportacion 02 ExportInvoiceBuilder 02 CUFE-SHA384
Factura de Contingencia 04 ContingencyInvoiceBuilder 04 CUFE-SHA384
Documento Soporte 05 SupportDocumentBuilder 05 CUDS-SHA384
Documento POS 20 PosDocumentBuilder 20 CUDE-SHA384
Nota Credito 91 CreditNoteBuilder 20 CUDE-SHA384
Nota Debito 92 DebitNoteBuilder 30 CUDE-SHA384

Codigos de Impuestos

Codigo Sigla Descripcion
01 IVA Impuesto al Valor Agregado
02 IC Impuesto al Consumo
03 ICA Impuesto de Industria y Comercio
04 INC Impuesto Nacional al Consumo
05 ReteIVA Retencion IVA
06 ReteFte Retencion en la Fuente
07 ReteICA Retencion ICA

Conceptos de Nota Credito

Codigo Descripcion
1 Devolucion parcial de los bienes y/o no aceptacion parcial del servicio
2 Anulacion de factura electronica
3 Rebaja o descuento parcial o total
4 Ajuste de precio

Conceptos de Nota Debito

Codigo Descripcion
1 Intereses
2 Gastos por cobrar
3 Cambio del valor
4 Otros

Tests

# Ejecutar tests
pytest tests/ -v

# Ejecutar tests con cobertura
pytest tests/ --cov=facho --cov=dian_fe --cov-report=html

Contribuir

Las contribuciones son bienvenidas. Ver CONTRIBUTING.md para mas detalles.

  1. Fork del repositorio
  2. Crear rama de feature (git checkout -b feature/mi-feature)
  3. Commit de cambios (git commit -am 'Agregar mi feature')
  4. Push a la rama (git push origin feature/mi-feature)
  5. Crear Pull Request

Desarrollo con Docker

make -f Makefile.dev dev-setup
make -f Makefile.dev dev-shell
make -f Makefile.dev test

Documentacion

Referencias DIAN

Licencia

Este proyecto esta licenciado bajo los terminos de la licencia que se encuentra en el archivo LICENSE.

Autores

Ver AUTHORS.md para la lista de contribuidores.

About

Facturacion Electronica Colombia

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.5%
  • Other 0.5%