class TotalProductSales(ReportView):
report_title = _("Product Sales Quantity and Value [no auto load]")
report_description = _("We compute the report over *two* fields `quantity and `value`."
"Results only load after you press Filter")
report_model = SalesTransaction
date_field = "date"
group_by = "product"
columns = [
"name",
ComputationField.create(Sum, "quantity", verbose_name="Total quantity sold", is_summable=False),
ComputationField.create(Sum, "value", name="sum__value", verbose_name="Total Value sold $"),
]
auto_load = False # Require the user to press the filter, useful if the report is resource demanding
chart_settings = [
Chart(
"Total sold $",
Chart.BAR,
data_source=["sum__value"],
title_source=["name"],
),
Chart(
"Total sold $ [PIE]",
Chart.PIE,
data_source=["sum__value"],
title_source=["name"],
),
]