From 8db2c8ee9620248da3ca6b274d2c92d0b89f4311 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 10 Aug 2026 14:07:32 -0700 Subject: [PATCH] Model and migration --- ...024_workflowaction_apply_ai_suggestions.py | 59 +++++++++++++++++++ src/documents/models.py | 39 ++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/documents/migrations/0024_workflowaction_apply_ai_suggestions.py diff --git a/src/documents/migrations/0024_workflowaction_apply_ai_suggestions.py b/src/documents/migrations/0024_workflowaction_apply_ai_suggestions.py new file mode 100644 index 000000000..61cb0485d --- /dev/null +++ b/src/documents/migrations/0024_workflowaction_apply_ai_suggestions.py @@ -0,0 +1,59 @@ +# Generated by Django 5.2.16 on 2026-08-10 18:26 + +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + dependencies = [ + ("documents", "0024_alter_workflowaction_type"), + ] + + operations = [ + migrations.AddField( + model_name="workflowaction", + name="ai_create_missing", + field=models.BooleanField( + default=False, + help_text="Create suggested tags, correspondents, document types and storage paths that do not already exist instead of skipping them.", + verbose_name="create missing objects", + ), + ), + migrations.AddField( + model_name="workflowaction", + name="ai_overwrite_existing", + field=models.BooleanField( + default=False, + help_text="Apply suggestions even if the document already has a value for that field. Tags are always added to, never replaced.", + verbose_name="overwrite existing values", + ), + ), + migrations.AddField( + model_name="workflowaction", + name="ai_suggestion_fields", + field=models.JSONField( + blank=True, + help_text="Which of the AI-suggested fields to apply to the document.", + null=True, + verbose_name="AI suggestion fields", + ), + ), + migrations.AlterField( + model_name="workflowaction", + name="type", + field=models.PositiveSmallIntegerField( + choices=[ + (1, "Assignment"), + (2, "Removal"), + (3, "Email"), + (4, "Webhook"), + (5, "Password removal"), + (6, "Move to trash"), + (7, "Remote OCR"), + (8, "Apply AI suggestions"), + ], + default=1, + verbose_name="Workflow Action Type", + ), + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index bb4c1e7b0..cbf583d4c 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -1672,6 +1672,18 @@ class WorkflowAction(models.Model): 7, _("Remote OCR"), ) + APPLY_AI_SUGGESTIONS = ( + 8, + _("Apply AI suggestions"), + ) + + class AISuggestionField(models.TextChoices): + TITLE = ("title", _("Title")) + TAGS = ("tags", _("Tags")) + CORRESPONDENT = ("correspondent", _("Correspondent")) + DOCUMENT_TYPE = ("document_type", _("Document type")) + STORAGE_PATH = ("storage_path", _("Storage path")) + CREATED = ("created", _("Created date")) type = models.PositiveSmallIntegerField( _("Workflow Action Type"), @@ -1910,6 +1922,33 @@ class WorkflowAction(models.Model): ), ) + ai_suggestion_fields = models.JSONField( + _("AI suggestion fields"), + null=True, + blank=True, + help_text=_( + "Which of the AI-suggested fields to apply to the document.", + ), + ) + + ai_create_missing = models.BooleanField( + _("create missing objects"), + default=False, + help_text=_( + "Create suggested tags, correspondents, document types and storage " + "paths that do not already exist instead of skipping them.", + ), + ) + + ai_overwrite_existing = models.BooleanField( + _("overwrite existing values"), + default=False, + help_text=_( + "Apply suggestions even if the document already has a value for that " + "field. Tags are always added to, never replaced.", + ), + ) + class Meta: verbose_name = _("workflow action") verbose_name_plural = _("workflow actions")