fixed expenses workflow

This commit is contained in:
ValueOn AG 2026-05-19 22:14:00 +02:00
parent a173fab15f
commit 09c6d33dec
2 changed files with 27 additions and 21 deletions

View file

@ -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."""

View file

@ -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