Implement trigger filter by tag, correspondent and doctype
This commit is contained in:
@@ -311,6 +311,40 @@ def document_matches_workflow(
|
||||
elif trigger_type is WorkflowTrigger.WorkflowTriggerType.DOCUMENT_ADDED:
|
||||
# document is type Document
|
||||
|
||||
# Document has_tags vs document tags
|
||||
if (
|
||||
trigger.filter_has_tags.all().count() > 0
|
||||
and document.tags.filter(
|
||||
id__in=trigger.filter_has_tags.all().values_list("id"),
|
||||
).count()
|
||||
== 0
|
||||
):
|
||||
log_match_failure(
|
||||
f"Document tags {document.tags} do not include"
|
||||
f" {trigger.filter_has_tags}",
|
||||
)
|
||||
trigger_matched = False
|
||||
|
||||
# Document has_correspondent vs document correpondent
|
||||
if (
|
||||
trigger.filter_has_correspondent is not None
|
||||
and document.correspondent != trigger.filter_has_correspondent
|
||||
):
|
||||
log_match_failure(
|
||||
f"Document correspondent {document.correspondent} does not match {trigger.filter_has_correspondent}",
|
||||
)
|
||||
trigger_matched = False
|
||||
|
||||
# Document has_correspondent vs document correpondent
|
||||
if (
|
||||
trigger.filter_has_document_type is not None
|
||||
and document.document_type != trigger.filter_has_document_type
|
||||
):
|
||||
log_match_failure(
|
||||
f"Document doc type {document.document_type} does not match {trigger.filter_has_document_type}",
|
||||
)
|
||||
trigger_matched = False
|
||||
|
||||
# Document filename vs template filename
|
||||
if (
|
||||
trigger.filter_filename is not None
|
||||
|
||||
@@ -395,6 +395,34 @@ class Migration(migrations.Migration):
|
||||
verbose_name="filter documents from this mail rule",
|
||||
),
|
||||
),
|
||||
(
|
||||
"filter_has_tags",
|
||||
models.ManyToManyField(
|
||||
blank=True,
|
||||
to="documents.tag",
|
||||
verbose_name="has these tag(s)",
|
||||
),
|
||||
),
|
||||
(
|
||||
"filter_has_correspondent",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="documents.documenttype",
|
||||
verbose_name="has this document type",
|
||||
),
|
||||
),
|
||||
(
|
||||
"filter_has_document_type",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="documents.correspondent",
|
||||
verbose_name="has this correspondent",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "workflow trigger",
|
||||
|
||||
@@ -943,6 +943,28 @@ class WorkflowTrigger(models.Model):
|
||||
verbose_name=_("filter documents from this mail rule"),
|
||||
)
|
||||
|
||||
filter_has_tags = models.ManyToManyField(
|
||||
Tag,
|
||||
blank=True,
|
||||
verbose_name=_("has these tag(s)"),
|
||||
)
|
||||
|
||||
filter_has_correspondent = models.ForeignKey(
|
||||
DocumentType,
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
verbose_name=_("has this document type"),
|
||||
)
|
||||
|
||||
filter_has_document_type = models.ForeignKey(
|
||||
Correspondent,
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
verbose_name=_("has this correspondent"),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("workflow trigger")
|
||||
verbose_name_plural = _("workflow triggers")
|
||||
|
||||
@@ -1287,6 +1287,9 @@ class WorkflowTriggerSerializer(serializers.ModelSerializer):
|
||||
"filter_path",
|
||||
"filter_filename",
|
||||
"filter_mailrule",
|
||||
"filter_has_tags",
|
||||
"filter_has_correspondent",
|
||||
"filter_has_document_type",
|
||||
]
|
||||
|
||||
def validate(self, attrs):
|
||||
|
||||
Reference in New Issue
Block a user