From be6ecd958770c404d38b4d7d368eaf6c2d3bdd6d Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 9 Jul 2021 00:36:54 +1000 Subject: [PATCH] Fixes for BuildOrder forms --- InvenTree/build/serializers.py | 1 + InvenTree/templates/js/build.js | 35 +++++++++++++---------- InvenTree/templates/js/forms.js | 3 ++ InvenTree/templates/js/model_renderers.js | 21 ++++++++++++++ 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 15c0fad84f..0677320401 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -80,6 +80,7 @@ class BuildSerializer(InvenTreeModelSerializer): 'completed', 'completion_date', 'destination', + 'parent', 'part', 'part_detail', 'overdue', diff --git a/InvenTree/templates/js/build.js b/InvenTree/templates/js/build.js index 55bd7172e1..e284a0e8c8 100644 --- a/InvenTree/templates/js/build.js +++ b/InvenTree/templates/js/build.js @@ -10,6 +10,11 @@ function buildFormFields() { title: {}, part: {}, quantity: {}, + parent: { + filters: { + part_detail: true, + } + }, batch: {}, target_date: {}, take_from: {}, @@ -48,6 +53,14 @@ function newBuildOrder(options={}) { fields.part.value = options.part; } + if (options.quantity) { + fields.quantity.value = options.quantity; + } + + if (options.parent) { + fields.parent.value = options.parent; + } + constructForm(`/api/build/`, { fields: fields, follow: true, @@ -409,14 +422,10 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { var idx = $(this).closest('tr').attr('data-index'); var row = $(table).bootstrapTable('getData')[idx]; - // Launch form to create a new build order - launchModalForm('{% url "build-create" %}', { - follow: true, - data: { - part: pk, - parent: buildId, - quantity: requiredQuantity(row) - sumAllocations(row), - } + newBuildOrder({ + part: pk, + parent: buildId, + quantity: requiredQuantity(row) - sumAllocations(row), }); }); @@ -1117,13 +1126,9 @@ function loadBuildPartsTable(table, options={}) { var idx = $(this).closest('tr').attr('data-index'); var row = $(table).bootstrapTable('getData')[idx]; - // Launch form to create a new build order - launchModalForm('{% url "build-create" %}', { - follow: true, - data: { - part: pk, - parent: options.build, - } + newBuildOrder({ + part: pk, + parent: options.build, }); }); } diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index e282499220..4af3a6f45e 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -1204,6 +1204,9 @@ function renderModelData(name, model, data, parameters, options) { case 'supplierpart': renderer = renderSupplierPart; break; + case 'build': + renderer = renderBuild; + break; case 'owner': renderer = renderOwner; break; diff --git a/InvenTree/templates/js/model_renderers.js b/InvenTree/templates/js/model_renderers.js index 3a5b85adac..91736e0b5a 100644 --- a/InvenTree/templates/js/model_renderers.js +++ b/InvenTree/templates/js/model_renderers.js @@ -70,6 +70,27 @@ function renderStockLocation(name, data, parameters, options) { } +function renderBuild(name, data, parameters, options) { + + var image = ''; + + if (data.part_detail && data.part_detail.thumbnail) { + image = data.part_detail.thumbnail; + } else { + image = `/static/img/blank_image.png`; + } + + var html = ``; + + html += `${data.reference} - ${data.quantity} x ${data.part_detail.full_name}`; + html += `{% trans "Build ID" %}: ${data.pk}`; + + html += `

${data.title}

`; + + return html; +} + + // Renderer for "Part" model function renderPart(name, data, parameters, options) {