From 17b0399d26bece98d48ecb021bd02ac879df5110 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 21 Dec 2022 22:09:21 +1100 Subject: [PATCH] Serial number autofill (#4091) * Add global setting to control seiral number auto-fill * Auto fill serial number field --- InvenTree/common/models.py | 7 +++++++ InvenTree/templates/InvenTree/settings/stock.html | 1 + InvenTree/templates/js/translated/stock.js | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 36ac62bf40..60b9df5ebf 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1215,6 +1215,13 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'validator': bool, }, + 'SERIAL_NUMBER_AUTOFILL': { + 'name': _('Autofill Serial Numbers'), + 'description': _('Autofill serial numbers in forms'), + 'default': False, + 'validator': bool, + }, + 'STOCK_BATCH_CODE_TEMPLATE': { 'name': _('Batch Code Template'), 'description': _('Template for generating default batch codes for stock items'), diff --git a/InvenTree/templates/InvenTree/settings/stock.html b/InvenTree/templates/InvenTree/settings/stock.html index 2f6c92c7d4..f45bf16e3c 100644 --- a/InvenTree/templates/InvenTree/settings/stock.html +++ b/InvenTree/templates/InvenTree/settings/stock.html @@ -12,6 +12,7 @@ {% include "InvenTree/settings/setting.html" with key="SERIAL_NUMBER_GLOBALLY_UNIQUE" icon="fa-hashtag" %} + {% include "InvenTree/settings/setting.html" with key="SERIAL_NUMBER_AUTOFILL" icon="fa-magic" %} {% include "InvenTree/settings/setting.html" with key="STOCK_BATCH_CODE_TEMPLATE" icon="fa-layer-group" %} {% include "InvenTree/settings/setting.html" with key="STOCK_ENABLE_EXPIRY" icon="fa-stopwatch" %} {% include "InvenTree/settings/setting.html" with key="STOCK_STALE_DAYS" icon="fa-calendar" %} diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 76d6f3ec5f..fa1c6e7944 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -240,6 +240,12 @@ function stockItemFields(options={}) { } setFormInputPlaceholder('serial_numbers', placeholder, opts); + + if (global_settings.SERIAL_NUMBER_AUTOFILL) { + if (data.next) { + updateFieldValue('serial_numbers', `${data.next}+`, {}, opts); + } + } } });