mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Report merge (#9532)
* Report merge
* Remove auto-generated file
* Remove pre-commit file
* Revert "Remove pre-commit file"
This reverts commit 00d80bae2a.
* 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 <code@mjmair.com>
			
			
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							45daef8442
						
					
				
				
					commit
					786b52d016
				
			| @@ -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/). | ||||
|   | ||||
| @@ -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 %} | ||||
| <h2>Merged Report for Selected Parts</h2> | ||||
| <table> | ||||
|   <tr> | ||||
|     <th>Name</th> | ||||
|     <th>Description</th> | ||||
|   </tr> | ||||
|   {% for part in instances %} | ||||
|     <tr> | ||||
|       <td>{{ part.name }}</td> | ||||
|       <td>{{ part.description }}</td> | ||||
|     </tr> | ||||
|   {% endfor %} | ||||
| </table> | ||||
| {% endraw %} | ||||
| ``` | ||||
|  | ||||
| Note that custom plugins may also add additional context variables to the report context. | ||||
|  | ||||
| ::: report.models.ReportTemplate.get_context | ||||
|   | ||||
| @@ -44,3 +44,5 @@ For example, rendering the name of a part (which is available in the particular | ||||
| </p></i> | ||||
| {% endraw %} | ||||
| ``` | ||||
| #### Rendering a single report vs. multiple report from selection | ||||
| Users can select multiple items such as `part`, `stockItem`,...etc to render from a report template. By default, the `merge` attribute of report template is disabled, which means an independent report will be generated for each item in the list of selected items. If `merge` is enabled, all selected items will be available in the `instances` context variable of the report template. Users are free to access them by indexing or in a loop. For more details, visit [context variable](./context_variables.md) | ||||
|   | ||||
| @@ -22,6 +22,8 @@ The following report templates are provided "out of the box" and can be used as | ||||
| | [Sales Order Shipment](#sales-order-shipment) | [SalesOrderShipment](../sales/sales_order.md) | Sales Order Shipment report | | ||||
| | [Stock Location](#stock-location) | [StockLocation](../stock/index.md#stock-location) | Stock Location report | | ||||
| | [Test Report](#test-report) | [StockItem](../stock/index.md#stock-item) | Test Report | | ||||
| | [Selected Stock Items Report](#selected-stock-items-report) | [StockItem](../stock/index.md#stock-item) | Selected Stock Items report | | ||||
|  | ||||
|  | ||||
| ### Bill of Materials Report | ||||
|  | ||||
| @@ -55,6 +57,10 @@ The following report templates are provided "out of the box" and can be used as | ||||
|  | ||||
| {{ templatefile("report/inventree_test_report.html") }} | ||||
|  | ||||
| ### Selected Stock Items Report | ||||
|  | ||||
| {{ templatefile("report/inventree_stock_report_merge.html") }} | ||||
|  | ||||
| ## Label Templates | ||||
|  | ||||
| The following label templates are provided "out of the box" and can be used as a starting point, or as a reference for creating custom label templates: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user