Skip to main content

PyPI - Python Version GitHub Actions Workflow Status PyPI - Version

django-ticketbai

django-ticketbai allows to create, manage, store and send TicketBai invoices to the Basque tax authorities.

Requirements

  • Python 3.11 or newer
  • Django 4.2 or 5.2

Installation

pip install django-ticketbai

Add the app to INSTALLED_APPS and run its migrations:

INSTALLED_APPS = [
    # ...
    "django_ticketbai",
]
python manage.py migrate django_ticketbai

Configuration

Two things have to be configured:

Data Where
Issuer and software data the TICKETBAI_CONF setting
Invoice series and signing certificate the Config model (editable in the admin)

The TICKETBAI_CONF setting

TICKETBAI_CONF is a dictionary with two mandatory sections, subject (the issuer of the invoices) and software (the TicketBai software declaration). It is passed as-is to pytbai, so its structure is the one pytbai.TBai expects:

{
  "subject": {
    "entity_id": "B12345678",
    "name": "ACME S.L.",
    "address": "Main street 1",
    "territory": "Gipuzkoa"
  },
  "software": {
    "license": "TBAIGIPRE00000000001",
    "dev_entity": "B00000000",
    "soft_name": "django-ticketbai",
    "soft_version": "1.0"
  }
}

In your Django settings:

TICKETBAI_CONF = {
    "subject": {
        "entity_id": "B12345678",
        "name": "ACME S.L.",
        "address": "Main street 1",
        "territory": "Gipuzkoa",
    },
    "software": {
        "license": "TBAIGIPRE00000000001",
        "dev_entity": "B00000000",
        "soft_name": "django-ticketbai",
        "soft_version": "1.0",
    },
}

subject

Key Required Default Description
entity_id yes – Tax id (NIF) of the issuer
name yes – Name of the issuer
address no None Address shown in the invoice PDF
territory no "Gipuzkoa" Araba, Bizkaia or Gipuzkoa
multi_recipient no "N" S (yes) or N (no)
external_invoice no "N" N, T or D, see pytbai.definitions.L4

software

Key Required Default Description
license yes – TicketBai licence of the software
dev_entity yes – Tax id (NIF) of the software developer
soft_name yes – Name of the software
soft_version yes – Version of the software

Notes

  • Do not add env to TICKETBAI_CONF: django-ticketbai sets it automatically.
  • Test or production endpoint is chosen with the DEBUG setting: DEBUG = True sends the invoices to the testing environment and DEBUG = False to the production one. Make sure DEBUG is False in production, otherwise the invoices are not sent to the Basque tax authorities but to the test service.
  • The models are registered in the Django admin only when the TICKETBAI_CONF setting is defined.
  • The bundled test view (django_ticketbai.views.test_send_and_store_invoice) answers KO when the setting is missing.

The Config model

The Config model holds the data that can change between installations, and it is meant to be edited in the Django admin:

Field Description
prefix, suffix Invoice series
pks12 PKCS#12 (.p12) certificate used to sign the invoices
password Password of the certificate
logo Optional logo shown in the invoice PDF
is_active Only the active configuration is used

At least one active Config object is required before creating an invoice.

Usage

from django.conf import settings

from django_ticketbai.utils.invoice import create_one_line_simplified_invoice

invoice = create_one_line_simplified_invoice(
    settings.TICKETBAI_CONF,
    "Simplified invoice",  # invoice description
    "customer@example.com",  # recipient email
    "Product",  # line description
    "1",  # quantity
    "200",  # unit price
)

The invoice is signed with the certificate of the active Config, stored, and sent to the corresponding endpoint. The signature of the previous invoice is chained automatically. The PDF is stored in the pdf field of the invoice.

Metadata

Release files for django-ticketbai 2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ticketbai 2.3
File Size Uploaded
django_ticketbai-2.3.tar.gz 23.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ticketbai 2.3
File Interpreter ABI Platform
django_ticketbai-2.3-py3-none-any.whl Python 3 none any Details

Total release size: 51.9 kB

Release files / django_ticketbai-2.3.tar.gz

Download URL django_ticketbai-2.3.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
22370e256a297449eda8b135be085831a2d79099ec2a6e5dd723bfe262a38d52
BLAKE2b-256 checksum
How to use checksums
f3bf1412e284eb95f91af2749787d0145ee763c603979a5e412e9b69291a93c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / django_ticketbai-2.3-py3-none-any.whl

Download URL django_ticketbai-2.3-py3-none-any.whl
Size 28.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78bfa7cd3cba7a5fe2a5cd1bf0506704c82e424ec35687309006df2ee93aa2aa
BLAKE2b-256 checksum
How to use checksums
ded2b3af2b615f8b925cf5c20b96cbba6400b6518281301051b49028e2518fed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

2.4

2 release files

This release

2.3 This release

2 release files

2.2

2 release files

2.1

2 release files

2.0

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page