From 40d650302b75b2fdd525f16bb012f6c9e9f24ae8 Mon Sep 17 00:00:00 2001 From: Eugen Ciur Date: Wed, 16 Oct 2024 09:35:52 +0200 Subject: [PATCH] minor bug fixes --- papermerge/core/db/doc.py | 17 ++++++++++++++--- .../components/DocumentDetails/CustomFields.tsx | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/papermerge/core/db/doc.py b/papermerge/core/db/doc.py index c302c1e7d..7abcdd409 100644 --- a/papermerge/core/db/doc.py +++ b/papermerge/core/db/doc.py @@ -11,6 +11,7 @@ from papermerge.core.constants import INCOMING_DATE_FORMAT from papermerge.core.db.models import ( ColoredTag, + CustomField, CustomFieldValue, Document, DocumentVersion, @@ -185,18 +186,28 @@ def update_doc_type(session: Session, document_id: UUID, document_type_id: UUID def update_doc_cfv( session: Session, document_id: UUID, - custom_fields: dict, # if of the document + custom_fields: dict, ) -> list[schemas.CFV]: - """ """ + """ + Update document's custom field values + """ items = get_doc_cfv(session, document_id=document_id) insert_values = [] update_values = [] + stmt = ( + select(CustomField.name) + .select_from(CustomFieldValue) + .join(CustomField) + .where(CustomFieldValue.document_id == document_id) + ) + existing_cf_name = [row[0] for row in session.execute(stmt).all()] + for item in items: if item.name not in custom_fields.keys(): continue - if item.value is None: + if item.name not in existing_cf_name: # prepare insert values v = dict( id=uuid.uuid4(), diff --git a/ui2/src/features/document/components/DocumentDetails/CustomFields.tsx b/ui2/src/features/document/components/DocumentDetails/CustomFields.tsx index 78654fa93..9d9271e8f 100644 --- a/ui2/src/features/document/components/DocumentDetails/CustomFields.tsx +++ b/ui2/src/features/document/components/DocumentDetails/CustomFields.tsx @@ -64,6 +64,7 @@ export default function CustomFields() { document_type_id: documentTypeID?.value!, type: i.type, name: i.name, + extra_data: i.extra_data, value: "" } })