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:
|
if model:
|
||||||
# Mark this field as "related", and point to the URL where we can get the data!
|
# Mark this field as "related", and point to the URL where we can get the data!
|
||||||
field_info['type'] = 'related field'
|
field_info['type'] = 'related field'
|
||||||
field_info['api_url'] = model.get_api_url()
|
|
||||||
field_info['model'] = model._meta.model_name
|
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
|
return field_info
|
||||||
|
@ -75,9 +75,11 @@ class BuildSerializer(InvenTreeModelSerializer):
|
|||||||
'pk',
|
'pk',
|
||||||
'url',
|
'url',
|
||||||
'title',
|
'title',
|
||||||
|
'batch',
|
||||||
'creation_date',
|
'creation_date',
|
||||||
'completed',
|
'completed',
|
||||||
'completion_date',
|
'completion_date',
|
||||||
|
'destination',
|
||||||
'part',
|
'part',
|
||||||
'part_detail',
|
'part_detail',
|
||||||
'overdue',
|
'overdue',
|
||||||
@ -87,6 +89,7 @@ class BuildSerializer(InvenTreeModelSerializer):
|
|||||||
'status',
|
'status',
|
||||||
'status_text',
|
'status_text',
|
||||||
'target_date',
|
'target_date',
|
||||||
|
'take_from',
|
||||||
'notes',
|
'notes',
|
||||||
'link',
|
'link',
|
||||||
'issued_by',
|
'issued_by',
|
||||||
|
@ -196,9 +196,25 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#build-edit").click(function () {
|
$("#build-edit").click(function () {
|
||||||
launchModalForm("{% url 'build-edit' build.id %}",
|
|
||||||
{
|
constructForm('{% url "api-build-detail" build.pk %}', {
|
||||||
reload: true
|
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
|
from . import views
|
||||||
|
|
||||||
build_detail_urls = [
|
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'^allocate/', views.BuildAllocate.as_view(), name='build-allocate'),
|
||||||
url(r'^cancel/', views.BuildCancel.as_view(), name='build-cancel'),
|
url(r'^cancel/', views.BuildCancel.as_view(), name='build-cancel'),
|
||||||
url(r'^delete/', views.BuildDelete.as_view(), name='build-delete'),
|
url(r'^delete/', views.BuildDelete.as_view(), name='build-delete'),
|
||||||
|
@ -744,49 +744,6 @@ class BuildCreate(AjaxCreateView):
|
|||||||
pass
|
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):
|
class BuildDelete(AjaxDeleteView):
|
||||||
""" View to delete a build """
|
""" View to delete a build """
|
||||||
|
|
||||||
|
@ -1206,6 +1206,10 @@ function renderModelData(name, model, data, parameters, options) {
|
|||||||
break;
|
break;
|
||||||
case 'owner':
|
case 'owner':
|
||||||
renderer = renderOwner;
|
renderer = renderOwner;
|
||||||
|
break;
|
||||||
|
case 'user':
|
||||||
|
renderer = renderUser;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,18 @@ function renderPart(name, data, parameters, options) {
|
|||||||
return html;
|
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
|
// Renderer for "Owner" model
|
||||||
function renderOwner(name, data, parameters, options) {
|
function renderOwner(name, data, parameters, options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user