Add option to skip inbox tags in consumption templates
This commit is contained in:
parent
05e294fc81
commit
9e50b43b0b
@ -32,6 +32,7 @@
|
||||
<div class="col">
|
||||
<pngx-input-text i18n-title title="Assign title" formControlName="assign_title" i18n-hint hint="Can include some placeholders, see <a target='_blank' href='https://docs.paperless-ngx.com/usage/#consumption-templates'>documentation</a>." [error]="error?.assign_title"></pngx-input-text>
|
||||
<pngx-input-tags [allowCreate]="false" i18n-title title="Assign tags" formControlName="assign_tags"></pngx-input-tags>
|
||||
<pngx-input-check i18n-title title="Skip assigning inbox tag(s)" formControlName="skip_inbox"></pngx-input-check>
|
||||
<pngx-input-select i18n-title title="Assign document type" [items]="documentTypes" [allowNull]="true" formControlName="assign_document_type"></pngx-input-select>
|
||||
<pngx-input-select i18n-title title="Assign correspondent" [items]="correspondents" [allowNull]="true" formControlName="assign_correspondent"></pngx-input-select>
|
||||
<pngx-input-select i18n-title title="Assign storage path" [items]="storagePaths" [allowNull]="true" formControlName="assign_storage_path"></pngx-input-select>
|
||||
|
@ -107,6 +107,7 @@ export class ConsumptionTemplateEditDialogComponent extends EditDialogComponent<
|
||||
sources: new FormControl([]),
|
||||
assign_title: new FormControl(null),
|
||||
assign_tags: new FormControl([]),
|
||||
skip_inbox: new FormControl(false),
|
||||
assign_owner: new FormControl(null),
|
||||
assign_document_type: new FormControl(null),
|
||||
assign_correspondent: new FormControl(null),
|
||||
|
@ -327,6 +327,7 @@ class Consumer(LoggingMixin):
|
||||
override_correspondent_id=None,
|
||||
override_document_type_id=None,
|
||||
override_tag_ids=None,
|
||||
override_skip_inbox=False,
|
||||
override_storage_path_id=None,
|
||||
task_id=None,
|
||||
override_created=None,
|
||||
@ -348,6 +349,7 @@ class Consumer(LoggingMixin):
|
||||
self.override_correspondent_id = override_correspondent_id
|
||||
self.override_document_type_id = override_document_type_id
|
||||
self.override_tag_ids = override_tag_ids
|
||||
self.override_skip_inbox = override_skip_inbox
|
||||
self.override_storage_path_id = override_storage_path_id
|
||||
self.task_id = task_id or str(uuid.uuid4())
|
||||
self.override_created = override_created
|
||||
@ -516,6 +518,7 @@ class Consumer(LoggingMixin):
|
||||
document=document,
|
||||
logging_group=self.logging_group,
|
||||
classifier=classifier,
|
||||
skip_inbox=self.override_skip_inbox,
|
||||
)
|
||||
|
||||
# After everything is in the database, copy the files into
|
||||
@ -621,6 +624,8 @@ class Consumer(LoggingMixin):
|
||||
template_overrides.tag_ids = [
|
||||
tag.pk for tag in template.assign_tags.all()
|
||||
]
|
||||
if template.skip_inbox:
|
||||
template_overrides.skip_inbox = True
|
||||
if template.assign_correspondent is not None:
|
||||
template_overrides.correspondent_id = (
|
||||
template.assign_correspondent.pk
|
||||
|
@ -20,6 +20,7 @@ class DocumentMetadataOverrides:
|
||||
correspondent_id: Optional[int] = None
|
||||
document_type_id: Optional[int] = None
|
||||
tag_ids: Optional[list[int]] = None
|
||||
skip_inbox: bool = False
|
||||
storage_path_id: Optional[int] = None
|
||||
created: Optional[datetime.datetime] = None
|
||||
asn: Optional[int] = None
|
||||
@ -57,6 +58,8 @@ class DocumentMetadataOverrides:
|
||||
self.tag_ids.extend(other.tag_ids)
|
||||
self.tag_ids = list(set(self.tag_ids))
|
||||
|
||||
self.skip_inbox = self.skip_inbox or other.skip_inbox
|
||||
|
||||
if self.view_users is None:
|
||||
self.view_users = other.view_users
|
||||
elif other.view_users is not None:
|
||||
|
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.8 on 2023-12-29 15:22
|
||||
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("documents", "1043_alter_savedviewfilterrule_rule_type"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="consumptiontemplate",
|
||||
name="skip_inbox",
|
||||
field=models.BooleanField(
|
||||
default=False,
|
||||
verbose_name="Skip assigning inbox tag(s)",
|
||||
),
|
||||
),
|
||||
]
|
@ -953,6 +953,11 @@ class ConsumptionTemplate(models.Model):
|
||||
verbose_name=_("assign this tag"),
|
||||
)
|
||||
|
||||
skip_inbox = models.BooleanField(
|
||||
_("Skip assigning inbox tag(s)"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
assign_document_type = models.ForeignKey(
|
||||
DocumentType,
|
||||
null=True,
|
||||
|
@ -1286,6 +1286,7 @@ class ConsumptionTemplateSerializer(serializers.ModelSerializer):
|
||||
"filter_mailrule",
|
||||
"assign_title",
|
||||
"assign_tags",
|
||||
"skip_inbox",
|
||||
"assign_correspondent",
|
||||
"assign_document_type",
|
||||
"assign_storage_path",
|
||||
|
@ -36,7 +36,16 @@ from documents.permissions import get_objects_for_user_owner_aware
|
||||
logger = logging.getLogger("paperless.handlers")
|
||||
|
||||
|
||||
def add_inbox_tags(sender, document: Document, logging_group=None, **kwargs):
|
||||
def add_inbox_tags(
|
||||
sender,
|
||||
document: Document,
|
||||
logging_group=None,
|
||||
skip_inbox=False,
|
||||
**kwargs,
|
||||
):
|
||||
if skip_inbox:
|
||||
return
|
||||
|
||||
if document.owner is not None:
|
||||
tags = get_objects_for_user_owner_aware(
|
||||
document.owner,
|
||||
|
@ -171,6 +171,7 @@ def consume_file(
|
||||
override_correspondent_id=overrides.correspondent_id,
|
||||
override_document_type_id=overrides.document_type_id,
|
||||
override_tag_ids=overrides.tag_ids,
|
||||
override_skip_inbox=overrides.skip_inbox,
|
||||
override_storage_path_id=overrides.storage_path_id,
|
||||
override_created=overrides.created,
|
||||
override_asn=overrides.asn,
|
||||
|
@ -227,6 +227,7 @@ class TestConsumptionTemplates(DirectoriesMixin, FileSystemAssertsMixin, TestCas
|
||||
order=0,
|
||||
sources=f"{DocumentSource.ApiUpload},{DocumentSource.ConsumeFolder},{DocumentSource.MailFetch}",
|
||||
filter_path="*/samples/*",
|
||||
skip_inbox=True,
|
||||
assign_title="Doc from {correspondent}",
|
||||
assign_correspondent=self.c,
|
||||
assign_document_type=self.dt,
|
||||
@ -240,6 +241,7 @@ class TestConsumptionTemplates(DirectoriesMixin, FileSystemAssertsMixin, TestCas
|
||||
order=0,
|
||||
sources=f"{DocumentSource.ApiUpload},{DocumentSource.ConsumeFolder},{DocumentSource.MailFetch}",
|
||||
filter_filename="*simple*",
|
||||
skip_inbox=False,
|
||||
assign_title="Doc from {correspondent}",
|
||||
assign_correspondent=self.c2,
|
||||
assign_storage_path=self.sp,
|
||||
@ -275,6 +277,7 @@ class TestConsumptionTemplates(DirectoriesMixin, FileSystemAssertsMixin, TestCas
|
||||
overrides["override_view_users"],
|
||||
[self.user2.pk, self.user3.pk],
|
||||
)
|
||||
self.assertTrue(overrides["override_skip_inbox"])
|
||||
|
||||
expected_str = f"Document matched template {ct1}"
|
||||
self.assertIn(expected_str, cm.output[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user