BaseDocumentReport

Developer guide for the Enezaframework reporting engine. Part of the Add Report series.

Table of Contents

  1. Overview
  2. Class Definition and MRO
  3. Required Attributes
  4. Optional Attributes
  5. report_name: Multiple Reports Per Model
  6. model Must Be Set
  7. Related Guides

Overview

DocumentReportView is the preferred single base class for document reports accessed via URL pk. It subclasses BaseDocumentReport, the compatibility base that combines DocumentReport (report type semantics) with DocumentReportPageView (URL dispatch, rendering, and designer integration), so a developer writes one class instead of two.

Location: enezareporting/report_base.py (DocumentReportView) and enezareporting/views.py (BaseDocumentReport).


Class Definition and MRO

python
class DocumentReportView(BaseDocumentReport):
    """Single-parent base for document (header + lines) reports."""
    __abstract__ = True


class BaseDocumentReport(DocumentReport, DocumentReportPageView):
    """Compatibility base for existing definitions."""
    __abstract__ = True
classDiagram
    class ReportEngineView
    class DesignTemplateMixin
    class DocumentReportPageView
    class DocumentReport
    class BaseDocumentReport
    class DocumentReportView

    ReportEngineView <|-- DocumentReportPageView
    DesignTemplateMixin <|-- DocumentReportPageView
    DocumentReport <|-- BaseDocumentReport
    DocumentReportPageView <|-- BaseDocumentReport
    BaseDocumentReport <|-- DocumentReportView

The effective MRO is: DocumentReportView → BaseDocumentReport → DocumentReport → DocumentReportPageView → DesignTemplateMixin → ReportEngineView.


Required Attributes

Attribute Description
model Django model for the document header. Required by get_registered_urls().
header_model Same as model (document header model for the generator).
header_fields Field name strings to display in the header grid.
line_columns Field name strings as columns in the lines table.

DocumentReportView raises ImproperlyConfigured at class creation when header_model is set but header_fields or line_columns is empty.


Optional Attributes

Attribute Default Description
report_name model.__name__.lower() Custom URL name segment. Set when one model has multiple reports.
lines_related_name "lines" Related name on the header model for line items.
line_total_fields [] Numeric fields to sum in the totals footer.
design_slug None Set to a ReportDesign.slug for a designer layout.

report_name: Multiple Reports Per Model

One model can serve many reports; report_name controls the URL name segment.

python
# If report_name is NOT set, the URL defaults to the model name:
class SalesInvoiceView(DocumentReportView):
    model = Invoice
    # No report_name → URL name: invoice_report


# Set report_name to distinguish multiple reports:
class PurchaseInvoiceView(DocumentReportView):
    model = Invoice
    report_name = "purchase_invoice"
    # URL name: purchase_invoice_report


class TaxInvoiceView(DocumentReportView):
    model = Invoice
    report_name = "tax_invoice"
    # URL name: tax_invoice_report

See the URL naming table in Document Report URLs, Designer & Rendering.


model Must Be Set

get_registered_urls() checks issubclass(view_class.model, Model). Every DocumentReportView child must set model = TheHeaderModel, even though @auto_url_register on a View subclass technically does not require it.

python
@auto_url_register
class InvoiceReportView(DocumentReportView):
    model = Invoice  # required for URL registration