mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improvements for "SupplierPartCreate" form
This commit is contained in:
parent
0e55911a6b
commit
47530b7d2a
@ -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' %}",
|
||||
},
|
||||
]
|
||||
});
|
||||
});
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user