Implement trigger filter by tag, correspondent and doctype

This commit is contained in:
shamoon 2023-12-26 00:06:10 -08:00
parent 84199a6894
commit 264d9f97fc
7 changed files with 105 additions and 2 deletions

View File

@ -38,11 +38,14 @@
<div class="col-md-6"> <div class="col-md-6">
<pngx-input-select i18n-title title="Filter sources" [items]="sourceOptions" [multiple]="true" formControlName="sources" [error]="error?.sources"></pngx-input-select> <pngx-input-select i18n-title title="Filter sources" [items]="sourceOptions" [multiple]="true" formControlName="sources" [error]="error?.sources"></pngx-input-select>
<pngx-input-text i18n-title title="Filter filename" formControlName="filter_filename" i18n-hint hint="Apply to documents that match this filename. Wildcards such as *.pdf or *invoice* are allowed. Case insensitive." [error]="error?.filter_filename"></pngx-input-text> <pngx-input-text i18n-title title="Filter filename" formControlName="filter_filename" i18n-hint hint="Apply to documents that match this filename. Wildcards such as *.pdf or *invoice* are allowed. Case insensitive." [error]="error?.filter_filename"></pngx-input-text>
</div>
<div class="col-md-6">
<pngx-input-text i18n-title title="Filter path" formControlName="filter_path" i18n-hint hint="Apply to documents that match this path. Wildcards specified as * are allowed. Case insensitive.</a>" [error]="error?.filter_path"></pngx-input-text> <pngx-input-text i18n-title title="Filter path" formControlName="filter_path" i18n-hint hint="Apply to documents that match this path. Wildcards specified as * are allowed. Case insensitive.</a>" [error]="error?.filter_path"></pngx-input-text>
<pngx-input-select i18n-title title="Filter mail rule" [items]="mailRules" [allowNull]="true" formControlName="filter_mailrule" i18n-hint hint="Apply to documents consumed via this mail rule." [error]="error?.filter_mailrule"></pngx-input-select> <pngx-input-select i18n-title title="Filter mail rule" [items]="mailRules" [allowNull]="true" formControlName="filter_mailrule" i18n-hint hint="Apply to documents consumed via this mail rule." [error]="error?.filter_mailrule"></pngx-input-select>
</div> </div>
<div class="col-md-6">
<pngx-input-tags [allowCreate]="false" i18n-title title="Has tags" formControlName="filter_has_tags"></pngx-input-tags>
<pngx-input-select i18n-title title="Has correspondent" [items]="correspondents" [allowNull]="true" formControlName="filter_has_correspondent"></pngx-input-select>
<pngx-input-select i18n-title title="Has document type" [items]="documentTypes" [allowNull]="true" formControlName="filter_has_document_type"></pngx-input-select>
</div>
</div> </div>
</div> </div>

View File

@ -150,6 +150,13 @@ export class WorkflowEditDialogComponent
filter_filename: new FormControl(trigger.filter_filename), filter_filename: new FormControl(trigger.filter_filename),
filter_path: new FormControl(trigger.filter_path), filter_path: new FormControl(trigger.filter_path),
filter_mailrule: new FormControl(trigger.filter_mailrule), filter_mailrule: new FormControl(trigger.filter_mailrule),
filter_has_tags: new FormControl(trigger.filter_has_tags),
filter_has_correspondent: new FormControl(
trigger.filter_has_correspondent
),
filter_has_document_type: new FormControl(
trigger.filter_has_document_type
),
}), }),
{ emitEvent } { emitEvent }
) )

View File

@ -22,4 +22,10 @@ export interface WorkflowTrigger extends ObjectWithId {
filter_path?: string filter_path?: string
filter_mailrule?: number // MailRule.id filter_mailrule?: number // MailRule.id
filter_has_tags?: number[] // Tag.id[]
filter_has_correspondent?: number // Correspondent.id
filter_has_document_type?: number // DocumentType.id
} }

View File

@ -311,6 +311,40 @@ def document_matches_workflow(
elif trigger_type is WorkflowTrigger.WorkflowTriggerType.DOCUMENT_ADDED: elif trigger_type is WorkflowTrigger.WorkflowTriggerType.DOCUMENT_ADDED:
# document is type Document # 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 # Document filename vs template filename
if ( if (
trigger.filter_filename is not None trigger.filter_filename is not None

View File

@ -395,6 +395,34 @@ class Migration(migrations.Migration):
verbose_name="filter documents from this mail rule", 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={ options={
"verbose_name": "workflow trigger", "verbose_name": "workflow trigger",

View File

@ -943,6 +943,28 @@ class WorkflowTrigger(models.Model):
verbose_name=_("filter documents from this mail rule"), 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: class Meta:
verbose_name = _("workflow trigger") verbose_name = _("workflow trigger")
verbose_name_plural = _("workflow triggers") verbose_name_plural = _("workflow triggers")

View File

@ -1287,6 +1287,9 @@ class WorkflowTriggerSerializer(serializers.ModelSerializer):
"filter_path", "filter_path",
"filter_filename", "filter_filename",
"filter_mailrule", "filter_mailrule",
"filter_has_tags",
"filter_has_correspondent",
"filter_has_document_type",
] ]
def validate(self, attrs): def validate(self, attrs):