mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bug fix for label printing with plugin on CUI (#7324)
* Bug fix for label printing with plugin on CUI - Missed edge case in recent refactor * Fix typo * Support non-pk fields * fix a number of typos * js fixes
This commit is contained in:
parent
bdebf878c3
commit
9047e325a9
@ -150,7 +150,7 @@ class LabelPrint(GenericAPIView):
|
||||
"""Return the plugin class for the given plugin key."""
|
||||
from plugin.models import PluginConfig
|
||||
|
||||
if plugin_slug is None:
|
||||
if not plugin_slug:
|
||||
# Use the default label printing plugin
|
||||
plugin_slug = InvenTreeLabelPlugin.NAME.lower()
|
||||
|
||||
@ -196,10 +196,10 @@ class LabelPrint(GenericAPIView):
|
||||
|
||||
# Plugin information provided?
|
||||
if self.request:
|
||||
plugin_key = self.request.data.get('plugin', None)
|
||||
plugin_key = self.request.data.get('plugin', '')
|
||||
# Legacy url based lookup
|
||||
if not plugin_key:
|
||||
plugin_key = self.request.query_params.get('plugin', None)
|
||||
plugin_key = self.request.query_params.get('plugin', '')
|
||||
plugin = self.get_plugin_class(plugin_key)
|
||||
plugin_serializer = self.get_plugin_serializer(plugin)
|
||||
|
||||
|
@ -2030,7 +2030,7 @@ function initializeRelatedField(field, fields, options={}) {
|
||||
|
||||
// Each 'row' must have the 'id' attribute
|
||||
for (var idx = 0; idx < data.length; idx++) {
|
||||
data[idx].id = data[idx].pk;
|
||||
data[idx].id = data[idx][field.pk_field ?? 'pk'];
|
||||
}
|
||||
|
||||
// Ref: https://select2.org/data-sources/formats
|
||||
@ -2054,7 +2054,9 @@ function initializeRelatedField(field, fields, options={}) {
|
||||
data = item.element.instance;
|
||||
}
|
||||
|
||||
if (!data.pk) {
|
||||
const pkField = field.pk_field ?? 'pk';
|
||||
|
||||
if (!data[pkField]) {
|
||||
return $(searching());
|
||||
}
|
||||
|
||||
@ -2075,6 +2077,8 @@ function initializeRelatedField(field, fields, options={}) {
|
||||
// Or, use the raw 'item' data as a backup
|
||||
var data = item;
|
||||
|
||||
const pkField = field.pk_field ?? 'pk';
|
||||
|
||||
if (item.element && item.element.instance) {
|
||||
data = item.element.instance;
|
||||
}
|
||||
@ -2084,7 +2088,7 @@ function initializeRelatedField(field, fields, options={}) {
|
||||
field.onSelect(data, field, options);
|
||||
}
|
||||
|
||||
if (!data.pk) {
|
||||
if (!data[pkField]) {
|
||||
return field.placeholder || '';
|
||||
}
|
||||
|
||||
@ -2246,7 +2250,9 @@ function setRelatedFieldData(name, data, options={}) {
|
||||
|
||||
var select = getFormFieldElement(name, options);
|
||||
|
||||
var option = new Option(name, data.pk, true, true);
|
||||
const pkField = options?.fields[name]?.pk_field ?? 'pk';
|
||||
|
||||
var option = new Option(name, data[pkField], true, true);
|
||||
|
||||
// Assign the JSON data to the 'instance' attribute,
|
||||
// so we can access and render it later
|
||||
|
@ -48,7 +48,7 @@ const defaultLabelTemplates = {
|
||||
*/
|
||||
function printLabels(options) {
|
||||
|
||||
let pluginId = -1;
|
||||
let plugin_name = '';
|
||||
|
||||
if (!options.items || options.items.length == 0) {
|
||||
showAlertDialog(
|
||||
@ -67,14 +67,13 @@ function printLabels(options) {
|
||||
items: item_string,
|
||||
};
|
||||
|
||||
function getPrintingFields(plugin_id, callback) {
|
||||
let url = '{% url "api-label-print" %}' + `?plugin=${plugin_id}`;
|
||||
function getPrintingFields(plugin_slug, callback) {
|
||||
|
||||
let url = '{% url "api-label-print" %}' + `?plugin=${plugin_slug}`;
|
||||
|
||||
inventreeGet(
|
||||
url,
|
||||
{
|
||||
plugin: plugin_id,
|
||||
},
|
||||
{},
|
||||
{
|
||||
method: 'OPTIONS',
|
||||
success: function(response) {
|
||||
@ -88,11 +87,11 @@ function printLabels(options) {
|
||||
// Callback when a particular label printing plugin is selected
|
||||
function onPluginSelected(value, name, field, formOptions) {
|
||||
|
||||
if (value == pluginId) {
|
||||
if (value == plugin_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
pluginId = value;
|
||||
plugin_name = value;
|
||||
|
||||
// Request new printing options for the selected plugin
|
||||
getPrintingFields(value, function(fields) {
|
||||
@ -108,7 +107,9 @@ function printLabels(options) {
|
||||
|
||||
const baseFields = {
|
||||
template: {},
|
||||
plugin: {},
|
||||
plugin: {
|
||||
idField: 'key',
|
||||
},
|
||||
items: {}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user