All workflows types override previous

This commit is contained in:
shamoon
2023-12-27 09:06:09 -08:00
parent d127c37977
commit 5b95f0a2c6
5 changed files with 14 additions and 17 deletions

View File

@@ -603,13 +603,12 @@ class Consumer(LoggingMixin):
return document
def get_template_overrides(
def get_workflow_overrides(
self,
input_doc: ConsumableDocument,
) -> DocumentMetadataOverrides:
"""
Match consumption templates to a document based on source and
file name filters, path filters or mail rule filter if specified
Get overrides from matching workflows
"""
overrides = DocumentMetadataOverrides()
for workflow in Workflow.objects.filter(enabled=True).order_by("order"):

View File

@@ -33,21 +33,20 @@ class DocumentMetadataOverrides:
def update(self, other: "DocumentMetadataOverrides") -> "DocumentMetadataOverrides":
"""
Merges two DocumentMetadataOverrides objects such that object B's overrides
are only applied if the property is empty in object A or merged if multiple
are accepted.
are applied to object A or merged if multiple are accepted.
The update is an in-place modification of self
"""
# only if empty
if self.title is None:
if other.title is not None:
self.title = other.title
if self.correspondent_id is None:
if other.correspondent_id is not None:
self.correspondent_id = other.correspondent_id
if self.document_type_id is None:
if other.document_type_id is not None:
self.document_type_id = other.document_type_id
if self.storage_path_id is None:
if other.storage_path_id is not None:
self.storage_path_id = other.storage_path_id
if self.owner_id is None:
if other.owner_id is not None:
self.owner_id = other.owner_id
# merge

View File

@@ -158,7 +158,7 @@ def consume_file(
overrides.asn = reader.asn
logger.info(f"Found ASN in barcode: {overrides.asn}")
template_overrides = Consumer().get_template_overrides(
template_overrides = Consumer().get_workflow_overrides(
input_doc=input_doc,
)

View File

@@ -244,7 +244,7 @@ class TestWorkflows(DirectoriesMixin, FileSystemAssertsMixin, APITestCase):
WHEN:
- File that matches is consumed
THEN:
- Template overrides are applied with subsequent templates only overwriting empty values
- Template overrides are applied with subsequent templates overwriting previous values
or merging if multiple
"""
trigger1 = WorkflowTrigger.objects.create(
@@ -306,9 +306,9 @@ class TestWorkflows(DirectoriesMixin, FileSystemAssertsMixin, APITestCase):
m.assert_called_once()
_, overrides = m.call_args
# template 1
self.assertEqual(overrides["override_correspondent_id"], self.c.pk)
self.assertEqual(overrides["override_document_type_id"], self.dt.pk)
# template 2
self.assertEqual(overrides["override_correspondent_id"], self.c2.pk)
self.assertEqual(overrides["override_storage_path_id"], self.sp.pk)
# template 1 & 2
self.assertEqual(