mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Download PDF for labels
This commit is contained in:
parent
bdc7367e29
commit
e133fff03e
@ -17,7 +17,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from InvenTree.helpers import validateFilterString, normalize
|
from InvenTree.helpers import validateFilterString, normalize
|
||||||
|
|
||||||
from stock.models import StockItem, StockLocation
|
import stock.models
|
||||||
|
|
||||||
|
|
||||||
def rename_label(instance, filename):
|
def rename_label(instance, filename):
|
||||||
@ -128,7 +128,7 @@ class StockItemLabel(LabelTemplate):
|
|||||||
|
|
||||||
filters = validateFilterString(self.filters)
|
filters = validateFilterString(self.filters)
|
||||||
|
|
||||||
items = StockItem.objects.filter(**filters)
|
items = stock.models.StockItem.objects.filter(**filters)
|
||||||
|
|
||||||
items = items.filter(pk=item.pk)
|
items = items.filter(pk=item.pk)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ class StockLocationLabel(LabelTemplate):
|
|||||||
|
|
||||||
filters = validateFilterString(self.filters)
|
filters = validateFilterString(self.filters)
|
||||||
|
|
||||||
locs = StockLocation.objects.filter(**filters)
|
locs = stock.models.StockLocation.objects.filter(**filters)
|
||||||
|
|
||||||
locs = locs.filter(pk=location.pk)
|
locs = locs.filter(pk=location.pk)
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ from InvenTree import helpers
|
|||||||
|
|
||||||
import common.models
|
import common.models
|
||||||
import report.models
|
import report.models
|
||||||
|
import label.models
|
||||||
|
|
||||||
from InvenTree.status_codes import StockStatus
|
from InvenTree.status_codes import StockStatus
|
||||||
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
|
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
|
||||||
@ -1333,14 +1334,31 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
return len(self.available_test_reports()) > 0
|
return len(self.available_test_reports()) > 0
|
||||||
|
|
||||||
|
def available_labels(self):
|
||||||
|
"""
|
||||||
|
Return a list of Label objects which match this StockItem
|
||||||
|
"""
|
||||||
|
|
||||||
|
labels = []
|
||||||
|
|
||||||
|
item_query = StockItem.objects.filter(pk=self.pk)
|
||||||
|
|
||||||
|
for lbl in label.models.StockItemLabel.objects.filter(enabled=True):
|
||||||
|
|
||||||
|
filters = helpers.validateFilterString(lbl.filters)
|
||||||
|
|
||||||
|
if item_query.filter(**filters).exists():
|
||||||
|
labels.append(lbl)
|
||||||
|
|
||||||
|
return labels
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_labels(self):
|
def has_labels(self):
|
||||||
"""
|
"""
|
||||||
Return True if there are any label templates available for this stock item
|
Return True if there are any label templates available for this stock item
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO - Implement this
|
return len(self.available_labels()) > 0
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=StockItem, dispatch_uid='stock_item_pre_delete_log')
|
@receiver(pre_delete, sender=StockItem, dispatch_uid='stock_item_pre_delete_log')
|
||||||
|
@ -403,12 +403,7 @@ $("#stock-test-report").click(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#print-label").click(function() {
|
$("#print-label").click(function() {
|
||||||
launchModalForm(
|
printStockItemLabels([{{ item.pk }}]);
|
||||||
"{% url 'stock-item-label-select' item.id %}",
|
|
||||||
{
|
|
||||||
follow: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#stock-duplicate").click(function() {
|
$("#stock-duplicate").click(function() {
|
||||||
|
@ -1,6 +1,45 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
function selectLabel(labels, options={}) {
|
function printStockItemLabels(items, options={}) {
|
||||||
|
/**
|
||||||
|
* Print stock item labels for the given stock items
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (items.length == 0) {
|
||||||
|
showAlertDialog(
|
||||||
|
'{% trans "Select Stock Items" %}',
|
||||||
|
'{% trans "Stock items must be selected before printing labels" %}'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request available labels from the server
|
||||||
|
inventreeGet(
|
||||||
|
'{% url "api-stockitem-label-list" %}',
|
||||||
|
{
|
||||||
|
enabled: true,
|
||||||
|
items: items,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
success: function(response) {
|
||||||
|
|
||||||
|
if (response.length == 0) {
|
||||||
|
showAlertDialog(
|
||||||
|
'{% trans "No Labels Found" %}',
|
||||||
|
'{% trans "No labels found which match selected stock item(s)" %}',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select label to print
|
||||||
|
selectLabel(response, items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectLabel(labels, items, options={}) {
|
||||||
/**
|
/**
|
||||||
* Present the user with the available labels,
|
* Present the user with the available labels,
|
||||||
* and allow them to select which label to print.
|
* and allow them to select which label to print.
|
||||||
@ -9,6 +48,8 @@ function selectLabel(labels, options={}) {
|
|||||||
* (via AJAX) from the server.
|
* (via AJAX) from the server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var stock_items = items;
|
||||||
|
|
||||||
var modal = options.modal || '#modal-form';
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
var label_list = makeOptionsList(
|
var label_list = makeOptionsList(
|
||||||
@ -29,6 +70,7 @@ function selectLabel(labels, options={}) {
|
|||||||
|
|
||||||
// Construct form
|
// Construct form
|
||||||
var html = `
|
var html = `
|
||||||
|
|
||||||
<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
|
<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
|
||||||
<div class='form-group'>
|
<div class='form-group'>
|
||||||
<label class='control-label requiredField' for='id_label'>
|
<label class='control-label requiredField' for='id_label'>
|
||||||
@ -49,4 +91,23 @@ function selectLabel(labels, options={}) {
|
|||||||
modalEnable(modal, true);
|
modalEnable(modal, true);
|
||||||
modalSetTitle(modal, '{% trans "Select Label Template" %}');
|
modalSetTitle(modal, '{% trans "Select Label Template" %}');
|
||||||
modalSetContent(modal, html);
|
modalSetContent(modal, html);
|
||||||
|
|
||||||
|
attachSelect(modal);
|
||||||
|
|
||||||
|
modalSubmit(modal, function() {
|
||||||
|
|
||||||
|
var label = $(modal).find('#id_label');
|
||||||
|
|
||||||
|
var pk = label.val();
|
||||||
|
|
||||||
|
closeModal(modal);
|
||||||
|
|
||||||
|
var href = `/api/label/stock/${pk}/print/?`;
|
||||||
|
|
||||||
|
stock_items.forEach(function(item) {
|
||||||
|
href += `items[]=${item}&`;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.location.href = href;
|
||||||
|
});
|
||||||
}
|
}
|
@ -166,6 +166,15 @@ function setFieldValue(fieldName, value, options={}) {
|
|||||||
field.val(value);
|
field.val(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFieldValue(fieldName, options={}) {
|
||||||
|
|
||||||
|
var modal = options.modal || '#modal-form';
|
||||||
|
|
||||||
|
var field = getFieldByName(modal, fieldName);
|
||||||
|
|
||||||
|
return field.val();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function partialMatcher(params, data) {
|
function partialMatcher(params, data) {
|
||||||
/* Replacement function for the 'matcher' parameter for a select2 dropdown.
|
/* Replacement function for the 'matcher' parameter for a select2 dropdown.
|
||||||
|
@ -654,28 +654,7 @@ function loadStockTable(table, options) {
|
|||||||
items.push(item.pk);
|
items.push(item.pk);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request available labels from the server
|
printStockItemLabels(items);
|
||||||
inventreeGet(
|
|
||||||
'{% url "api-stockitem-label-list" %}',
|
|
||||||
{
|
|
||||||
enabled: true,
|
|
||||||
items: items,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
success: function(response) {
|
|
||||||
|
|
||||||
if (response.length == 0) {
|
|
||||||
showAlertDialog(
|
|
||||||
'{% trans "No Labels Found" %}',
|
|
||||||
'{% trans "No labels found which match selected stock item(s)" %}',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var label = selectLabel(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#multi-item-stocktake').click(function() {
|
$('#multi-item-stocktake').click(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user