2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-06-11 19:27:02 +00:00

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
This commit is contained in:
Oliver
2026-06-11 16:32:14 +10:00
committed by GitHub
parent 39cc399a67
commit 3309032b26
3 changed files with 20 additions and 1 deletions
@@ -267,4 +267,4 @@ class LabelPrinterMachine(BaseMachineType):
if not location_pk: if not location_pk:
return None return None
return StockLocation.objects.get(pk=location_pk) return StockLocation.objects.filter(pk=location_pk).first()
+8
View File
@@ -297,6 +297,14 @@ class TestLabelPrinterMachineType(InvenTreeAPITestCase):
self.assertIn('is not a valid choice', str(response.data['machine'])) 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): class AdminTest(AdminTestCase):
"""Tests for the admin interface integration.""" """Tests for the admin interface integration."""
+11
View File
@@ -2,6 +2,7 @@ import { t } from '@lingui/core/macro';
import type { SpotlightActionData } from '@mantine/spotlight'; import type { SpotlightActionData } from '@mantine/spotlight';
import { import {
IconBarcode, IconBarcode,
IconDevicesPc,
IconLink, IconLink,
IconPlug, IconPlug,
IconPointer, IconPointer,
@@ -234,6 +235,16 @@ export function getActions(navigate: NavigateFunction) {
leftSection: <IconPlug size='1.2rem' /> leftSection: <IconPlug size='1.2rem' />
}); });
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: <IconDevicesPc size='1.2rem' />
});
staff && staff &&
user?.hasViewPermission(ModelType.reporttemplate) && user?.hasViewPermission(ModelType.reporttemplate) &&
_actions.push({ _actions.push({