Skip to content

Commit

Permalink
Allow merging multiple source references with different types. (#4170)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput committed Aug 20, 2024
1 parent 2ded051 commit 25feb04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 0 additions & 6 deletions bims/custom_admin/source_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ def merge_source_references(self, request, queryset):
messages.ERROR)
return

elif source_type >= 2:
self.message_user(
request, 'Source references should have same type', messages.ERROR
)
return

merge_source_references(primary_source_reference=verified.first(),
source_reference_list=queryset)

Expand Down
13 changes: 11 additions & 2 deletions bims/tests/test_source_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def test_merge_source_reference(self):
note='test', source=self.entry)
database = SourceReferenceDatabaseF.create()
document = SourceReferenceDocumentF.create()
unpublished = SourceReferenceF.create(note='unpublished')
source_document_id = document.source.id

BiologicalCollectionRecordF.create(
Expand All @@ -199,6 +200,9 @@ def test_merge_source_reference(self):
BiologicalCollectionRecordF.create(
source_reference=document
)
BiologicalCollectionRecordF.create(
source_reference=unpublished
)
self.assertTrue(
Document.objects.filter(id=source_document_id).exists()
)
Expand All @@ -209,7 +213,7 @@ def test_merge_source_reference(self):
1
)
source_references = SourceReference.objects.filter(
id__in=[database.id, document.id]
id__in=[database.id, document.id, unpublished.id]
)
merge_source_references(
primary_source_reference=biblio,
Expand All @@ -219,7 +223,7 @@ def test_merge_source_reference(self):
BiologicalCollectionRecord.objects.filter(
source_reference=biblio
).count(),
3
4
)
self.assertFalse(
BiologicalCollectionRecord.objects.filter(
Expand All @@ -239,6 +243,11 @@ def test_merge_source_reference(self):
id=document.id
).exists()
)
self.assertFalse(
SourceReference.objects.filter(
id=unpublished.id
).exists()
)


class TestRemoveRecordsBySourceReference(FastTenantTestCase):
Expand Down

0 comments on commit 25feb04

Please sign in to comment.