mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Printing order (#10199)
* Fix printing order for labels - Order of printing should match order of submission * Same for reports
This commit is contained in:
		| @@ -175,7 +175,10 @@ class LabelPrint(GenericAPIView): | ||||
|  | ||||
|         instances = template.get_model().objects.filter(pk__in=items) | ||||
|  | ||||
|         if instances.count() == 0: | ||||
|         # Sort the instances by the order of the provided items | ||||
|         instances = sorted(instances, key=lambda item: items.index(item.pk)) | ||||
|  | ||||
|         if len(instances) == 0: | ||||
|             raise ValidationError(_('No valid items provided to template')) | ||||
|  | ||||
|         return self.print(template, instances, plugin, request) | ||||
| @@ -254,7 +257,10 @@ class ReportPrint(GenericAPIView): | ||||
|  | ||||
|         instances = template.get_model().objects.filter(pk__in=items) | ||||
|  | ||||
|         if instances.count() == 0: | ||||
|         # Sort the instances by the order of the provided items | ||||
|         instances = sorted(instances, key=lambda item: items.index(item.pk)) | ||||
|  | ||||
|         if len(instances) == 0: | ||||
|             raise ValidationError(_('No valid items provided to template')) | ||||
|  | ||||
|         return self.print(template, instances, request) | ||||
|   | ||||
| @@ -35,6 +35,9 @@ def print_reports(template_id: int, item_ids: list[int], output_id: int, **kwarg | ||||
|     model = template.get_model() | ||||
|     items = model.objects.filter(pk__in=item_ids) | ||||
|  | ||||
|     # Ensure they are sorted by the order of the provided item IDs | ||||
|     items = sorted(items, key=lambda item: item_ids.index(item.pk)) | ||||
|  | ||||
|     template.print(items, output=output) | ||||
|  | ||||
|  | ||||
| @@ -68,6 +71,9 @@ def print_labels( | ||||
|     model = template.get_model() | ||||
|     items = model.objects.filter(pk__in=item_ids) | ||||
|  | ||||
|     # Ensure they are sorted by the order of the provided item IDs | ||||
|     items = sorted(items, key=lambda item: item_ids.index(item.pk)) | ||||
|  | ||||
|     plugin = registry.get_plugin(plugin_slug, active=True) | ||||
|  | ||||
|     if not plugin: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user