From 3309032b261e891944db5270a305a3ecf9f926ce Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 11 Jun 2026 16:32:14 +1000 Subject: [PATCH] Machine fixes (#12154) * Handle missing machine location - e.g. if location PK is invalid or has been deleted * Add spotlight action for machine management panel * Add unit test for code change --- .../InvenTree/machine/machine_types/label_printer.py | 2 +- src/backend/InvenTree/machine/tests.py | 8 ++++++++ src/frontend/src/defaults/actions.tsx | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/backend/InvenTree/machine/machine_types/label_printer.py b/src/backend/InvenTree/machine/machine_types/label_printer.py index f598f5dd55..47f108ffc7 100644 --- a/src/backend/InvenTree/machine/machine_types/label_printer.py +++ b/src/backend/InvenTree/machine/machine_types/label_printer.py @@ -267,4 +267,4 @@ class LabelPrinterMachine(BaseMachineType): if not location_pk: return None - return StockLocation.objects.get(pk=location_pk) + return StockLocation.objects.filter(pk=location_pk).first() diff --git a/src/backend/InvenTree/machine/tests.py b/src/backend/InvenTree/machine/tests.py index 831438e356..abd7f42211 100755 --- a/src/backend/InvenTree/machine/tests.py +++ b/src/backend/InvenTree/machine/tests.py @@ -297,6 +297,14 @@ class TestLabelPrinterMachineType(InvenTreeAPITestCase): self.assertIn('is not a valid choice', str(response.data['machine'])) + def test_location_invalid_pk(self): + """Test that location property returns None for an invalid PK without raising.""" + machine = self.create_machine() + + machine.set_setting('LOCATION', 'M', 999999) + + self.assertIsNone(machine.location) + class AdminTest(AdminTestCase): """Tests for the admin interface integration.""" diff --git a/src/frontend/src/defaults/actions.tsx b/src/frontend/src/defaults/actions.tsx index 908dce6b3c..1eb3d01a32 100644 --- a/src/frontend/src/defaults/actions.tsx +++ b/src/frontend/src/defaults/actions.tsx @@ -2,6 +2,7 @@ import { t } from '@lingui/core/macro'; import type { SpotlightActionData } from '@mantine/spotlight'; import { IconBarcode, + IconDevicesPc, IconLink, IconPlug, IconPointer, @@ -234,6 +235,16 @@ export function getActions(navigate: NavigateFunction) { leftSection: }); + staff && + user?.hasViewPermission(ModelType.pluginconfig) && + _actions.push({ + id: 'machine-management', + label: t`Machines`, + description: t`Manage machines and machine types`, + onClick: () => navigate('/settings/admin/machine'), + leftSection: + }); + staff && user?.hasViewPermission(ModelType.reporttemplate) && _actions.push({