From 4768c9cbb3a4298a9d8e34ca26526b19a8b7cc8f Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 19 Nov 2020 15:31:39 -0500 Subject: [PATCH 1/3] Fixed validation of SupplierPart edit form by forcing the value of single_pricing field --- InvenTree/company/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index 2f734a7cc5..a98df503b2 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -274,6 +274,12 @@ class SupplierPartEdit(AjaxUpdateView): def get_form(self): form = super().get_form() + supplier_part = self.get_object() + + # It appears that hiding a MoneyField fails validation + # Therefore the idea to set the value before hiding + if form.is_valid(): + form.cleaned_data['single_pricing'] = supplier_part.unit_pricing # Hide the single-pricing field (only for creating a new SupplierPart!) form.fields['single_pricing'].widget = HiddenInput() From 11745ebd6c315ca4295ede55cefa76b08c2fdd3c Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 19 Nov 2020 15:32:42 -0500 Subject: [PATCH 2/3] Removed one too many indent --- InvenTree/company/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index a98df503b2..2720f4ccac 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -279,7 +279,7 @@ class SupplierPartEdit(AjaxUpdateView): # It appears that hiding a MoneyField fails validation # Therefore the idea to set the value before hiding if form.is_valid(): - form.cleaned_data['single_pricing'] = supplier_part.unit_pricing + form.cleaned_data['single_pricing'] = supplier_part.unit_pricing # Hide the single-pricing field (only for creating a new SupplierPart!) form.fields['single_pricing'].widget = HiddenInput() From 20e8161038d693425d15c06baedca9f756b7c1c1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 20 Nov 2020 08:29:06 +1100 Subject: [PATCH 3/3] Reduce duplicate function calls in custom context parser --- InvenTree/InvenTree/context.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/InvenTree/InvenTree/context.py b/InvenTree/InvenTree/context.py index 8753749e3f..9fee5deaab 100644 --- a/InvenTree/InvenTree/context.py +++ b/InvenTree/InvenTree/context.py @@ -13,6 +13,22 @@ from users.models import RuleSet def health_status(request): + """ + Provide system health status information to the global context. + + - Not required for AJAX requests + - Do not provide if it is already provided to the context + """ + + if request.path.endswith('.js'): + # Do not provide to script requests + return {} + + if hasattr(request, '_inventree_health_status'): + # Do not duplicate efforts + return {} + + request._inventree_health_status = True return { "system_healthy": InvenTree.status.check_system_health(), @@ -20,6 +36,15 @@ def health_status(request): def status_codes(request): + """ + Provide status code enumerations. + """ + + if hasattr(request, '_inventree_status_codes'): + # Do not duplicate efforts + return {} + + request._inventree_status_codes = True return { # Expose the StatusCode classes to the templates