fix: Update metadata synchronization logic to always sync changes and correct field mappings

This commit is contained in:
bsiggel
2026-03-25 21:34:18 +00:00
parent 1ffc37b0b7
commit 50c5070894
2 changed files with 27 additions and 15 deletions

View File

@@ -289,7 +289,8 @@ class AdvowareDocumentSyncUtils:
""" """
Check if metadata needs update in EspoCRM. Check if metadata needs update in EspoCRM.
Compares History metadata (text, art, dat) with EspoCRM fields. Compares History metadata (text, art, hNr) with EspoCRM fields.
Always syncs metadata changes even if file content hasn't changed.
Args: Args:
espo_doc: Document from EspoCRM espo_doc: Document from EspoCRM
@@ -300,24 +301,28 @@ class AdvowareDocumentSyncUtils:
""" """
updates = {} updates = {}
# Map History fields to EspoCRM fields # Map History fields to correct EspoCRM field names
history_text = advo_history.get('text', '') history_text = advo_history.get('text', '')
history_art = advo_history.get('art', '') history_art = advo_history.get('art', '')
history_dat = advo_history.get('dat', '') history_hnr = advo_history.get('hNr')
espo_description = espo_doc.get('description', '') espo_bemerkung = espo_doc.get('advowareBemerkung', '')
espo_type = espo_doc.get('type', '') espo_art = espo_doc.get('advowareArt', '')
espo_date = espo_doc.get('dateUploaded', '') espo_hnr = espo_doc.get('hnr')
# Check if different # Check if different - sync metadata independently of file changes
if history_text and history_text != espo_description: if history_text != espo_bemerkung:
updates['description'] = history_text updates['advowareBemerkung'] = history_text
if history_art and history_art != espo_type: if history_art != espo_art:
updates['type'] = history_art updates['advowareArt'] = history_art
if history_dat and history_dat != espo_date: if history_hnr is not None and history_hnr != espo_hnr:
updates['dateUploaded'] = history_dat updates['hnr'] = history_hnr
# Always update lastSyncTimestamp when metadata changes
if len(updates) > 0:
updates['lastSyncTimestamp'] = datetime.now().isoformat()
needs_update = len(updates) > 0 needs_update = len(updates) > 0

View File

@@ -240,6 +240,9 @@ async def handler(event_data: Dict[str, Any], ctx: FlowContext) -> None:
# Extract full Windows path from watcher data # Extract full Windows path from watcher data
full_path = windows_file.get('path', '') full_path = windows_file.get('path', '')
# Current timestamp for sync tracking
now_iso = datetime.now().isoformat()
new_doc = await espocrm.create_entity('CDokumente', { new_doc = await espocrm.create_entity('CDokumente', {
'name': filename, 'name': filename,
'dokumentId': attachment.get('id'), # Link to attachment 'dokumentId': attachment.get('id'), # Link to attachment
@@ -252,7 +255,8 @@ async def handler(event_data: Dict[str, Any], ctx: FlowContext) -> None:
'blake3hash': blake3_hash, 'blake3hash': blake3_hash,
'syncedHash': blake3_hash, 'syncedHash': blake3_hash,
'usn': windows_file.get('usn', 0), 'usn': windows_file.get('usn', 0),
'syncStatus': 'synced' 'syncStatus': 'synced',
'lastSyncTimestamp': now_iso
}) })
doc_id = new_doc.get('id') doc_id = new_doc.get('id')
@@ -281,12 +285,15 @@ async def handler(event_data: Dict[str, Any], ctx: FlowContext) -> None:
# Update document in EspoCRM with correct field names # Update document in EspoCRM with correct field names
ctx.logger.info(f"💾 Updating document in EspoCRM...") ctx.logger.info(f"💾 Updating document in EspoCRM...")
now_iso = datetime.now().isoformat()
update_data = { update_data = {
'blake3hash': blake3_hash, 'blake3hash': blake3_hash,
'syncedHash': blake3_hash, 'syncedHash': blake3_hash,
'usn': windows_file.get('usn', 0), 'usn': windows_file.get('usn', 0),
'dateipfad': full_path, 'dateipfad': full_path,
'syncStatus': 'synced' 'syncStatus': 'synced',
'lastSyncTimestamp': now_iso
} }
# Also update History fields if available # Also update History fields if available