diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index 8eaadc9a5f..efec7c3aba 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -15,6 +15,12 @@ class EditBuildForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + for field in ['part']: + if field in initial: + self.fields['field'].disabled = True + class Meta: model = Build fields = [ diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 00d82ddd60..6661081aa9 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -13,6 +13,11 @@ class EditPartForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + if 'category' in initial: + self.fields['category'].disabled = True + class Meta: model = Part fields = [ @@ -40,6 +45,11 @@ class EditCategoryForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + if 'category' in initial: + self.fields['parent'].disabled = True + class Meta: model = PartCategory fields = [ @@ -59,6 +69,12 @@ class EditBomItemForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + for field in ['part', 'sub_part']: + if field in initial: + self.fields[field].disabled = True + class Meta: model = BomItem fields = [ @@ -75,6 +91,12 @@ class EditSupplierPartForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + for field in ['supplier', 'part']: + if field in initial: + self.fields[field].disabled = True + class Meta: model = SupplierPart fields = [ diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 33d2ec573f..f59fb2c50c 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -98,11 +98,18 @@ $(document).ready(function () { launchModalForm("#modal-form", "{% url 'part-edit' part.id %}"); }); + {% if part.category %} + var partRedirect = "{% url 'category-detail' part.category.id %}"; + {% else %} + var partRedirect = "{% url 'part-index' %}"; + {% endif %} + $('#delete-part').click(function() { launchDeleteForm("#modal-delete", "{% url 'part-delete' part.id %}", - {redirect: "{% url 'part-index' %}"} - ); + { + redirect: partRedirect + }); }); }); diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index ee28b15c1b..e5b0a8af48 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -239,12 +239,8 @@ class SupplierPartCreate(AjaxCreateView): if supplier_id: initials['supplier'] = get_object_or_404(Company, pk=supplier_id) - # TODO - # self.fields['supplier'].disabled = True if part_id: initials['part'] = get_object_or_404(Part, pk=part_id) - # TODO - # self.fields['part'].disabled = True return initials diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 1b49b8e223..795963af80 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -15,6 +15,11 @@ class EditStockLocationForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + if 'location' in initial: + self.fields['parent'].disabled = True + class Meta: model = StockLocation fields = [ @@ -32,6 +37,12 @@ class EditStockItemForm(forms.ModelForm): self.helper.form_tag = False + initial = kwargs.get('initial', {}) + + for field in ['part', 'location']: + if field in initial: + self.fields[field].disabled = True + class Meta: model = StockItem fields = [