generate_fattura_xml
Assemble prepared blocks into a complete FatturaPA v1.2.3 XML document for Italian e-invoicing. Returns the final XML string, filename, and transmission format, ready for XSD validation.
Instructions
Assemble a complete FatturaPA v1.2.3 XML document from all prepared blocks.
Use this as step 10 in the invoice generation workflow — the final assembly step. All required blocks must come from their respective builder/validator tools; pass the full dict returned by each tool (the function unwraps the top-level key).
Required: dati_trasmissione, cedente_prestatore, cessionario_committente, dati_generali, dettaglio_linee (list), dati_riepilogo (list from compute_totali()). Optional: dati_pagamento, allegati (list), dati_ritenuta.
Does NOT validate against the XSD schema — call validate_fattura_xsd() (step 11) on the returned 'xml' string immediately after to confirm conformance.
On success returns {'xml': str, 'filename': str, 'formato_trasmissione': str, 'length_bytes': int}. On unexpected error returns {'error': ''}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| allegati | No | List of Allegati dicts from add_allegato(). Optional. | |
| dati_generali | Yes | DatiGenerali block from build_dati_generali(). Contains document type, date, number, and currency. | |
| dati_ritenuta | No | DatiRitenuta block from check_ritenuta_acconto(). Required for professional invoices with withholding tax (ritenuta d'acconto). | |
| dati_pagamento | No | DatiPagamento block from build_dati_pagamento(). Optional. | |
| dati_riepilogo | Yes | List of DatiRiepilogo dicts from compute_totali(). Contains VAT summary grouped by AliquotaIVA. | |
| dettaglio_linee | Yes | List of DettaglioLinee dicts from add_linea_dettaglio(). Each entry must have NumeroLinea, Descrizione, PrezzoUnitario, PrezzoTotale, and AliquotaIVA. | |
| additional_bodies | No | Additional FatturaElettronicaBody blocks for FPA12 batch invoicing. Each entry is a dict with keys: dati_generali, dettaglio_linee, dati_riepilogo, and optionally dati_pagamento, allegati, dati_ritenuta. Only valid for FPA12 (B2G) transmissions; FPR12 does not support batching. | |
| dati_trasmissione | Yes | DatiTrasmissione block from build_transmission_header(). Must contain IdTrasmittente, ProgressivoInvio, FormatoTrasmissione, and CodiceDestinatario. | |
| cedente_prestatore | Yes | CedentePrestatore block from validate_cedente_prestatore(). Contains seller's tax ID, name, address, and fiscal regime. | |
| cessionario_committente | Yes | CessionarioCommittente block from validate_cessionario(). Contains buyer's tax ID, name, and address. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||