From 786b52d016837e9c1b1171b731e0c9f369227a72 Mon Sep 17 00:00:00 2001
From: "Tuan (Tristan) Le" <38996499+tristanle22@users.noreply.github.com>
Date: Fri, 20 Jun 2025 00:06:28 -0400
Subject: [PATCH] Report merge (#9532)
* Report merge
* Remove auto-generated file
* Remove pre-commit file
* Revert "Remove pre-commit file"
This reverts commit 00d80bae2a551d103473bb932efa03cff18b5e9f.
* Update API version
* Reduced duplicated logic
* reset pre-commit config
* Added migration files
* Added unit test
* Removed redundant migration
* Updated migration file
* Added a default report template with merge enabled
* Unit test to ensure a single page is generated
* Added docs to support merge feature
* Clean up
* Clean up
* Fixed unresolved link
* Updated API version
* Fixed test report path issue
* Add plugin context for each instance
* merge in master
* Fixed formating
* Added more detailed user guide
* Updated docs
* Added assert to ensure test html output exists
* Updated docs
* Fixed report test path
---------
Co-authored-by: Matthias Mair
---
docs/docs/api/schema.md | 2 +-
docs/docs/report/context_variables.md | 22 +++
docs/docs/report/report.md | 2 +
docs/docs/report/samples.md | 6 +
.../InvenTree/InvenTree/api_version.py | 5 +-
src/backend/InvenTree/report/apps.py | 7 +
.../migrations/0031_reporttemplate_merge.py | 22 +++
src/backend/InvenTree/report/models.py | 135 +++++++++++++-----
src/backend/InvenTree/report/serializers.py | 7 +-
.../report/inventree_stock_report_merge.html | 127 ++++++++++++++++
src/backend/InvenTree/report/tests.py | 33 +++++
.../AdminCenter/ReportTemplatePanel.tsx | 6 +
12 files changed, 337 insertions(+), 37 deletions(-)
create mode 100644 src/backend/InvenTree/report/migrations/0031_reporttemplate_merge.py
create mode 100644 src/backend/InvenTree/report/templates/report/inventree_stock_report_merge.html
diff --git a/docs/docs/api/schema.md b/docs/docs/api/schema.md
index 5d4ac82a23..f4ce2837f3 100644
--- a/docs/docs/api/schema.md
+++ b/docs/docs/api/schema.md
@@ -7,7 +7,7 @@ The API schema as documented below is generated using the [drf-spectactular](htt
## API Version
-This documentation is for API version: `339`
+This documentation is for API version: `352`
!!! tip "API Schema History"
We track API schema changes, and provide a snapshot of each API schema version in the [API schema repository](https://github.com/inventree/schema/).
diff --git a/docs/docs/report/context_variables.md b/docs/docs/report/context_variables.md
index 670a26fea5..ddd8a8d8d0 100644
--- a/docs/docs/report/context_variables.md
+++ b/docs/docs/report/context_variables.md
@@ -23,6 +23,28 @@ In addition to the [global context](#global-context), all *report* templates hav
{{ report_context("base", "report") }}
+When using the `merge` context variable, the selected items are available in the `instances` list. {{ templatefile("report/inventree_stock_report_merge.html") }} shows a complete example. To access individual item attributes, you can either loop through the `instances` or access them by index like `instance.0.name`.
+
+Below is an example template that generates a single report for some selected parts. Each part occupies a row in the table
+
+```html
+{% raw %}
+
Merged Report for Selected Parts
+
+
+{% endraw %}
+```
+
Note that custom plugins may also add additional context variables to the report context.
::: report.models.ReportTemplate.get_context
diff --git a/docs/docs/report/report.md b/docs/docs/report/report.md
index cff02f5141..795c0f9483 100644
--- a/docs/docs/report/report.md
+++ b/docs/docs/report/report.md
@@ -44,3 +44,5 @@ For example, rendering the name of a part (which is available in the particular
+
+ {% for part in instances %}
+ Name
+ Description
+
+
+ {% endfor %}
+{{ part.name }}
+ {{ part.description }}
+
{{ item.part.description }}
+{{ item.stock_item.location }}
+Stock Item ID: {{ item.stock_item.pk }}
+
+ |
+ + {% if sub_item.serialized %} + {% trans "Serial" %}: {{ sub_item.serial }} + {% else %} + {% trans "Quantity" %}: {% decimal sub_item.quantity %} + {% endif %} + | +