diff --git a/docs/usage.md b/docs/usage.md index 66b548a2f..b8c6dce32 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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: diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 2c50aebd6..d9ed45144 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -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"): diff --git a/src/documents/data_models.py b/src/documents/data_models.py index 0d506cd6a..6bf3f4f96 100644 --- a/src/documents/data_models.py +++ b/src/documents/data_models.py @@ -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 diff --git a/src/documents/tasks.py b/src/documents/tasks.py index 2b1449737..5b042bd1e 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -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, ) diff --git a/src/documents/tests/test_workflows.py b/src/documents/tests/test_workflows.py index 293937fb3..db30411e9 100644 --- a/src/documents/tests/test_workflows.py +++ b/src/documents/tests/test_workflows.py @@ -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(