fix: Update metadata synchronization logic to always sync changes and correct field mappings
This commit is contained in:
@@ -289,7 +289,8 @@ class AdvowareDocumentSyncUtils:
|
||||
"""
|
||||
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:
|
||||
espo_doc: Document from EspoCRM
|
||||
@@ -300,24 +301,28 @@ class AdvowareDocumentSyncUtils:
|
||||
"""
|
||||
updates = {}
|
||||
|
||||
# Map History fields to EspoCRM fields
|
||||
# Map History fields to correct EspoCRM field names
|
||||
history_text = advo_history.get('text', '')
|
||||
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_type = espo_doc.get('type', '')
|
||||
espo_date = espo_doc.get('dateUploaded', '')
|
||||
espo_bemerkung = espo_doc.get('advowareBemerkung', '')
|
||||
espo_art = espo_doc.get('advowareArt', '')
|
||||
espo_hnr = espo_doc.get('hnr')
|
||||
|
||||
# Check if different
|
||||
if history_text and history_text != espo_description:
|
||||
updates['description'] = history_text
|
||||
# Check if different - sync metadata independently of file changes
|
||||
if history_text != espo_bemerkung:
|
||||
updates['advowareBemerkung'] = history_text
|
||||
|
||||
if history_art and history_art != espo_type:
|
||||
updates['type'] = history_art
|
||||
if history_art != espo_art:
|
||||
updates['advowareArt'] = history_art
|
||||
|
||||
if history_dat and history_dat != espo_date:
|
||||
updates['dateUploaded'] = history_dat
|
||||
if history_hnr is not None and history_hnr != espo_hnr:
|
||||
updates['hnr'] = history_hnr
|
||||
|
||||
# Always update lastSyncTimestamp when metadata changes
|
||||
if len(updates) > 0:
|
||||
updates['lastSyncTimestamp'] = datetime.now().isoformat()
|
||||
|
||||
needs_update = len(updates) > 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user