diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index 537f7b07c3..2364f36b61 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -33,16 +33,29 @@ "{% url 'supplier-part-create' %}", { data: { - supplier: {{ company.id }} + {% if company.is_supplier %}supplier: {{ company.id }},{% endif %} + {% if company.is_manufacturer %}manufacturer: {{ company.id }},{% endif %} }, reload: true, secondary: [ { field: 'part', - label: 'New Part', - title: 'Create New Part', + label: '{% trans "New Part" %}', + title: '{% trans "Create new Part" %}', url: "{% url 'part-create' %}" }, + { + field: 'supplier', + label: "{% trans 'New Supplier' %}", + title: "{% trans 'Create new Supplier' %}", + url: "{% url 'supplier-create' %}", + }, + { + field: 'manufacturer', + label: '{% trans "New Manufacturer" %}', + title: '{% trans "Create new Manufacturer" %}', + url: "{% url 'manufacturer-create' %}", + }, ] }); }); diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index d1fc9b643f..ae88629505 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -273,10 +273,6 @@ class SupplierPartCreate(AjaxCreateView): Hide some fields if they are not appropriate in context """ form = super(AjaxCreateView, self).get_form() - - if form.initial.get('supplier', None): - # Hide the supplier field - form.fields['supplier'].widget = HiddenInput() if form.initial.get('part', None): # Hide the part field @@ -292,20 +288,27 @@ class SupplierPartCreate(AjaxCreateView): """ initials = super(SupplierPartCreate, self).get_initial().copy() + manufacturer_id = self.get_param('manufacturer') supplier_id = self.get_param('supplier') part_id = self.get_param('part') if supplier_id: try: initials['supplier'] = Company.objects.get(pk=supplier_id) - except Company.DoesNotExist: - initials['supplier'] = None + except (ValueError, Company.DoesNotExist): + pass + + if manufacturer_id: + try: + initials['manufacturer'] = Company.objects.get(pk=manufacturer_id) + except (ValueError, Company.DoesNotExist): + pass if part_id: try: initials['part'] = Part.objects.get(pk=part_id) - except Part.DoesNotExist: - initials['part'] = None + except (ValueError, Part.DoesNotExist): + pass return initials