mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-05 14:58:50 +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."""
|
"""Return the plugin class for the given plugin key."""
|
||||||
from plugin.models import PluginConfig
|
from plugin.models import PluginConfig
|
||||||
|
|
||||||
if plugin_slug is None:
|
if not plugin_slug:
|
||||||
# Use the default label printing plugin
|
# Use the default label printing plugin
|
||||||
plugin_slug = InvenTreeLabelPlugin.NAME.lower()
|
plugin_slug = InvenTreeLabelPlugin.NAME.lower()
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ class LabelPrint(GenericAPIView):
|
|||||||
|
|
||||||
# Plugin information provided?
|
# Plugin information provided?
|
||||||
if self.request:
|
if self.request:
|
||||||
plugin_key = self.request.data.get('plugin', None)
|
plugin_key = self.request.data.get('plugin', '')
|
||||||
# Legacy url based lookup
|
# Legacy url based lookup
|
||||||
if not plugin_key:
|
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 = self.get_plugin_class(plugin_key)
|
||||||
plugin_serializer = self.get_plugin_serializer(plugin)
|
plugin_serializer = self.get_plugin_serializer(plugin)
|
||||||
|
|
||||||
|
@ -2030,7 +2030,7 @@ function initializeRelatedField(field, fields, options={}) {
|
|||||||
|
|
||||||
// Each 'row' must have the 'id' attribute
|
// Each 'row' must have the 'id' attribute
|
||||||
for (var idx = 0; idx < data.length; idx++) {
|
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
|
// Ref: https://select2.org/data-sources/formats
|
||||||
@ -2054,7 +2054,9 @@ function initializeRelatedField(field, fields, options={}) {
|
|||||||
data = item.element.instance;
|
data = item.element.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.pk) {
|
const pkField = field.pk_field ?? 'pk';
|
||||||
|
|
||||||
|
if (!data[pkField]) {
|
||||||
return $(searching());
|
return $(searching());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2075,6 +2077,8 @@ function initializeRelatedField(field, fields, options={}) {
|
|||||||
// Or, use the raw 'item' data as a backup
|
// Or, use the raw 'item' data as a backup
|
||||||
var data = item;
|
var data = item;
|
||||||
|
|
||||||
|
const pkField = field.pk_field ?? 'pk';
|
||||||
|
|
||||||
if (item.element && item.element.instance) {
|
if (item.element && item.element.instance) {
|
||||||
data = item.element.instance;
|
data = item.element.instance;
|
||||||
}
|
}
|
||||||
@ -2084,7 +2088,7 @@ function initializeRelatedField(field, fields, options={}) {
|
|||||||
field.onSelect(data, field, options);
|
field.onSelect(data, field, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.pk) {
|
if (!data[pkField]) {
|
||||||
return field.placeholder || '';
|
return field.placeholder || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2246,7 +2250,9 @@ function setRelatedFieldData(name, data, options={}) {
|
|||||||
|
|
||||||
var select = getFormFieldElement(name, 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,
|
// Assign the JSON data to the 'instance' attribute,
|
||||||
// so we can access and render it later
|
// so we can access and render it later
|
||||||
|
@ -48,7 +48,7 @@ const defaultLabelTemplates = {
|
|||||||
*/
|
*/
|
||||||
function printLabels(options) {
|
function printLabels(options) {
|
||||||
|
|
||||||
let pluginId = -1;
|
let plugin_name = '';
|
||||||
|
|
||||||
if (!options.items || options.items.length == 0) {
|
if (!options.items || options.items.length == 0) {
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
@ -67,14 +67,13 @@ function printLabels(options) {
|
|||||||
items: item_string,
|
items: item_string,
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPrintingFields(plugin_id, callback) {
|
function getPrintingFields(plugin_slug, callback) {
|
||||||
let url = '{% url "api-label-print" %}' + `?plugin=${plugin_id}`;
|
|
||||||
|
let url = '{% url "api-label-print" %}' + `?plugin=${plugin_slug}`;
|
||||||
|
|
||||||
inventreeGet(
|
inventreeGet(
|
||||||
url,
|
url,
|
||||||
{
|
{},
|
||||||
plugin: plugin_id,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
method: 'OPTIONS',
|
method: 'OPTIONS',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@ -88,11 +87,11 @@ function printLabels(options) {
|
|||||||
// Callback when a particular label printing plugin is selected
|
// Callback when a particular label printing plugin is selected
|
||||||
function onPluginSelected(value, name, field, formOptions) {
|
function onPluginSelected(value, name, field, formOptions) {
|
||||||
|
|
||||||
if (value == pluginId) {
|
if (value == plugin_name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginId = value;
|
plugin_name = value;
|
||||||
|
|
||||||
// Request new printing options for the selected plugin
|
// Request new printing options for the selected plugin
|
||||||
getPrintingFields(value, function(fields) {
|
getPrintingFields(value, function(fields) {
|
||||||
@ -108,7 +107,9 @@ function printLabels(options) {
|
|||||||
|
|
||||||
const baseFields = {
|
const baseFields = {
|
||||||
template: {},
|
template: {},
|
||||||
plugin: {},
|
plugin: {
|
||||||
|
idField: 'key',
|
||||||
|
},
|
||||||
items: {}
|
items: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user