mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-02 19:08:47 +00:00
Fix note duplication
This commit is contained in:
@@ -702,23 +702,24 @@ class InvenTreeNoteMixin(InvenTreePermissionCheckMixin, models.Model):
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
other: The other model instance to copy notes from
|
other: The other model instance to copy notes from
|
||||||
**kwargs: Additional keyword arguments to pass to the Note constructor
|
|
||||||
"""
|
"""
|
||||||
import common.models
|
import common.models
|
||||||
|
|
||||||
notes = []
|
|
||||||
|
|
||||||
content_type = ContentType.objects.get_for_model(self.__class__)
|
content_type = ContentType.objects.get_for_model(self.__class__)
|
||||||
|
|
||||||
for note in other.notes.all():
|
# Sort so primary note is saved last — Note.save() promotes the last
|
||||||
note.pk = None
|
# note saved with primary=True, which correctly mirrors the source.
|
||||||
note.model_id = self.pk
|
source_notes = sorted(other.notes.all(), key=lambda n: n.primary)
|
||||||
note.model_type = content_type
|
|
||||||
|
|
||||||
notes.append(note)
|
for source_note in source_notes:
|
||||||
|
common.models.Note(
|
||||||
if len(notes) > 0:
|
model_type=content_type,
|
||||||
common.models.Note.objects.bulk_create(notes, batch_size=250)
|
model_id=self.pk,
|
||||||
|
primary=source_note.primary,
|
||||||
|
title=source_note.title,
|
||||||
|
description=source_note.description,
|
||||||
|
content=source_note.content,
|
||||||
|
).save()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def primary_note(self):
|
def primary_note(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user