Update note accessors

This commit is contained in:
Oliver Walters
2026-05-24 10:10:28 +00:00
parent 8377f53b6f
commit 9e91663d07
+17 -3
View File
@@ -707,9 +707,23 @@ class InvenTreeNoteMixin(InvenTreePermissionCheckMixin):
if len(notes) > 0: if len(notes) > 0:
common.models.Note.objects.bulk_create(notes, batch_size=250) common.models.Note.objects.bulk_create(notes, batch_size=250)
def get_note(self, title: str): @property
"""Return a Note instance for the given note title.""" def primary_note(self):
return self.notes_list.filter(title=title).first() """Return the primary note for this model instance, if it exists."""
return self.notes_list.all().order_by('-primary').first()
def get_note(self, title: Optional[str] = None):
"""Return a Note instance for the given note title.
Arguments:
title: Title of the note to retrieve. If None, returns the primary note (if it exists)
"""
notes = self.notes_list.all().order_by('-primary')
if title:
notes = notes.filter(title=title)
return notes.first()
def check_note_delete(self, note) -> bool: def check_note_delete(self, note) -> bool:
"""Run a check to determine if the provided note can be deleted. """Run a check to determine if the provided note can be deleted.