Printable Receipts

Version 1.2.0 introduced PDF-generation for validated receipts. This functionality is backed mostly by three model classes:

  • TaxPayerProfile: Contains the TaxPayer’s metadata (such as name, address, etc).
  • ReceiptPDF: Contains receipts’ metadata which is required for the PDF generation. Since the information in TaxPayerProfile is bound to change over time, it’s actually copied over to ReceiptPDF.
  • ReceiptEntry: Represents a single entry (e.g.: an item in an invoice) in a printable receipt.

Creation of ReceiptPDF instances can generally be done with the create_for_receipt() helper method. ReceiptEntry instances should be created manually.

The PDF files themselves are created the first time you save the model instance (via a pre_save hook). You can generate (either before saving, or because you need to regenerate it) by calling ReceiptPDF.save_pdf().

Note that the TaxPayerProfile model is merely a helper one – it’s entirely possible to construct ReceiptPDF manually without them.


Since version 3.2.0, PDFs include the barcode defined in AFIP 1702/04.

Version 3.2.0 used the receipt’s expiration date for the barcode. After some debate with fellow developers and accountants, we’ve resolved that the CAE’s expiration date should be used. Even though resolution 1702/04 does not explicitly state this (it just says “Expiration Date”, their own receipt PDFs use this date. Also, not all receipts have expiration dates.

It was also later confirmed via a response from AFIP that the CAE expiration should be used.

Exposing receipts


Printable receipts can be exposed via views. They all require a pk URL-param, so URL registration should look something like:


Note that you’ll generally want to subclass these and add some for of permission checking.

class django_afip.views.ReceiptHTMLView(**kwargs)

Renders a receipt as HTML.

class django_afip.views.ReceiptPDFView(**kwargs)

Renders a receipt as a PDF, prompting to download it.

class django_afip.views.ReceiptPDFDisplayView(**kwargs)

Renders a receipt as a PDF.

Browsers should render the file, rather than prompt to download it.


The template used for the HTML and PDF receipts is found in templates/receipts/code_X.html, where X is the ReceiptType‘s code. If you want to override the default (you probably do), simply place a template with the same path/name inside your own app, and make sure it’s listed before django_afip in INSTALLED_APPS.

Note that you may also expose receipts as plain Django media files. The URL will be relative or absolute depending on your media files configuration.

printable = ReceiptPDF.objects.last()
# <FieldFile: receipts/790bc4f648e844bda7149ac517fdcf65.pdf>
# '/media/receipts/790bc4f648e844bda7149ac517fdcf65.pdf'