Skip to content

Commit

Permalink
minor bug fixes (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur authored Oct 16, 2024
1 parent 351c59c commit 8b9ae52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions papermerge/core/db/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from papermerge.core.constants import INCOMING_DATE_FORMAT
from papermerge.core.db.models import (
ColoredTag,
CustomField,
CustomFieldValue,
Document,
DocumentVersion,
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
}
})
Expand Down

0 comments on commit 8b9ae52

Please sign in to comment.