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.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_ticketbai-2.4.tar.gz | 23.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_ticketbai-2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.9 kB
Release files / django_ticketbai-2.4.tar.gz
| Download URL | django_ticketbai-2.4.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee0e7222a3fa6bf6312c2a2806a5a5425eeb8ca132ca1b6a0b65132dbcd84476
|
|
BLAKE2b-256 checksum How to use checksums |
784c3beaf3700a360f01d1043024cd3da64084101d5e9943f10a3bf52fb3e4b0
|
| 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.4-py3-none-any.whl
| Download URL | django_ticketbai-2.4-py3-none-any.whl |
|---|---|
| Size | 28.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b71ca842cb6a07850fcd2f38a1d0b7feb10a6966c8ff2c14ddca0129e9d8752
|
|
BLAKE2b-256 checksum How to use checksums |
fef9fa5b0a524bb50c4a8b6bf02a76941f323f6747767448de6493331be7857f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|