From 624c5094c5851bfbef63569ab5ce393f25238010 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 10:57:32 +1000 Subject: [PATCH] Prevent editing of SupplierPart fields if initial values are provided --- InvenTree/part/views.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 7667b3908a..b8762f556d 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -406,6 +406,23 @@ class SupplierPartCreate(AjaxCreateView): ajax_form_title = 'Create new Supplier Part' context_object_name = 'part' + def get_form(self): + form = super(AjaxCreateView, self).get_form() + + # Was the form supplied with initial data? + + print("Initial:", form.initial) + print(dir(form)) + + if form.initial.get('supplier', None): + # Hide the supplier field + form.fields['supplier'].widget.attrs['disabled'] = True + + if form.initial.get('part', None): + # Hide the part field + form.fields['part'].widget.attrs['disabled'] = True + + return form def get_initial(self): """ Provide initial data for new SupplierPart: