All workflows types override previous
This commit is contained in:
parent
d127c37977
commit
5b95f0a2c6
@ -274,10 +274,9 @@ to workflow trigger 'types':
|
||||
- Updated: fires when a document is updated. Similar to 'added' events, can include filtering by tags, doc type, or
|
||||
correspondent
|
||||
|
||||
In general, workflows are applied sequentially (by sort order) but the behavior of consequtive workflows depends on the type.
|
||||
"Consumption" workflows will never override an assignment from a preceding workflow. "Added" and "Updated" workflow triggers
|
||||
will overwrite these values (since these are immediately assigned to the document). Titles are always overwritten by
|
||||
subsequent workflows. Assignments that accept multiple items e.g. tags, custom fields and permissions will be merged.
|
||||
In general, workflow (and any actions they contain) are applied sequentially by sort order. Subsequent workflow actions will
|
||||
override assignments from a preceeding workflow except for assignments that accept multiple items e.g. tags, custom fields and
|
||||
permissions will be merged.
|
||||
|
||||
Workflows allow you to filter by:
|
||||
|
||||
|
@ -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"):
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
)
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user