From fdd70263ea84de102c8dabe2d85af9a8236ec54c Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 7 Feb 2024 11:36:20 +1100 Subject: [PATCH] Week number (#6439) * Support week number for batch generation * Bug fix - hour is not minute * Update docs --- InvenTree/stock/models.py | 3 ++- docs/docs/stock/tracking.md | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 099670dfb0..05f6482bea 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -324,8 +324,9 @@ def generate_batch_code(): 'year': now.year, 'month': now.month, 'day': now.day, - 'hour': now.minute, + 'hour': now.hour, 'minute': now.minute, + 'week': now.isocalendar()[1], } return Template(batch_template).render(context) diff --git a/docs/docs/stock/tracking.md b/docs/docs/stock/tracking.md index 4420711ad8..55da6b2b25 100644 --- a/docs/docs/stock/tracking.md +++ b/docs/docs/stock/tracking.md @@ -30,6 +30,19 @@ Batch codes can be generated automatically based on a provided pattern. The defa {% include 'img.html' %} {% endwith %} +#### Context Variables + +The following context variables are available by default when generating a batch code using the builtin generation functionality: + +| Variable | Description | +| --- | --- | +| year | The current year e.g. `2024` | +| month | The current month number, e.g. `5` | +| day | The current day of month, e.g. `21` | +| hour | The current hour of day, in 24-hour format, e.g. `23` | +| minute | The current minute of hour, e.g. `17` | +| week | The current week of year, e.g. `51` | + #### Plugin Support To implement custom batch code functionality, refer to the details on the [Validation Plugin Mixin](../extend/plugins/validation.md#batch-codes).