mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor forms for ManufacturerPartParameter
This commit is contained in:
parent
bfc5a7dcf8
commit
870542e4c1
@ -15,7 +15,7 @@ from djmoney.forms.fields import MoneyField
|
|||||||
|
|
||||||
from common.settings import currency_code_default
|
from common.settings import currency_code_default
|
||||||
|
|
||||||
from .models import Company, ManufacturerPartParameter
|
from .models import Company
|
||||||
from .models import ManufacturerPart
|
from .models import ManufacturerPart
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
from .models import SupplierPriceBreak
|
from .models import SupplierPriceBreak
|
||||||
@ -58,21 +58,6 @@ class EditManufacturerPartForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EditManufacturerPartParameterForm(HelperForm):
|
|
||||||
"""
|
|
||||||
Form for creating / editing a ManufacturerPartParameter object
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = ManufacturerPartParameter
|
|
||||||
fields = [
|
|
||||||
'manufacturer_part',
|
|
||||||
'name',
|
|
||||||
'value',
|
|
||||||
'units',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class EditSupplierPartForm(HelperForm):
|
class EditSupplierPartForm(HelperForm):
|
||||||
""" Form for editing a SupplierPart object """
|
""" Form for editing a SupplierPart object """
|
||||||
|
|
||||||
|
@ -57,15 +57,26 @@
|
|||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
|
function reloadParameters() {
|
||||||
|
$("#parameter-table").bootstrapTable("refresh");
|
||||||
|
}
|
||||||
|
|
||||||
$('#parameter-create').click(function() {
|
$('#parameter-create').click(function() {
|
||||||
launchModalForm(
|
|
||||||
"{% url 'manufacturer-part-parameter-create' %}",
|
constructForm('{% url "api-manufacturer-part-parameter-list" %}', {
|
||||||
{
|
method: 'POST',
|
||||||
data: {
|
fields: {
|
||||||
manufacturer_part: {{ part.id }},
|
name: {},
|
||||||
|
value: {},
|
||||||
|
units: {},
|
||||||
|
manufacturer_part: {
|
||||||
|
value: {{ part.pk }},
|
||||||
|
hidden: true,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
title: '{% trans "Add Parameter" %}',
|
||||||
|
onSuccess: reloadParameters
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#supplier-create').click(function () {
|
$('#supplier-create').click(function () {
|
||||||
|
@ -23,13 +23,12 @@ from InvenTree.views import AjaxCreateView, AjaxUpdateView, AjaxDeleteView
|
|||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool
|
||||||
from InvenTree.views import InvenTreeRoleMixin
|
from InvenTree.views import InvenTreeRoleMixin
|
||||||
|
|
||||||
from .models import Company, ManufacturerPartParameter
|
from .models import Company
|
||||||
from .models import ManufacturerPart
|
from .models import ManufacturerPart
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
|
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
|
||||||
from .forms import EditManufacturerPartParameterForm
|
|
||||||
from .forms import EditManufacturerPartForm
|
from .forms import EditManufacturerPartForm
|
||||||
from .forms import EditSupplierPartForm
|
from .forms import EditSupplierPartForm
|
||||||
from .forms import CompanyImageDownloadForm
|
from .forms import CompanyImageDownloadForm
|
||||||
@ -414,66 +413,6 @@ class ManufacturerPartDelete(AjaxDeleteView):
|
|||||||
part.delete()
|
part.delete()
|
||||||
|
|
||||||
return self.renderJsonResponse(self.request, data=data, form=self.get_form())
|
return self.renderJsonResponse(self.request, data=data, form=self.get_form())
|
||||||
|
|
||||||
|
|
||||||
class ManufacturerPartParameterCreate(AjaxCreateView):
|
|
||||||
"""
|
|
||||||
View for creating a new ManufacturerPartParameter object
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = ManufacturerPartParameter
|
|
||||||
form_class = EditManufacturerPartParameterForm
|
|
||||||
ajax_form_title = _('Add Manufacturer Part Parameter')
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
|
|
||||||
form = super().get_form()
|
|
||||||
|
|
||||||
# Hide the manufacturer_part field if specified
|
|
||||||
if form.initial.get('manufacturer_part', None):
|
|
||||||
form.fields['manufacturer_part'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
|
|
||||||
initials = super().get_initial().copy()
|
|
||||||
|
|
||||||
manufacturer_part = self.get_param('manufacturer_part')
|
|
||||||
|
|
||||||
if manufacturer_part:
|
|
||||||
try:
|
|
||||||
initials['manufacturer_part'] = ManufacturerPartParameter.objects.get(pk=manufacturer_part)
|
|
||||||
except (ValueError, ManufacturerPartParameter.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
return initials
|
|
||||||
|
|
||||||
|
|
||||||
class ManufacturerPartParameterEdit(AjaxUpdateView):
|
|
||||||
"""
|
|
||||||
View for editing a ManufacturerPartParameter object
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = ManufacturerPartParameter
|
|
||||||
form_class = EditManufacturerPartParameterForm
|
|
||||||
ajax_form_title = _('Edit Manufacturer Part Parameter')
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
|
|
||||||
form = super().get_form()
|
|
||||||
|
|
||||||
form.fields['manufacturer_part'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
|
|
||||||
class ManufacturerPartParameterDelete(AjaxDeleteView):
|
|
||||||
"""
|
|
||||||
View for deleting a ManufacturerPartParameter object
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = ManufacturerPartParameter
|
|
||||||
|
|
||||||
|
|
||||||
class SupplierPartDetail(DetailView):
|
class SupplierPartDetail(DetailView):
|
||||||
|
@ -342,27 +342,28 @@ function loadManufacturerPartParameterTable(table, url, options) {
|
|||||||
$(table).find('.button-parameter-edit').click(function() {
|
$(table).find('.button-parameter-edit').click(function() {
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
launchModalForm(
|
constructForm(`/api/company/part/manufacturer/parameter/${pk}/`, {
|
||||||
`/manufacturer-part/parameter/${pk}/edit/`,
|
fields: {
|
||||||
{
|
name: {},
|
||||||
success: function() {
|
value: {},
|
||||||
$(table).bootstrapTable('refresh');
|
units: {},
|
||||||
}
|
},
|
||||||
|
title: '{% trans "Edit Parameter" %}',
|
||||||
|
onSuccess: function() {
|
||||||
|
$(table).bootstrapTable('refresh');
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
$(table).find('.button-parameter-delete').click(function() {
|
$(table).find('.button-parameter-delete').click(function() {
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
launchModalForm(
|
constructForm(`/api/company/part/manufacturer/parameter/${pk}/`, {
|
||||||
`/manufacturer-part/parameter/${pk}/delete/`,
|
method: 'DELETE',
|
||||||
{
|
title: '{% trans "Delete Parameter" %}',
|
||||||
success: function() {
|
onSuccess: function() {
|
||||||
$(table).bootstrapTable('refresh');
|
$(table).bootstrapTable('refresh');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user