mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +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:
		| @@ -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 | | ||||
| | date | Current date, represented as a Python datetime.date 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_description | Description of the report template | | ||||
| | template_name | Name of the report template | | ||||
|   | ||||
| @@ -147,6 +147,9 @@ class LabelPrintingMixin: | ||||
|  | ||||
|         N = len(items) | ||||
|  | ||||
|         if N <= 0: | ||||
|             raise ValidationError(_('No items provided to print')) | ||||
|  | ||||
|         # Generate a label output for each provided item | ||||
|         for item in items: | ||||
|             context = label.get_context(item, request) | ||||
| @@ -177,9 +180,13 @@ class LabelPrintingMixin: | ||||
|                 self.print_label(**print_args) | ||||
|             else: | ||||
|                 # 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) | ||||
|  | ||||
|             # Update the progress of the print job | ||||
|   | ||||
| @@ -246,7 +246,6 @@ class ReportTemplateBase(MetadataMixin, InvenTree.models.InvenTreeModel): | ||||
|             'base_url': get_base_url(request=request), | ||||
|             'date': InvenTree.helpers.current_date(), | ||||
|             'datetime': InvenTree.helpers.current_time(), | ||||
|             'request': request, | ||||
|             'template': self, | ||||
|             'template_description': self.description, | ||||
|             'template_name': self.name, | ||||
|   | ||||
| @@ -2158,7 +2158,7 @@ class StockItem( | ||||
|  | ||||
|     def testResultList(self, **kwargs): | ||||
|         """Return a list of test-result objects for this StockItem.""" | ||||
|         return self.testResultMap(**kwargs).values() | ||||
|         return list(self.testResultMap(**kwargs).values()) | ||||
|  | ||||
|     def requiredTestStatus(self): | ||||
|         """Return the status of the tests required for this StockItem. | ||||
|   | ||||
| @@ -15,11 +15,13 @@ import { ActionDropdown } from '../items/ActionDropdown'; | ||||
|  | ||||
| export function PrintingActions({ | ||||
|   items, | ||||
|   hidden, | ||||
|   enableLabels, | ||||
|   enableReports, | ||||
|   modelType | ||||
| }: { | ||||
|   items: number[]; | ||||
|   hidden?: boolean; | ||||
|   enableLabels?: boolean; | ||||
|   enableReports?: boolean; | ||||
|   modelType?: ModelType; | ||||
| @@ -79,8 +81,6 @@ export function PrintingActions({ | ||||
|         mixin: 'labels' | ||||
|       }, | ||||
|       onValueChange: (value: string, record?: any) => { | ||||
|         console.log('onValueChange:', value, record); | ||||
|  | ||||
|         if (record?.key && record?.key != pluginKey) { | ||||
|           setPluginKey(record.key); | ||||
|         } | ||||
| @@ -100,6 +100,7 @@ export function PrintingActions({ | ||||
|     }, | ||||
|     successMessage: t`Label printing completed successfully`, | ||||
|     onFormSuccess: (response: any) => { | ||||
|       setPluginKey(''); | ||||
|       if (!response.complete) { | ||||
|         // TODO: Periodically check for completion (requires server-side changes) | ||||
|         notifications.show({ | ||||
| @@ -164,28 +165,30 @@ export function PrintingActions({ | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <> | ||||
|       {reportModal.modal} | ||||
|       {labelModal.modal} | ||||
|       <ActionDropdown | ||||
|         tooltip={t`Printing Actions`} | ||||
|         icon={<IconPrinter />} | ||||
|         disabled={!enabled} | ||||
|         actions={[ | ||||
|           { | ||||
|             name: t`Print Labels`, | ||||
|             icon: <IconTags />, | ||||
|             onClick: () => labelModal.open(), | ||||
|             hidden: !enableLabels | ||||
|           }, | ||||
|           { | ||||
|             name: t`Print Reports`, | ||||
|             icon: <IconReport />, | ||||
|             onClick: () => reportModal.open(), | ||||
|             hidden: !enableReports | ||||
|           } | ||||
|         ]} | ||||
|       /> | ||||
|     </> | ||||
|     !hidden && ( | ||||
|       <> | ||||
|         {reportModal.modal} | ||||
|         {labelModal.modal} | ||||
|         <ActionDropdown | ||||
|           tooltip={t`Printing Actions`} | ||||
|           icon={<IconPrinter />} | ||||
|           disabled={!enabled} | ||||
|           actions={[ | ||||
|             { | ||||
|               name: t`Print Labels`, | ||||
|               icon: <IconTags />, | ||||
|               onClick: () => labelModal.open(), | ||||
|               hidden: !enableLabels | ||||
|             }, | ||||
|             { | ||||
|               name: t`Print Reports`, | ||||
|               icon: <IconReport />, | ||||
|               onClick: () => reportModal.open(), | ||||
|               hidden: !enableReports | ||||
|             } | ||||
|           ]} | ||||
|         /> | ||||
|       </> | ||||
|     ) | ||||
|   ); | ||||
| } | ||||
|   | ||||
| @@ -144,10 +144,12 @@ export function OptionsApiForm({ | ||||
|       if (error.response) { | ||||
|         invalidResponse(error.response.status); | ||||
|       } else { | ||||
|         notifications.hide('form-error'); | ||||
|         notifications.show({ | ||||
|           title: t`Form Error`, | ||||
|           message: error.message, | ||||
|           color: 'red' | ||||
|           color: 'red', | ||||
|           id: 'form-error' | ||||
|         }); | ||||
|       } | ||||
|       return false; | ||||
|   | ||||
| @@ -294,6 +294,7 @@ export default function Stock() { | ||||
|       <PrintingActions | ||||
|         modelType={ModelType.stocklocation} | ||||
|         items={[location.pk ?? 0]} | ||||
|         hidden={!location?.pk} | ||||
|         enableLabels | ||||
|         enableReports | ||||
|       />, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user