mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor BuildOrderEdit form
This commit is contained in:
parent
0599fbaf26
commit
245c04367b
@ -166,7 +166,12 @@ class InvenTreeMetadata(SimpleMetadata):
|
||||
if model:
|
||||
# Mark this field as "related", and point to the URL where we can get the data!
|
||||
field_info['type'] = 'related field'
|
||||
field_info['api_url'] = model.get_api_url()
|
||||
field_info['model'] = model._meta.model_name
|
||||
|
||||
# Special case for 'user' model
|
||||
if field_info['model'] == 'user':
|
||||
field_info['api_url'] = '/api/user/'
|
||||
else:
|
||||
field_info['api_url'] = model.get_api_url()
|
||||
|
||||
return field_info
|
||||
|
@ -75,9 +75,11 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
'pk',
|
||||
'url',
|
||||
'title',
|
||||
'batch',
|
||||
'creation_date',
|
||||
'completed',
|
||||
'completion_date',
|
||||
'destination',
|
||||
'part',
|
||||
'part_detail',
|
||||
'overdue',
|
||||
@ -87,6 +89,7 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
'status',
|
||||
'status_text',
|
||||
'target_date',
|
||||
'take_from',
|
||||
'notes',
|
||||
'link',
|
||||
'issued_by',
|
||||
|
@ -196,9 +196,25 @@ src="{% static 'img/blank_image.png' %}"
|
||||
});
|
||||
|
||||
$("#build-edit").click(function () {
|
||||
launchModalForm("{% url 'build-edit' build.id %}",
|
||||
{
|
||||
reload: true
|
||||
|
||||
constructForm('{% url "api-build-detail" build.pk %}', {
|
||||
fields: {
|
||||
reference: {
|
||||
prefix: "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}",
|
||||
},
|
||||
title: {},
|
||||
part: {},
|
||||
quantity: {},
|
||||
batch: {},
|
||||
target_date: {},
|
||||
take_from: {},
|
||||
destination: {},
|
||||
link: {},
|
||||
issued_by: {},
|
||||
responsible: {},
|
||||
},
|
||||
title: '{% trans "Edit Build Order" %}',
|
||||
reload: true,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -7,7 +7,6 @@ from django.conf.urls import url, include
|
||||
from . import views
|
||||
|
||||
build_detail_urls = [
|
||||
url(r'^edit/', views.BuildUpdate.as_view(), name='build-edit'),
|
||||
url(r'^allocate/', views.BuildAllocate.as_view(), name='build-allocate'),
|
||||
url(r'^cancel/', views.BuildCancel.as_view(), name='build-cancel'),
|
||||
url(r'^delete/', views.BuildDelete.as_view(), name='build-delete'),
|
||||
|
@ -744,49 +744,6 @@ class BuildCreate(AjaxCreateView):
|
||||
pass
|
||||
|
||||
|
||||
class BuildUpdate(AjaxUpdateView):
|
||||
""" View for editing a Build object """
|
||||
|
||||
model = Build
|
||||
form_class = forms.EditBuildForm
|
||||
context_object_name = 'build'
|
||||
ajax_form_title = _('Edit Build Order Details')
|
||||
ajax_template_name = 'modal_form.html'
|
||||
|
||||
def get_form(self):
|
||||
|
||||
form = super().get_form()
|
||||
|
||||
build = self.get_object()
|
||||
|
||||
# Fields which are included in the form, but hidden
|
||||
hidden = [
|
||||
'parent',
|
||||
'sales_order',
|
||||
]
|
||||
|
||||
if build.is_complete:
|
||||
# Fields which cannot be edited once the build has been completed
|
||||
|
||||
hidden += [
|
||||
'part',
|
||||
'quantity',
|
||||
'batch',
|
||||
'take_from',
|
||||
'destination',
|
||||
]
|
||||
|
||||
for field in hidden:
|
||||
form.fields[field].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'info': _('Edited build'),
|
||||
}
|
||||
|
||||
|
||||
class BuildDelete(AjaxDeleteView):
|
||||
""" View to delete a build """
|
||||
|
||||
|
@ -1206,6 +1206,10 @@ function renderModelData(name, model, data, parameters, options) {
|
||||
break;
|
||||
case 'owner':
|
||||
renderer = renderOwner;
|
||||
break;
|
||||
case 'user':
|
||||
renderer = renderUser;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -92,6 +92,18 @@ function renderPart(name, data, parameters, options) {
|
||||
return html;
|
||||
}
|
||||
|
||||
// Renderer for "User" model
|
||||
function renderUser(name, data, parameters, options) {
|
||||
|
||||
var html = `<span>${data.username}</span>`;
|
||||
|
||||
if (data.first_name && data.last_name) {
|
||||
html += ` - <i>${data.first_name} ${data.last_name}</i>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
// Renderer for "Owner" model
|
||||
function renderOwner(name, data, parameters, options) {
|
||||
|
Loading…
Reference in New Issue
Block a user