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
envtoTICKETBAI_CONF:django-ticketbaisets it automatically. - Test or production endpoint is chosen with the
DEBUGsetting:DEBUG = Truesends the invoices to the testing environment andDEBUG = Falseto the production one. Make sureDEBUGisFalsein 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_CONFsetting is defined. - The bundled test view (
django_ticketbai.views.test_send_and_store_invoice) answersKOwhen 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.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_ticketbai-2.5.tar.gz | 24.8 kB | Without provenance | Details for django_ticketbai-2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ticketbai-2.5-py3-none-any.whl | Python 3 | none | any | Details for django_ticketbai-2.5-py3-none-any.whl |
Total release size: 53.2 kB
Release files / django_ticketbai-2.5.tar.gz
| Download URL | django_ticketbai-2.5.tar.gz |
|---|---|
| Size | 24.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a98688dcbcb2f9076fef70819e65c1de97073e7bfa49a56cda838252c0f87c86
|
|
BLAKE2b-256 checksum How to use checksums |
a7af367600da345c33b15757c5a324ccd6dd7dd38593e21de5184d0e2d55817c
|
| 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.5-py3-none-any.whl
| Download URL | django_ticketbai-2.5-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cd7654c9e8fe9e1b1f0c93747f2618b1afbd62fbfb70d11f77afa2b7a7f74b8
|
|
BLAKE2b-256 checksum How to use checksums |
8816a07d51b8e14de9851ca2ec48c0db49fe07df2f881e4d8adba74a799e8d89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for django-ticketbai 2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.