feat(sync): Enhance metadata synchronization for unchanged files in Advoware sync process
This commit is contained in:
@@ -312,14 +312,12 @@ class AdvowareDocumentSyncUtils:
|
|||||||
"""
|
"""
|
||||||
updates = {}
|
updates = {}
|
||||||
|
|
||||||
# Map History fields to correct EspoCRM field names
|
# Map History metadata fields to 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_hnr = advo_history.get('hNr')
|
|
||||||
|
|
||||||
espo_bemerkung = espo_doc.get('advowareBemerkung', '')
|
espo_bemerkung = espo_doc.get('advowareBemerkung', '')
|
||||||
espo_art = espo_doc.get('advowareArt', '')
|
espo_art = espo_doc.get('advowareArt', '')
|
||||||
espo_hnr = espo_doc.get('hnr')
|
|
||||||
|
|
||||||
# Check if different - sync metadata independently of file changes
|
# Check if different - sync metadata independently of file changes
|
||||||
if history_text != espo_bemerkung:
|
if history_text != espo_bemerkung:
|
||||||
@@ -328,8 +326,12 @@ class AdvowareDocumentSyncUtils:
|
|||||||
if history_art != espo_art:
|
if history_art != espo_art:
|
||||||
updates['advowareArt'] = history_art
|
updates['advowareArt'] = history_art
|
||||||
|
|
||||||
if history_hnr is not None and history_hnr != espo_hnr:
|
# Sync dat (creation date from Advoware History) → advowareErstellungTimestamp
|
||||||
updates['hnr'] = history_hnr
|
history_dat_raw = advo_history.get('dat') or ''
|
||||||
|
history_erstellung = history_dat_raw.replace('T', ' ')[:19] if history_dat_raw else ''
|
||||||
|
espo_erstellung = espo_doc.get('advowareErstellungTimestamp') or ''
|
||||||
|
if history_erstellung and history_erstellung != espo_erstellung:
|
||||||
|
updates['advowareErstellungTimestamp'] = history_erstellung
|
||||||
|
|
||||||
# Always update lastSyncTimestamp when metadata changes (EspoCRM format)
|
# Always update lastSyncTimestamp when metadata changes (EspoCRM format)
|
||||||
if len(updates) > 0:
|
if len(updates) > 0:
|
||||||
|
|||||||
@@ -247,6 +247,16 @@ async def _run_advoware_sync(
|
|||||||
ctx.logger.info(f" [{action.action:12s}] {filename} (hnr={hnr}) – {action.reason}")
|
ctx.logger.info(f" [{action.action:12s}] {filename} (hnr={hnr}) – {action.reason}")
|
||||||
|
|
||||||
if action.action == 'SKIP':
|
if action.action == 'SKIP':
|
||||||
|
# Even for unchanged files: sync metadata from History (art, text, hnr, dat)
|
||||||
|
if espo_doc and history_entry:
|
||||||
|
needs_meta_update, meta_updates = sync_utils.should_sync_metadata(espo_doc, history_entry)
|
||||||
|
if needs_meta_update:
|
||||||
|
await espocrm.update_entity('CDokumente', espo_doc['id'], meta_updates)
|
||||||
|
ctx.logger.info(f" [META UPDATE ] {filename} (hnr={hnr}) – {list(meta_updates.keys())}")
|
||||||
|
results['updated'] += 1
|
||||||
|
else:
|
||||||
|
results['skipped'] += 1
|
||||||
|
else:
|
||||||
results['skipped'] += 1
|
results['skipped'] += 1
|
||||||
|
|
||||||
elif action.action == 'CREATE':
|
elif action.action == 'CREATE':
|
||||||
@@ -274,6 +284,7 @@ async def _run_advoware_sync(
|
|||||||
'hnr': history_entry.get('hNr') if history_entry else None,
|
'hnr': history_entry.get('hNr') if history_entry else None,
|
||||||
'advowareArt': (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100] if history_entry else 'Schreiben',
|
'advowareArt': (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100] if history_entry else 'Schreiben',
|
||||||
'advowareBemerkung': (history_entry.get('text', '') or '')[:255] if history_entry else '',
|
'advowareBemerkung': (history_entry.get('text', '') or '')[:255] if history_entry else '',
|
||||||
|
'advowareErstellungTimestamp': ((history_entry.get('dat') or '').replace('T', ' ')[:19] or None) if history_entry else None,
|
||||||
'dateipfad': windows_file.get('path', ''),
|
'dateipfad': windows_file.get('path', ''),
|
||||||
'blake3hash': blake3_hash,
|
'blake3hash': blake3_hash,
|
||||||
'syncedHash': blake3_hash,
|
'syncedHash': blake3_hash,
|
||||||
@@ -322,6 +333,9 @@ async def _run_advoware_sync(
|
|||||||
update_data['hnr'] = history_entry.get('hNr')
|
update_data['hnr'] = history_entry.get('hNr')
|
||||||
update_data['advowareArt'] = (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100]
|
update_data['advowareArt'] = (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100]
|
||||||
update_data['advowareBemerkung'] = (history_entry.get('text', '') or '')[:255]
|
update_data['advowareBemerkung'] = (history_entry.get('text', '') or '')[:255]
|
||||||
|
erstellung_dat = (history_entry.get('dat') or '').replace('T', ' ')[:19]
|
||||||
|
if erstellung_dat:
|
||||||
|
update_data['advowareErstellungTimestamp'] = erstellung_dat
|
||||||
|
|
||||||
await espocrm.update_entity('CDokumente', espo_doc['id'], update_data)
|
await espocrm.update_entity('CDokumente', espo_doc['id'], update_data)
|
||||||
results['updated'] += 1
|
results['updated'] += 1
|
||||||
|
|||||||
@@ -264,6 +264,16 @@ async def _run_advoware_sync(
|
|||||||
ctx.logger.info(f" [{action.action:12s}] {filename} (hnr={hnr}) – {action.reason}")
|
ctx.logger.info(f" [{action.action:12s}] {filename} (hnr={hnr}) – {action.reason}")
|
||||||
|
|
||||||
if action.action == 'SKIP':
|
if action.action == 'SKIP':
|
||||||
|
# Even for unchanged files: sync metadata from History (art, text, hnr, dat)
|
||||||
|
if espo_doc and history_entry:
|
||||||
|
needs_meta_update, meta_updates = sync_utils.should_sync_metadata(espo_doc, history_entry)
|
||||||
|
if needs_meta_update:
|
||||||
|
await espocrm.update_entity('CDokumente', espo_doc['id'], meta_updates)
|
||||||
|
ctx.logger.info(f" [META UPDATE ] {filename} (hnr={hnr}) – {list(meta_updates.keys())}")
|
||||||
|
results['updated'] += 1
|
||||||
|
else:
|
||||||
|
results['skipped'] += 1
|
||||||
|
else:
|
||||||
results['skipped'] += 1
|
results['skipped'] += 1
|
||||||
|
|
||||||
elif action.action == 'CREATE':
|
elif action.action == 'CREATE':
|
||||||
@@ -290,6 +300,7 @@ async def _run_advoware_sync(
|
|||||||
'hnr': history_entry.get('hNr') if history_entry else None,
|
'hnr': history_entry.get('hNr') if history_entry else None,
|
||||||
'advowareArt': (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100] if history_entry else 'Schreiben',
|
'advowareArt': (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100] if history_entry else 'Schreiben',
|
||||||
'advowareBemerkung': (history_entry.get('text', '') or '')[:255] if history_entry else '',
|
'advowareBemerkung': (history_entry.get('text', '') or '')[:255] if history_entry else '',
|
||||||
|
'advowareErstellungTimestamp': ((history_entry.get('dat') or '').replace('T', ' ')[:19] or None) if history_entry else None,
|
||||||
'dateipfad': windows_file.get('path', ''),
|
'dateipfad': windows_file.get('path', ''),
|
||||||
'blake3hash': blake3_hash,
|
'blake3hash': blake3_hash,
|
||||||
'syncedHash': blake3_hash,
|
'syncedHash': blake3_hash,
|
||||||
@@ -337,6 +348,9 @@ async def _run_advoware_sync(
|
|||||||
update_data['hnr'] = history_entry.get('hNr')
|
update_data['hnr'] = history_entry.get('hNr')
|
||||||
update_data['advowareArt'] = (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100]
|
update_data['advowareArt'] = (history_entry.get('art', 'Schreiben') or 'Schreiben')[:100]
|
||||||
update_data['advowareBemerkung'] = (history_entry.get('text', '') or '')[:255]
|
update_data['advowareBemerkung'] = (history_entry.get('text', '') or '')[:255]
|
||||||
|
erstellung_dat = (history_entry.get('dat') or '').replace('T', ' ')[:19]
|
||||||
|
if erstellung_dat:
|
||||||
|
update_data['advowareErstellungTimestamp'] = erstellung_dat
|
||||||
|
|
||||||
# Mark for re-sync to xAI only if file content actually changed
|
# Mark for re-sync to xAI only if file content actually changed
|
||||||
# (USN can change without content change, e.g. metadata-only updates)
|
# (USN can change without content change, e.g. metadata-only updates)
|
||||||
|
|||||||
Reference in New Issue
Block a user