mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-17 20:23:50 +00:00
Fix notes on part creation (#12332)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
@@ -822,9 +822,13 @@ class NotesFieldMixin:
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if hasattr(self, 'context'):
|
if hasattr(self, 'context'):
|
||||||
|
request = self.context.get('request', None)
|
||||||
|
method = getattr(request, 'method', None)
|
||||||
|
|
||||||
if view := self.context.get('view', None):
|
if view := self.context.get('view', None):
|
||||||
if (
|
if (
|
||||||
issubclass(view.__class__, ListModelMixin)
|
issubclass(view.__class__, ListModelMixin)
|
||||||
|
and method in SAFE_METHODS
|
||||||
and not InvenTree.ready.isGeneratingSchema()
|
and not InvenTree.ready.isGeneratingSchema()
|
||||||
):
|
):
|
||||||
self.fields.pop('notes', None)
|
self.fields.pop('notes', None)
|
||||||
|
|||||||
@@ -1495,6 +1495,40 @@ class PartCreationTests(PartAPITestBase):
|
|||||||
self.assertFalse(response.data['active'])
|
self.assertFalse(response.data['active'])
|
||||||
self.assertFalse(response.data['purchaseable'])
|
self.assertFalse(response.data['purchaseable'])
|
||||||
|
|
||||||
|
def test_notes_on_create(self):
|
||||||
|
"""Test that notes can be set when creating a Part."""
|
||||||
|
list_url = reverse('api-part-list')
|
||||||
|
|
||||||
|
notes = """
|
||||||
|
### Created from importer
|
||||||
|
|
||||||
|
Notes should persist during part creation.
|
||||||
|
"""
|
||||||
|
expected_notes = notes.strip()
|
||||||
|
|
||||||
|
response = self.post(
|
||||||
|
list_url,
|
||||||
|
{
|
||||||
|
'name': 'part with notes',
|
||||||
|
'description': 'Part notes are created in the same request',
|
||||||
|
'category': 1,
|
||||||
|
'notes': notes,
|
||||||
|
},
|
||||||
|
expected_code=201,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.data['notes'], expected_notes)
|
||||||
|
|
||||||
|
part = Part.objects.get(pk=response.data['pk'])
|
||||||
|
self.assertEqual(part.notes, expected_notes)
|
||||||
|
|
||||||
|
detail_url = reverse('api-part-detail', kwargs={'pk': part.pk})
|
||||||
|
response = self.get(detail_url, expected_code=200)
|
||||||
|
self.assertEqual(response.data['notes'], expected_notes)
|
||||||
|
|
||||||
|
response = self.get(list_url, {'limit': 1}, expected_code=200)
|
||||||
|
self.assertNotIn('notes', response.data['results'][0])
|
||||||
|
|
||||||
def test_initial_stock(self):
|
def test_initial_stock(self):
|
||||||
"""Tests for initial stock quantity creation."""
|
"""Tests for initial stock quantity creation."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user