class PreComputedMonthlySales(ReportView):
report_title = _("Crosstab Precomputed: Monthly Sales")
report_description = _("Uses crosstab_precomputed=True on a model whose rows are already aggregated. "
"Columns are the distinct month values discovered at query time — no aggregation needed.")
report_model = MonthlySalesSummary
date_field = "month"
group_by = "product"
crosstab_field = "month"
crosstab_precomputed = True # signals that data is already aggregated
crosstab_columns = ["total_sales", "total_quantity"] # These fields are already computed/aggregated in database
columns = ["name", "__crosstab__"]
chart_settings = [
Chart(
_("Monthly Sales by Product"),
Chart.BAR,
data_source=["total_sales"],
title_source=["name"],
),
Chart(
_("Monthly Quantity by Product"),
Chart.LINE,
data_source=["total_quantity"],
title_source=["name"],
),
]