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.

Test environment and test NIF included
Read the documentation

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.

Test environment and test NIF included

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.

  1. Register the NIF with the NIF management API and sign the representation form. Each NIF has its own API key.
  2. Create your own module that inherits account.move and extends _post: that covers the Post button, bulk posting, auto-posting and point-of-sale invoices.
  3. Call POST /verifactu/create (or /ticketbai/create, depending on the company) with the company's API key.
  4. Store qr, huella and uuid in invoice fields and add the QR to the PDF report.
  5. 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.

models/account_move.py · Odoo 16–18
# 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

Special cases when invoicing from Odoo
CaseWhat to doRead more
NumberingEvery invoice needs a series with sequential numbering. If invoice numbers can have gaps, give the invoice its own numberVerifactu requirements
Customer without a NIFSimplified invoice (F2), without nif or nombre. The API rejects an F2 above €3,000 (vf-verifactu-f2_limite_3000)Simplified invoice
Return or refundCorrective invoice: R5 if the original was simplified; R1–R4 if it was a full invoiceCorrective invoices
Customer asks for a full invoice laterExchange invoice (F3) replacing the simplified oneExchange invoice
Canary Islands, Ceuta and MelillaIGIC or IPSI in the lines (impuesto field), not VATIGIC · IPSI
Products without VATCheck whether they are exempt (operacion_exenta) or not subject (calificacion_operacion): they are not sent at rate 0Exempt invoice
CancellationOnly for invoices that should never have been issued: POST /verifactu/cancelCancellation
Sale to another EU countryIt depends on whether the customer is a business and on the distance-selling thresholdIntra-EU examples
Equivalence surchargetipo_recargo_equivalencia and cuota_recargo_equivalencia on the VAT line, not as another lineEquivalence surcharge
IRPF withholdingNot sent: importe_total is base + tax (+ surcharge), without subtracting the withholdingDisbursements and withholding
Several companies or shopsOne NIF per company, each with its own API keyNIF 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.

Producers and resellers of invoicing softwareSince 29 Jul 2025
RDL 15/2025 did not change this date.
In force
Corporate Income Tax payers1 Jan 2027
Published in the BOE, future date
Everyone else, including the self-employed1 Jul 2027
Published in the BOE, future date
Postponement of the pending obligationsOct 2028
The note does not specify the scope for businesses invoicing over €8M.
Announced, no rule published
TicketBAI in Álava: foral taxpayersSince 1 Dec 2022
Phased from 1 April 2022; all other taxpayers since 1 December 2022.
In force
Batuz in Bizkaia (TicketBAI and LROE): all taxpayersSince 1 Jan 2026
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.
In force
TicketBAI in Gipuzkoa: foral taxpayersSince 1 Jun 2023
Phased by activity from 1 July 2022.
In force

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.

Questions about Verifactu and Odoo

More questions about Verifactu

Is there a module or app from Verifacti for Odoo?

No. Verifacti is an API: Odoo connects to it with the code on this page, in your own development. There are third-party modules in the Odoo Apps store.

Does Odoo comply with Verifactu on its own?

It depends on your version and what you have installed: check with your provider. Whoever invoices needs a system that generates the invoicing records and sends them to the AEAT. Which obligation each business has depends on its case: who Verifactu applies to.

Does it work for TicketBAI too?

Yes. If the NIF is taxed in Álava, Bizkaia or Gipuzkoa, the flow is the same with the TicketBAI API: the endpoint (/ticketbai/create), the invoice fields and the API key change.

Do I need a digital certificate?

No. Verifacti is an AEAT social collaborator and submits with its own certificate once the taxpayer signs the representation form, the same one for the AEAT and the foral treasuries. It can be signed online, without a certificate.

How much does it cost?

From €14.99 per month for the first NIF active in production, VAT excluded, with the Verifactu API or the TicketBAI API. The test environment and test NIF are free. Every plan, in pricing.

Connect Odoo in the test environment

Create your free account and try the API with a test NIF before going to production.

Test environment and test NIF includedRead the documentation