2
0
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:
Oliver 2024-05-27 19:12:29 +10:00 committed by GitHub
parent 9047e325a9
commit b402836dc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 42 additions and 31 deletions

View File

@ -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 |

View File

@ -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

View File

@ -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,

View File

@ -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.

View File

@ -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,6 +165,7 @@ export function PrintingActions({
} }
return ( return (
!hidden && (
<> <>
{reportModal.modal} {reportModal.modal}
{labelModal.modal} {labelModal.modal}
@ -187,5 +189,6 @@ export function PrintingActions({
]} ]}
/> />
</> </>
)
); );
} }

View File

@ -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;

View File

@ -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
/>, />,