Print part labels

This commit is contained in:
Oliver 2021-07-08 22:54:41 +10:00
parent c39f705ef7
commit 15cb1e0005
4 changed files with 61 additions and 2 deletions

View File

@ -394,7 +394,7 @@ class PartLabelMixin:
for key in ['part', 'part[]', 'parts', 'parts[]']: for key in ['part', 'part[]', 'parts', 'parts[]']:
if key in params: if key in params:
parts = parts.getlist(key, []) parts = params.getlist(key, [])
break break
valid_ids = [] valid_ids = []

View File

@ -255,7 +255,7 @@ class LabelConfig(AppConfig):
'file': 'part_label.html', 'file': 'part_label.html',
'name': 'Part Label', 'name': 'Part Label',
'description': 'Simple part label', 'description': 'Simple part label',
'width': 50, 'width': 70,
'height': 24, 'height': 24,
}, },
] ]

View File

@ -268,6 +268,10 @@
); );
}); });
$('#print-label').click(function() {
printPartLabels([{{ part.pk }}]);
});
$("#part-count").click(function() { $("#part-count").click(function() {
launchModalForm("/stock/adjust/", { launchModalForm("/stock/adjust/", {
data: { data: {

View File

@ -105,6 +105,61 @@ function printStockLocationLabels(locations, options={}) {
} }
function printPartLabels(parts, options={}) {
/**
* Print labels for the provided parts
*/
if (parts.length == 0) {
showAlertDialog(
'{% trans "Select Parts" %}',
'{% trans "Part(s) must be selected before printing labels" %}',
);
return;
}
// Request available labels from the server
inventreeGet(
'{% url "api-part-label-list" %}',
{
enabled: true,
parts: parts,
},
{
success: function(response) {
if (response.length == 0) {
showAlertDialog(
'{% trans "No Labels Found" %}',
'{% trans "No labels found which match the selected part(s)" %}',
);
return;
}
// Select label to print
selectLabel(
response,
parts,
{
success: function(pk) {
var url = `/api/label/part/${pk}/print/?`;
parts.forEach(function(part) {
url += `parts[]=${part}&`;
});
window.location.href = url;
}
}
);
}
}
);
}
function selectLabel(labels, items, options={}) { function selectLabel(labels, items, options={}) {
/** /**
* Present the user with the available labels, * Present the user with the available labels,