diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index 13f737057d..b2d17efdfe 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -394,7 +394,7 @@ class PartLabelMixin: for key in ['part', 'part[]', 'parts', 'parts[]']: if key in params: - parts = parts.getlist(key, []) + parts = params.getlist(key, []) break valid_ids = [] diff --git a/InvenTree/label/apps.py b/InvenTree/label/apps.py index 0293c3d18c..2556e11bca 100644 --- a/InvenTree/label/apps.py +++ b/InvenTree/label/apps.py @@ -255,7 +255,7 @@ class LabelConfig(AppConfig): 'file': 'part_label.html', 'name': 'Part Label', 'description': 'Simple part label', - 'width': 50, + 'width': 70, 'height': 24, }, ] diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index ee9d541762..53ab0aaf14 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -268,6 +268,10 @@ ); }); + $('#print-label').click(function() { + printPartLabels([{{ part.pk }}]); + }); + $("#part-count").click(function() { launchModalForm("/stock/adjust/", { data: { diff --git a/InvenTree/templates/js/label.js b/InvenTree/templates/js/label.js index dab9c6dcfa..dc9e8fa935 100644 --- a/InvenTree/templates/js/label.js +++ b/InvenTree/templates/js/label.js @@ -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={}) { /** * Present the user with the available labels,