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' %}",
|
"{% url 'supplier-part-create' %}",
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
supplier: {{ company.id }}
|
{% if company.is_supplier %}supplier: {{ company.id }},{% endif %}
|
||||||
|
{% if company.is_manufacturer %}manufacturer: {{ company.id }},{% endif %}
|
||||||
},
|
},
|
||||||
reload: true,
|
reload: true,
|
||||||
secondary: [
|
secondary: [
|
||||||
{
|
{
|
||||||
field: 'part',
|
field: 'part',
|
||||||
label: 'New Part',
|
label: '{% trans "New Part" %}',
|
||||||
title: 'Create New Part',
|
title: '{% trans "Create new Part" %}',
|
||||||
url: "{% url 'part-create' %}"
|
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
|
Hide some fields if they are not appropriate in context
|
||||||
"""
|
"""
|
||||||
form = super(AjaxCreateView, self).get_form()
|
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):
|
if form.initial.get('part', None):
|
||||||
# Hide the part field
|
# Hide the part field
|
||||||
@ -292,20 +288,27 @@ class SupplierPartCreate(AjaxCreateView):
|
|||||||
"""
|
"""
|
||||||
initials = super(SupplierPartCreate, self).get_initial().copy()
|
initials = super(SupplierPartCreate, self).get_initial().copy()
|
||||||
|
|
||||||
|
manufacturer_id = self.get_param('manufacturer')
|
||||||
supplier_id = self.get_param('supplier')
|
supplier_id = self.get_param('supplier')
|
||||||
part_id = self.get_param('part')
|
part_id = self.get_param('part')
|
||||||
|
|
||||||
if supplier_id:
|
if supplier_id:
|
||||||
try:
|
try:
|
||||||
initials['supplier'] = Company.objects.get(pk=supplier_id)
|
initials['supplier'] = Company.objects.get(pk=supplier_id)
|
||||||
except Company.DoesNotExist:
|
except (ValueError, Company.DoesNotExist):
|
||||||
initials['supplier'] = None
|
pass
|
||||||
|
|
||||||
|
if manufacturer_id:
|
||||||
|
try:
|
||||||
|
initials['manufacturer'] = Company.objects.get(pk=manufacturer_id)
|
||||||
|
except (ValueError, Company.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
if part_id:
|
if part_id:
|
||||||
try:
|
try:
|
||||||
initials['part'] = Part.objects.get(pk=part_id)
|
initials['part'] = Part.objects.get(pk=part_id)
|
||||||
except Part.DoesNotExist:
|
except (ValueError, Part.DoesNotExist):
|
||||||
initials['part'] = None
|
pass
|
||||||
|
|
||||||
return initials
|
return initials
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user