Fixes for BuildOrder forms

This commit is contained in:
Oliver 2021-07-09 00:36:54 +10:00
parent 13ca076f42
commit be6ecd9587
4 changed files with 45 additions and 15 deletions

View File

@ -80,6 +80,7 @@ class BuildSerializer(InvenTreeModelSerializer):
'completed',
'completion_date',
'destination',
'parent',
'part',
'part_detail',
'overdue',

View File

@ -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,
});
});
}

View File

@ -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;

View File

@ -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 = `<img src='${image}' class='select2-thumbnail'>`;
html += `<span><b>${data.reference}</b></span> - ${data.quantity} x ${data.part_detail.full_name}`;
html += `<span class='float-right'>{% trans "Build ID" %}: ${data.pk}</span>`;
html += `<p><i>${data.title}</i></p>`;
return html;
}
// Renderer for "Part" model
function renderPart(name, data, parameters, options) {