From 2b8590eb5dc55ccbffaf60850e5fa4984076e353 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 4 Mar 2023 10:01:16 +1100 Subject: [PATCH] Report maths (#448) * Rename file * Expand conditional example * Add documentation for using media variables --- docs/report/{media.md => helpers.md} | 44 +++++++++++++++++++++++----- docs/report/labels.md | 2 +- docs/report/report.md | 4 +++ mkdocs.yml | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) rename docs/report/{media.md => helpers.md} (77%) diff --git a/docs/report/media.md b/docs/report/helpers.md similarity index 77% rename from docs/report/media.md rename to docs/report/helpers.md index 5da7551..26b3565 100644 --- a/docs/report/media.md +++ b/docs/report/helpers.md @@ -1,14 +1,8 @@ --- -title: Using media files +title: Helper Functions --- -## Media Files - -*Media files* are any files uploaded to the InvenTree server by the user. These are stored under the `/media/` directory and can be accessed for use in custom reports or labels. - -**Load Report Functions** - -To load images into the reports/labels the report helper functions must first be loaded in the template: +Some common functions are provided for use in custom report and label templates. To include these, load the `report` functions at the start of the template: ```html {% raw %} @@ -17,6 +11,40 @@ To load images into the reports/labels the report helper functions must first be {% endraw %} ``` +## Maths Operations + +Simple mathematical operators are available, as demonstrated in the example template below: + +```html +{% raw %} + +{% load report %} + +{% add 1 3 %} +{% subtract 4 3 %} +{% multiply 1.2 3.4 %} +{% divide 10 2 %} + +{% endraw %} +``` + +These operators can also be used with variables: + +```html +{% raw %} +{% load report %} + +{% for line in order.lines %} +Total: {% multiply line.purchase_price line.quantity %}
+{% endfor %} + +{% endraw %} +``` + +## Media Files + +*Media files* are any files uploaded to the InvenTree server by the user. These are stored under the `/media/` directory and can be accessed for use in custom reports or labels. + ### Uploaded Images You can access an uploaded image file if you know the *path* of the image, relative to the top-level `/media/` directory. To load the image into a report, use the `{% raw %}{% uploaded_image ... %}{% endraw %}` tag: diff --git a/docs/report/labels.md b/docs/report/labels.md index e445d9b..9940d9a 100644 --- a/docs/report/labels.md +++ b/docs/report/labels.md @@ -106,7 +106,7 @@ Refer to the [barcode documentation](./barcodes.md). ### Using media files -Refer to the [media files documentation](./media.md). +Refer to the [media files documentation](./helpers.md#media-files). ### Conditional Formatting diff --git a/docs/report/report.md b/docs/report/report.md index 31208d3..23c86a1 100644 --- a/docs/report/report.md +++ b/docs/report/report.md @@ -60,6 +60,10 @@ The django template system allows for conditional rendering, providing condition {% raw %} {% if %} {% do_something %} +{% elif %} + +{% else %} + {% endif %} {% endraw %} ``` diff --git a/mkdocs.yml b/mkdocs.yml index ddf7459..03594c2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -118,7 +118,7 @@ nav: - Sales Order: report/sales_order.md - BOM: report/bom.md - Labels: report/labels.md - - Media Files: report/media.md + - Helper Functions: report/helpers.md - Barcodes: report/barcodes.md - Context Variables: report/context_variables.md - Admin: