From 09c6d33deca58e715c8e6256a2c9ed0021eee44d Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Tue, 19 May 2026 22:14:00 +0200
Subject: [PATCH] fixed expenses workflow
---
.../mainServiceSharepoint.py | 27 +++++++------------
.../methodTrustee/actions/processDocuments.py | 21 ++++++++++++---
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/modules/serviceCenter/services/serviceSharepoint/mainServiceSharepoint.py b/modules/serviceCenter/services/serviceSharepoint/mainServiceSharepoint.py
index 483d7fbe..4fd1fb36 100644
--- a/modules/serviceCenter/services/serviceSharepoint/mainServiceSharepoint.py
+++ b/modules/serviceCenter/services/serviceSharepoint/mainServiceSharepoint.py
@@ -327,27 +327,20 @@ class SharepointService:
return None
async def uploadFile(self, siteId: str, folderPath: str, fileName: str, content: bytes) -> Dict[str, Any]:
- """Upload a file to SharePoint."""
- try:
- # Clean the path
- cleanPath = folderPath.lstrip('/')
- uploadPath = f"{cleanPath.rstrip('/')}/{fileName}"
- endpoint = f"sites/{siteId}/drive/root:/{uploadPath}:/content"
+ """Upload a file to SharePoint. Raises on failure."""
+ cleanPath = folderPath.lstrip('/')
+ uploadPath = f"{cleanPath.rstrip('/')}/{fileName}"
+ endpoint = f"sites/{siteId}/drive/root:/{uploadPath}:/content"
- logger.info(f"Uploading file to: {endpoint}")
+ logger.info(f"Uploading file to: {endpoint}")
- result = await self._makeGraphApiCall(endpoint, method="PUT", data=content)
+ result = await self._makeGraphApiCall(endpoint, method="PUT", data=content)
- if "error" in result:
- logger.error(f"Upload failed: {result['error']}")
- return result
+ if "error" in result:
+ raise Exception(f"Upload failed: {result['error']}")
- logger.info(f"File uploaded successfully: {fileName}")
- return result
-
- except Exception as e:
- logger.error(f"Error uploading file: {str(e)}")
- return {"error": f"Error uploading file: {str(e)}"}
+ logger.info(f"File uploaded successfully: {fileName}")
+ return result
async def downloadFile(self, siteId: str, fileId: str) -> Optional[bytes]:
"""Download a file from SharePoint."""
diff --git a/modules/workflows/methods/methodTrustee/actions/processDocuments.py b/modules/workflows/methods/methodTrustee/actions/processDocuments.py
index b05e25f4..29d5ab13 100644
--- a/modules/workflows/methods/methodTrustee/actions/processDocuments.py
+++ b/modules/workflows/methods/methodTrustee/actions/processDocuments.py
@@ -247,16 +247,29 @@ def _resolveDocumentList(documentListParam, services) -> List[tuple]:
if isinstance(first, dict) and ("documentData" in first or "documentName" in first):
for doc in documentListParam:
rawData = doc.get("documentData")
- logger.debug("_resolveDocumentList: doc keys=%s documentData type=%s documentData truthy=%s", list(doc.keys()), type(rawData).__name__, bool(rawData))
+ fileId = (doc.get("validationMetadata") or {}).get("fileId") or doc.get("fileId", "")
+ fileName = doc.get("documentName") or doc.get("fileName") or "document"
+ mimeType = doc.get("mimeType") or doc.get("documentMimeType") or "application/json"
+
+ # When documentData was persisted as binary (_hasBinaryData), read it
+ # back from file storage via the chat service.
+ if not rawData and doc.get("_hasBinaryData") and fileId:
+ chatService = getattr(services, "chat", None)
+ if chatService:
+ try:
+ rawBytes = chatService.getFileData(fileId)
+ if rawBytes:
+ rawData = rawBytes.decode("utf-8") if isinstance(rawBytes, bytes) else rawBytes
+ except Exception as e:
+ logger.debug("_resolveDocumentList: failed to read binary for fileId=%s: %s", fileId, e)
+
+ logger.debug("_resolveDocumentList: doc keys=%s documentData type=%s documentData truthy=%s", list(doc.keys()), type(rawData).__name__ if rawData else "NoneType", bool(rawData))
if not rawData:
continue
try:
data = json.loads(rawData) if isinstance(rawData, str) else rawData
except (json.JSONDecodeError, TypeError):
continue
- fileId = (doc.get("validationMetadata") or {}).get("fileId") or doc.get("fileId", "")
- fileName = doc.get("documentName") or doc.get("fileName") or "document"
- mimeType = doc.get("mimeType") or doc.get("documentMimeType") or "application/json"
results.append((data, fileId, fileName, mimeType))
if results:
return results