Verifactu in Odoo: how to connect Odoo with the Verifactu API
Verifacti has no official Odoo module: Odoo connects to the Verifactu API from your own module that, when an invoice is posted, sends its data as JSON and stores the QR the API returns. No XML to generate, no hash to compute and no digital certificate: Verifacti sends the invoicing record to the AEAT as a colaborador social. The same pattern works for TicketBAI with the TicketBAI API.
Which APIs you need for Odoo
Your connector uses two pieces: the submission API that matches the NIF (Verifactu API in common territory; TicketBAI API in Álava, Bizkaia and Gipuzkoa) and the NIF management API, integrated once to register the NIF, manage the representation form and receive webhooks. Each NIF uses one API or the other depending on where it is taxed.
How to connect Odoo with the API
Flow: posted invoice in Odoo (_post of account.move) → your module → Verifactu API or TicketBAI API → AEAT or foral treasury.
- Register the NIF with the NIF management API and sign the representation form. Each NIF has its own API key.
- Create your own module that inherits
account.moveand extends_post: that covers the Post button, bulk posting, auto-posting and point-of-sale invoices. - Call
POST /verifactu/create(or/ticketbai/create, depending on the company) with the company's API key. - Store
qr,huellaanduuidin invoice fields and add the QR to the PDF report. - Credit notes are sent as corrective invoices.
Do you build software and want to offer Verifactu to your customers? See ERP vendors.
Example: from the posted invoice to the record
The model inherits account.move. Bases and tax amounts come from the tax lines, in company currency: the IRPF withholding is not sent and the equivalence surcharge goes on its VAT line. The total is the sum of what is sent. If the API answers with an error, posting is rolled back and Odoo shows the message; a registered invoice cannot go back to draft. If you post in bulk and one invoice fails, the earlier ones in the batch are already registered even though Odoo rolls back: post one by one or send from a queue.
# verifacti/models/account_move.py · módulo propio para Odoo 16, 17 y 18.
# Envía cada factura de cliente publicada a la API Verifactu y guarda el QR en la factura.
import hashlib
import json
import requests
from odoo import _, fields, models
from odoo.exceptions import UserError
# Recargo de equivalencia → tipo de IVA al que acompaña
RECARGO = {5.2: 21.0, 1.75: 21.0, 1.4: 10.0, 0.62: 5.0, 0.5: 4.0, 0.26: 2.0}
class ResCompany(models.Model):
_inherit = "res.company"
verifacti_api_key = fields.Char(groups="base.group_system")
class AccountMove(models.Model):
_inherit = "account.move"
verifactu_uuid = fields.Char(copy=False, readonly=True)
verifactu_qr = fields.Binary(copy=False, readonly=True)
verifactu_huella = fields.Char(copy=False, readonly=True)
# _post cubre el botón, la publicación en lote, la automática y las facturas del TPV
def _post(self, soft=True):
posted = super()._post(soft)
for move in posted.filtered(lambda m: m.move_type == "out_invoice" and not m.verifactu_uuid):
move._verifactu_enviar()
return posted
def button_draft(self):
if any(self.mapped("verifactu_uuid")):
raise UserError(_("Esta factura ya está registrada en Verifactu: corrígela con una rectificativa."))
return super().button_draft()
def _verifactu_factura(self):
lineas = {}
for tax_line in self.line_ids.filtered("tax_line_id"):
tasa = tax_line.tax_line_id.amount
if tasa < 0:
continue # retención de IRPF: no va en el registro
tipo = RECARGO.get(tasa, tasa)
linea = lineas.setdefault(tipo, {"base": 0.0, "cuota": 0.0, "recargo": 0.0, "tipo_recargo": 0.0})
if tasa in RECARGO:
linea["recargo"] += -tax_line.balance
linea["tipo_recargo"] = tasa
else:
linea["base"] += tax_line.tax_base_amount
linea["cuota"] += -tax_line.balance
serie, _sep, numero = self.name.rpartition("/")
vat = self.partner_id.vat or ""
nif = vat[2:] if vat.startswith("ES") else vat
envio = []
for tipo, l in lineas.items():
linea = {
"base_imponible": f"{l['base']:.2f}",
"tipo_impositivo": f"{tipo:g}",
"cuota_repercutida": f"{l['cuota']:.2f}",
}
if l["recargo"]:
linea.update(tipo_recargo_equivalencia=f"{l['tipo_recargo']:g}", cuota_recargo_equivalencia=f"{l['recargo']:.2f}")
envio.append(linea)
# Importes en la moneda de la compañía; el total es la suma de lo que se envía (sin la retención)
total = sum(l["base"] + l["cuota"] + l["recargo"] for l in lineas.values())
factura = {
"serie": serie + "/",
"numero": numero,
"fecha_expedicion": self.invoice_date.strftime("%d-%m-%Y"),
"tipo_factura": "F1" if nif else "F2",
"descripcion": self.ref or self.invoice_line_ids[:1].name or self.name,
"lineas": envio,
"importe_total": f"{total:.2f}",
}
if nif:
factura.update(nif=nif, nombre=self.commercial_partner_id.name)
return factura
def _verifactu_enviar(self):
cuerpo = json.dumps(self._verifactu_factura())
huella_cuerpo = hashlib.sha256(cuerpo.encode()).hexdigest()[:12]
r = requests.post(
"https://api.verifacti.com/verifactu/create",
data=cuerpo,
headers={
"Authorization": f"Bearer {self.company_id.sudo().verifacti_api_key}",
"Content-Type": "application/json",
"Idempotency-Key": f"odoo-{self.env.cr.dbname}-{self.id}-{huella_cuerpo}",
},
timeout=30,
)
registro = r.json()
if r.status_code != 200:
raise UserError(_("Verifactu: %s", registro.get("error")))
self.write({
"verifactu_uuid": registro["uuid"],
"verifactu_qr": registro["qr"],
"verifactu_huella": registro["huella"],
})The code groups the lines by VAT rate and uses F1 if the customer has a NIF and F2 otherwise. It sends the Idempotency-Key header with the invoice identifier plus a digest of the body: an identical retry never duplicates the invoice and, if you fix the data after an error, the key changes. The response carries the uuid, the state (Pendiente: the submission to the AEAT is queued), the verification URL, the QR in Base64 and the hash: store them with the invoice.
More code in the Verifactu tutorial in Python. For TicketBAI, the call goes to POST /ticketbai/create with the foral NIF's API key: the fields, in the TicketBAI API documentation.
Special cases in Odoo
| Case | What to do | Read more |
|---|---|---|
| Numbering | Every invoice needs a series with sequential numbering. If invoice numbers can have gaps, give the invoice its own number | Verifactu requirements |
| Customer without a NIF | Simplified invoice (F2), without nif or nombre. The API rejects an F2 above €3,000 (vf-verifactu-f2_limite_3000) | Simplified invoice |
| Return or refund | Corrective invoice: R5 if the original was simplified; R1–R4 if it was a full invoice | Corrective invoices |
| Customer asks for a full invoice later | Exchange invoice (F3) replacing the simplified one | Exchange invoice |
| Canary Islands, Ceuta and Melilla | IGIC or IPSI in the lines (impuesto field), not VAT | IGIC · IPSI |
| Products without VAT | Check whether they are exempt (operacion_exenta) or not subject (calificacion_operacion): they are not sent at rate 0 | Exempt invoice |
| Cancellation | Only for invoices that should never have been issued: POST /verifactu/cancel | Cancellation |
| Sale to another EU country | It depends on whether the customer is a business and on the distance-selling threshold | Intra-EU examples |
| Equivalence surcharge | tipo_recargo_equivalencia and cuota_recargo_equivalencia on the VAT line, not as another line | Equivalence surcharge |
| IRPF withholding | Not sent: importe_total is base + tax (+ surcharge), without subtracting the withholding | Disbursements and withholding |
| Several companies or shops | One NIF per company, each with its own API key | NIF management API |
Dates
The first row only applies if you build the connector to sell it: then you sell invoicing software. For those who invoice, the Verifactu dates are published in the BOE and the postponement to October 2028 is announced with no rule published. In Álava, Bizkaia and Gipuzkoa, TicketBAI is in force.
| Who | Date | Status | Rule |
|---|---|---|---|
| Producers and resellers of invoicing software RDL 15/2025 did not change this date. | Since 29 Jul 2025 | In force | RD 1007/2023 · Orden HAC/1177/2024 |
| Corporate Income Tax payers | 1 Jan 2027 | Published in the BOE, future date | RDL 15/2025 |
| Everyone else, including the self-employed | 1 Jul 2027 | Published in the BOE, future date | RDL 15/2025 |
| Postponement of the pending obligations The note does not specify the scope for businesses invoicing over €8M. | Oct 2028 | Announced, no rule published | Nota de Hacienda, 5 oct 2026 |
| TicketBAI in Álava: foral taxpayers Phased from 1 April 2022; all other taxpayers since 1 December 2022. | Since 1 Dec 2022 | In force | NF 13/2021 y DF 48/2021 · FAQ 1.9 · calendario |
| Batuz in Bizkaia (TicketBAI and LROE): all taxpayers Companies that are not SMEs since 1 January 2024; everyone else in windows on 1 July 2024, 1 January 2025, 1 July 2025 and 1 January 2026. | Since 1 Jan 2026 | In force | NF 8/2023 · Batuz |
| TicketBAI in Gipuzkoa: foral taxpayers Phased by activity from 1 July 2022. | Since 1 Jun 2023 | In force | NF 3/2020 · DF 32/2020 |
This is not advice: each taxpayer determines what applies to them with their adviser.
More detail in Verifactu dates and TicketBAI.
Pricing
Public tariff of the Verifactu API and the TicketBAI API: you pay per NIF active in production, VAT excluded. Custom per-NIF pricing is available for volume.
From
€14.99
per month for the first NIF active in production, VAT excluded
See all pricing- The price per NIF goes down with every tier.
- Free test environment and test NIF.
- Annual plan with a 10% discount, no setup fees.
- Up to 3,000 invoicing records per month per NIF.
- Startup plan for companies under 12 months old, with under €100,000 in revenue and under €200,000 in funding.
- Same price with the Verifactu API and the TicketBAI API: each NIF uses one or the other depending on where it is taxed.
- Online signing of the representation form: €2.90 + VAT per signature.
Developer resources
For your AI: llms.txt and the OpenAPI specification.
Questions about Verifactu and Odoo
More questions about VerifactuIs there a module or app from Verifacti for Odoo?
Does Odoo comply with Verifactu on its own?
Does it work for TicketBAI too?
/ticketbai/create), the invoice fields and the API key change.Do I need a digital certificate?
How much does it cost?
Other integrations
Connect Odoo in the test environment
Create your free account and try the API with a test NIF before going to production.