Finding a mistake immediately after issuing an invoice is normal. Changing the customer name, editing a line and generating the PDF again looks like the fastest solution.
It also destroys the history of what was issued.
An issued invoice is not a living template. It has a number, date, and accounting and fiscal effects. A correction must add documents or records explaining what changed, not rewrite the past.
First identify what happened
Not every change is the same operation:
- Refund or discount: the sale happened, but some or all of its value is returned.
- Customer, line or tax error: the transaction happened, but the invoice contains incorrect data and needs a correct version.
- Issued by mistake: the transaction never happened and the invoice should not have been issued.
The correct reason determines whether you need a credit note, a replacement invoice or a cancellation record. “Cancel” is not a universal button for making any inconvenient invoice disappear.
The original invoice remains
The AEAT states that invoices issued in error must retain their numbering. Under VERI*FACTU, the original registration record also remains in the chain.
When an invoice for a transaction that never happened must be cancelled, a new cancellation record is created identifying the original registration record. If a correct invoice must then be issued, it will have a different number or issue date.
When a statutory rectification cause exists—for example, an incorrectly calculated tax amount or a change to the taxable base—a correcting invoice is issued. Codes R1 to R5 and the correction-by-difference or correction-by-substitution method describe that correction for tax purposes.
The common principle is simple: the original is not modified. The history is extended.
How FiscalRail models it
FiscalRail creates an amendment linked to the original invoice. The selected reason determines the generated documents:
- For a refund or discount, it creates a full credit note and may create a lower-value replacement.
- To correct customer, line or tax data, it creates the full credit note and the required replacement containing the correct data.
- For a transaction that never happened, issued_by_mistake voids the invoice without creating a credit note or replacement.
For Spanish accounts, FiscalRail also creates the corresponding VERI*FACTU registration, correction or cancellation records. The original, credit note and replacement remain separate retrievable documents linked through the amendment.
The correction must be atomic and idempotent
A correction may consume numbers from several series and create several documents. Issuing the credit note and failing before the replacement would leave an incomplete result.
FiscalRail therefore validates and commits the entire amendment as one operation. If any generated document is invalid, none is issued and no series number is consumed.
Send an idempotency key as well. If the connection fails after the operation commits, retry the exact same request with the same key. FiscalRail returns the earlier result instead of correcting the invoice twice.
Each document can be amended once. If a replacement needs another correction, apply the next amendment to that replacement rather than to the first invoice.
An AEAT rejection is not a commercial correction
A rejected VERI*FACTU record means that the AEAT did not accept the fiscal record. It does not automatically mean the sale must be refunded or another invoice issued.
Inspect the error first and decide whether the record must be repaired or the invoice itself corrected. FiscalRail blocks ordinary commercial amendment reasons while the original VERI*FACTU registration record is rejected; a credit note or replacement must not be used as a shortcut for repairing a fiscal rejection. The issued_by_mistake reason, reserved for transactions that never occurred, follows a separate cancellation path.
Confusing a transport or validation problem with a commercial refund usually creates more incorrect documents, not fewer.
Test the complete workflow
A sound integration retains the IDs of the original, credit note and replacement; processes events without assuming order; and shows users the complete relationship between the documents.
Read the correcting invoices guide and the AEAT's invoicing procedures FAQ. You can exercise corrections and cancellations in a Test account without submitting data to the AEAT.
This article is not tax advice. The correct document depends on the reason and circumstances of the transaction; ask your adviser.
