From b152f7041bbc2615f59cd2d57090657134473b47 Mon Sep 17 00:00:00 2001 From: eeintech Date: Fri, 12 Mar 2021 10:30:31 -0500 Subject: [PATCH] Add setting to disable IPN editing after part is created (web only) --- InvenTree/common/models.py | 7 +++++++ InvenTree/part/views.py | 6 ++++++ InvenTree/templates/InvenTree/settings/part.html | 1 + 3 files changed, 14 insertions(+) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 06c06bde05..381888c588 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -97,6 +97,13 @@ class InvenTreeSetting(models.Model): 'validator': bool, }, + 'PART_ALLOW_EDIT_IPN': { + 'name': _('Allow Editing IPN'), + 'description': _('Allow changing the IPN value while editing a part'), + 'default': True, + 'validator': bool, + }, + 'PART_COPY_BOM': { 'name': _('Copy Part BOM Data'), 'description': _('Copy BOM data by default when duplicating a part'), diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 65f859566b..37704c5f46 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -910,6 +910,12 @@ class PartEdit(AjaxUpdateView): form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part) + # Check if IPN can be edited + ipn_edit_enable = InvenTreeSetting.get_setting('PART_ALLOW_EDIT_IPN') + if not ipn_edit_enable and not self.request.user.is_superuser: + # Admin can still change IPN + form.fields['IPN'].disabled = True + return form diff --git a/InvenTree/templates/InvenTree/settings/part.html b/InvenTree/templates/InvenTree/settings/part.html index bef951e203..092d9c576c 100644 --- a/InvenTree/templates/InvenTree/settings/part.html +++ b/InvenTree/templates/InvenTree/settings/part.html @@ -18,6 +18,7 @@ {% include "InvenTree/settings/setting.html" with key="PART_IPN_REGEX" %} {% include "InvenTree/settings/setting.html" with key="PART_ALLOW_DUPLICATE_IPN" %} + {% include "InvenTree/settings/setting.html" with key="PART_ALLOW_EDIT_IPN" %} {% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" %} {% include "InvenTree/settings/setting.html" with key="PART_RECENT_COUNT" icon="fa-clock" %}