From 245c04367b79eaad574db9f0583c618af0e3a24d Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 8 Jul 2021 23:57:42 +1000 Subject: [PATCH] Refactor BuildOrderEdit form --- InvenTree/InvenTree/metadata.py | 7 ++- InvenTree/build/serializers.py | 3 ++ .../build/templates/build/build_base.html | 24 +++++++++-- InvenTree/build/urls.py | 1 - InvenTree/build/views.py | 43 ------------------- InvenTree/templates/js/forms.js | 4 ++ InvenTree/templates/js/model_renderers.js | 12 ++++++ 7 files changed, 45 insertions(+), 49 deletions(-) diff --git a/InvenTree/InvenTree/metadata.py b/InvenTree/InvenTree/metadata.py index f1b1c0c040..92948653b0 100644 --- a/InvenTree/InvenTree/metadata.py +++ b/InvenTree/InvenTree/metadata.py @@ -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 diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 363614035a..15c0fad84f 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -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', diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index 2376daf0cf..4fe24d7caf 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -196,10 +196,26 @@ 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, + }); }); $("#build-cancel").click(function() { diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index 549a20ee7e..588e44fb35 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -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'), diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 16004dacc1..e94cc869db 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -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 """ diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index ac3bcefd04..e282499220 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -1206,6 +1206,10 @@ function renderModelData(name, model, data, parameters, options) { break; case 'owner': renderer = renderOwner; + break; + case 'user': + renderer = renderUser; + break; default: break; } diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index 5b838f184b..3a5b85adac 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -92,6 +92,18 @@ function renderPart(name, data, parameters, options) { return html; } +// Renderer for "User" model +function renderUser(name, data, parameters, options) { + + var html = `${data.username}`; + + if (data.first_name && data.last_name) { + html += ` - ${data.first_name} ${data.last_name}`; + } + + return html; +} + // Renderer for "Owner" model function renderOwner(name, data, parameters, options) {