mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Label printing bug fixes (#7329)
* Hide printing actions button for top level stock location * Fix typo * Add another check for null * Remove debug statement * Prevent display of multiple form-error notifications * Fix pickling for print offloading * Reset selected plugin * Exclude the entire 'context' object when pickling a printing job
This commit is contained in:
parent
9047e325a9
commit
b402836dc4
@ -16,7 +16,6 @@ In addition to the model-specific context variables, the following global contex
|
|||||||
| base_url | The base URL for the InvenTree instance |
|
| base_url | The base URL for the InvenTree instance |
|
||||||
| date | Current date, represented as a Python datetime.date object |
|
| date | Current date, represented as a Python datetime.date object |
|
||||||
| datetime | Current datetime, represented as a Python datetime object |
|
| datetime | Current datetime, represented as a Python datetime object |
|
||||||
| request | The Django request object associated with the printing process |
|
|
||||||
| template | The report template instance which is being rendered against |
|
| template | The report template instance which is being rendered against |
|
||||||
| template_description | Description of the report template |
|
| template_description | Description of the report template |
|
||||||
| template_name | Name of the report template |
|
| template_name | Name of the report template |
|
||||||
|
@ -147,6 +147,9 @@ class LabelPrintingMixin:
|
|||||||
|
|
||||||
N = len(items)
|
N = len(items)
|
||||||
|
|
||||||
|
if N <= 0:
|
||||||
|
raise ValidationError(_('No items provided to print'))
|
||||||
|
|
||||||
# Generate a label output for each provided item
|
# Generate a label output for each provided item
|
||||||
for item in items:
|
for item in items:
|
||||||
context = label.get_context(item, request)
|
context = label.get_context(item, request)
|
||||||
@ -177,9 +180,13 @@ class LabelPrintingMixin:
|
|||||||
self.print_label(**print_args)
|
self.print_label(**print_args)
|
||||||
else:
|
else:
|
||||||
# Offload the print task to the background worker
|
# Offload the print task to the background worker
|
||||||
# Exclude the 'pdf_file' object - cannot be pickled
|
|
||||||
|
|
||||||
kwargs.pop('pdf_file', None)
|
# Exclude the 'pdf_file' object - cannot be pickled
|
||||||
|
print_args.pop('pdf_file', None)
|
||||||
|
|
||||||
|
# Exclude the 'context' object - cannot be pickled
|
||||||
|
print_args.pop('context', None)
|
||||||
|
|
||||||
offload_task(plugin_label.print_label, self.plugin_slug(), **print_args)
|
offload_task(plugin_label.print_label, self.plugin_slug(), **print_args)
|
||||||
|
|
||||||
# Update the progress of the print job
|
# Update the progress of the print job
|
||||||
|
@ -246,7 +246,6 @@ class ReportTemplateBase(MetadataMixin, InvenTree.models.InvenTreeModel):
|
|||||||
'base_url': get_base_url(request=request),
|
'base_url': get_base_url(request=request),
|
||||||
'date': InvenTree.helpers.current_date(),
|
'date': InvenTree.helpers.current_date(),
|
||||||
'datetime': InvenTree.helpers.current_time(),
|
'datetime': InvenTree.helpers.current_time(),
|
||||||
'request': request,
|
|
||||||
'template': self,
|
'template': self,
|
||||||
'template_description': self.description,
|
'template_description': self.description,
|
||||||
'template_name': self.name,
|
'template_name': self.name,
|
||||||
|
@ -2158,7 +2158,7 @@ class StockItem(
|
|||||||
|
|
||||||
def testResultList(self, **kwargs):
|
def testResultList(self, **kwargs):
|
||||||
"""Return a list of test-result objects for this StockItem."""
|
"""Return a list of test-result objects for this StockItem."""
|
||||||
return self.testResultMap(**kwargs).values()
|
return list(self.testResultMap(**kwargs).values())
|
||||||
|
|
||||||
def requiredTestStatus(self):
|
def requiredTestStatus(self):
|
||||||
"""Return the status of the tests required for this StockItem.
|
"""Return the status of the tests required for this StockItem.
|
||||||
|
@ -15,11 +15,13 @@ import { ActionDropdown } from '../items/ActionDropdown';
|
|||||||
|
|
||||||
export function PrintingActions({
|
export function PrintingActions({
|
||||||
items,
|
items,
|
||||||
|
hidden,
|
||||||
enableLabels,
|
enableLabels,
|
||||||
enableReports,
|
enableReports,
|
||||||
modelType
|
modelType
|
||||||
}: {
|
}: {
|
||||||
items: number[];
|
items: number[];
|
||||||
|
hidden?: boolean;
|
||||||
enableLabels?: boolean;
|
enableLabels?: boolean;
|
||||||
enableReports?: boolean;
|
enableReports?: boolean;
|
||||||
modelType?: ModelType;
|
modelType?: ModelType;
|
||||||
@ -79,8 +81,6 @@ export function PrintingActions({
|
|||||||
mixin: 'labels'
|
mixin: 'labels'
|
||||||
},
|
},
|
||||||
onValueChange: (value: string, record?: any) => {
|
onValueChange: (value: string, record?: any) => {
|
||||||
console.log('onValueChange:', value, record);
|
|
||||||
|
|
||||||
if (record?.key && record?.key != pluginKey) {
|
if (record?.key && record?.key != pluginKey) {
|
||||||
setPluginKey(record.key);
|
setPluginKey(record.key);
|
||||||
}
|
}
|
||||||
@ -100,6 +100,7 @@ export function PrintingActions({
|
|||||||
},
|
},
|
||||||
successMessage: t`Label printing completed successfully`,
|
successMessage: t`Label printing completed successfully`,
|
||||||
onFormSuccess: (response: any) => {
|
onFormSuccess: (response: any) => {
|
||||||
|
setPluginKey('');
|
||||||
if (!response.complete) {
|
if (!response.complete) {
|
||||||
// TODO: Periodically check for completion (requires server-side changes)
|
// TODO: Periodically check for completion (requires server-side changes)
|
||||||
notifications.show({
|
notifications.show({
|
||||||
@ -164,28 +165,30 @@ export function PrintingActions({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
!hidden && (
|
||||||
{reportModal.modal}
|
<>
|
||||||
{labelModal.modal}
|
{reportModal.modal}
|
||||||
<ActionDropdown
|
{labelModal.modal}
|
||||||
tooltip={t`Printing Actions`}
|
<ActionDropdown
|
||||||
icon={<IconPrinter />}
|
tooltip={t`Printing Actions`}
|
||||||
disabled={!enabled}
|
icon={<IconPrinter />}
|
||||||
actions={[
|
disabled={!enabled}
|
||||||
{
|
actions={[
|
||||||
name: t`Print Labels`,
|
{
|
||||||
icon: <IconTags />,
|
name: t`Print Labels`,
|
||||||
onClick: () => labelModal.open(),
|
icon: <IconTags />,
|
||||||
hidden: !enableLabels
|
onClick: () => labelModal.open(),
|
||||||
},
|
hidden: !enableLabels
|
||||||
{
|
},
|
||||||
name: t`Print Reports`,
|
{
|
||||||
icon: <IconReport />,
|
name: t`Print Reports`,
|
||||||
onClick: () => reportModal.open(),
|
icon: <IconReport />,
|
||||||
hidden: !enableReports
|
onClick: () => reportModal.open(),
|
||||||
}
|
hidden: !enableReports
|
||||||
]}
|
}
|
||||||
/>
|
]}
|
||||||
</>
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,12 @@ export function OptionsApiForm({
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
invalidResponse(error.response.status);
|
invalidResponse(error.response.status);
|
||||||
} else {
|
} else {
|
||||||
|
notifications.hide('form-error');
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: t`Form Error`,
|
title: t`Form Error`,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
color: 'red'
|
color: 'red',
|
||||||
|
id: 'form-error'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -294,6 +294,7 @@ export default function Stock() {
|
|||||||
<PrintingActions
|
<PrintingActions
|
||||||
modelType={ModelType.stocklocation}
|
modelType={ModelType.stocklocation}
|
||||||
items={[location.pk ?? 0]}
|
items={[location.pk ?? 0]}
|
||||||
|
hidden={!location?.pk}
|
||||||
enableLabels
|
enableLabels
|
||||||
enableReports
|
enableReports
|
||||||
/>,
|
/>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user