sync_manager.py aktualisiert
This commit is contained in:
@@ -103,7 +103,8 @@ class SyncManager:
|
|||||||
|
|
||||||
def run_sync(self):
|
def run_sync(self):
|
||||||
"""Führt den gesamten Synchronisationsprozess aus."""
|
"""Führt den gesamten Synchronisationsprozess aus."""
|
||||||
if not self._load_data(): return
|
if not self._load_data():
|
||||||
|
return
|
||||||
|
|
||||||
self.target_sheet_name = self.sheet_handler.get_main_sheet_name()
|
self.target_sheet_name = self.sheet_handler.get_main_sheet_name()
|
||||||
if not self.target_sheet_name:
|
if not self.target_sheet_name:
|
||||||
@@ -114,7 +115,13 @@ class SyncManager:
|
|||||||
gsheet_ids = set(self.gsheet_df[self.gsheet_df['CRM ID'] != '']['CRM ID'].dropna())
|
gsheet_ids = set(self.gsheet_df[self.gsheet_df['CRM ID'] != '']['CRM ID'].dropna())
|
||||||
|
|
||||||
new_ids = d365_ids - gsheet_ids
|
new_ids = d365_ids - gsheet_ids
|
||||||
deleted_ids = gsheet_ids - d365_ids
|
# --- LOGIK-KORREKTUR START ---
|
||||||
|
# Die 'deleted_ids' Logik ist nur korrekt, wenn der D365-Export ein VOLLSTÄNDIGER
|
||||||
|
# Export aller aktiven Accounts ist. Da wir hier mit Stichproben arbeiten,
|
||||||
|
# deaktivieren wir diesen Schritt, um fälschliches Archivieren zu verhindern.
|
||||||
|
deleted_ids = set() # Wir setzen es auf ein leeres Set.
|
||||||
|
self.logger.info("Archivierungs-Schritt wird übersprungen (Teil-Export angenommen).")
|
||||||
|
# --- LOGIK-KORREKTUR ENDE ---
|
||||||
existing_ids = d365_ids.intersection(gsheet_ids)
|
existing_ids = d365_ids.intersection(gsheet_ids)
|
||||||
|
|
||||||
self.logger.info(f"Sync-Analyse: {len(new_ids)} neue, {len(deleted_ids)} zu archivierende, {len(existing_ids)} bestehende Accounts.")
|
self.logger.info(f"Sync-Analyse: {len(new_ids)} neue, {len(deleted_ids)} zu archivierende, {len(existing_ids)} bestehende Accounts.")
|
||||||
@@ -122,6 +129,7 @@ class SyncManager:
|
|||||||
updates_to_batch, rows_to_append = [], []
|
updates_to_batch, rows_to_append = [], []
|
||||||
|
|
||||||
if new_ids:
|
if new_ids:
|
||||||
|
# ... (Rest der Funktion bleibt exakt gleich) ...
|
||||||
new_accounts_df = self.d365_df[self.d365_df['CRM ID'].isin(new_ids)]
|
new_accounts_df = self.d365_df[self.d365_df['CRM ID'].isin(new_ids)]
|
||||||
for _, row in new_accounts_df.iterrows():
|
for _, row in new_accounts_df.iterrows():
|
||||||
new_row_data = [""] * len(COLUMN_ORDER)
|
new_row_data = [""] * len(COLUMN_ORDER)
|
||||||
@@ -131,7 +139,7 @@ class SyncManager:
|
|||||||
new_row_data[col_idx] = row[gsheet_col]
|
new_row_data[col_idx] = row[gsheet_col]
|
||||||
rows_to_append.append(new_row_data)
|
rows_to_append.append(new_row_data)
|
||||||
|
|
||||||
if deleted_ids:
|
if deleted_ids: # Dieser Block wird nun nie mehr betreten
|
||||||
for crm_id in deleted_ids:
|
for crm_id in deleted_ids:
|
||||||
row_indices = self.gsheet_df[self.gsheet_df['CRM ID'] == crm_id].index
|
row_indices = self.gsheet_df[self.gsheet_df['CRM ID'] == crm_id].index
|
||||||
if not row_indices.empty:
|
if not row_indices.empty:
|
||||||
@@ -146,7 +154,9 @@ class SyncManager:
|
|||||||
d365_row = d365_indexed.loc[crm_id]
|
d365_row = d365_indexed.loc[crm_id]
|
||||||
gsheet_row = gsheet_indexed.loc[crm_id]
|
gsheet_row = gsheet_indexed.loc[crm_id]
|
||||||
|
|
||||||
row_updates, conflict_messages, needs_reeval = {}, [], False
|
row_updates = {}
|
||||||
|
conflict_messages = []
|
||||||
|
needs_reeval = False
|
||||||
|
|
||||||
for gsheet_col in self.d365_wins_cols:
|
for gsheet_col in self.d365_wins_cols:
|
||||||
d365_val = str(d365_row[gsheet_col])
|
d365_val = str(d365_row[gsheet_col])
|
||||||
@@ -154,7 +164,6 @@ class SyncManager:
|
|||||||
if d365_val != gsheet_val:
|
if d365_val != gsheet_val:
|
||||||
row_updates[gsheet_col] = d365_val
|
row_updates[gsheet_col] = d365_val
|
||||||
needs_reeval = True
|
needs_reeval = True
|
||||||
# NEUES LOGGING
|
|
||||||
self.logger.debug(f"ReEval für {crm_id} durch '{gsheet_col}': D365='{d365_val}' | GSheet='{gsheet_val}'")
|
self.logger.debug(f"ReEval für {crm_id} durch '{gsheet_col}': D365='{d365_val}' | GSheet='{gsheet_val}'")
|
||||||
|
|
||||||
for gsheet_col in self.smart_merge_cols:
|
for gsheet_col in self.smart_merge_cols:
|
||||||
|
|||||||
Reference in New Issue
Block a user