sync_manager.py aktualisiert
This commit is contained in:
@@ -139,19 +139,12 @@ class SyncManager:
|
|||||||
rows_to_append.append(new_row_data)
|
rows_to_append.append(new_row_data)
|
||||||
|
|
||||||
if existing_ids:
|
if existing_ids:
|
||||||
# Erstelle ein indiziertes D365-DataFrame für schnellen Zugriff
|
|
||||||
d365_indexed = self.d365_df.set_index('CRM ID')
|
d365_indexed = self.d365_df.set_index('CRM ID')
|
||||||
|
gsheet_indexed = self.gsheet_df.set_index('CRM ID')
|
||||||
# --- FINALE KORREKTUR DER ITERATIONS-LOGIK ---
|
|
||||||
# Wir filtern das GSheet-DataFrame, um nur die bestehenden Zeilen zu bekommen,
|
|
||||||
# ABER wir behalten seinen ursprünglichen numerischen Index.
|
|
||||||
gsheet_to_update_df = self.gsheet_df[self.gsheet_df['CRM ID'].isin(existing_ids)]
|
|
||||||
|
|
||||||
# .iterrows() gibt hier den korrekten numerischen Index und die Zeilendaten zurück
|
for row_idx, gsheet_row in gsheet_indexed.iterrows():
|
||||||
for original_row_index, gsheet_row in gsheet_to_update_df.iterrows():
|
crm_id = gsheet_row.name
|
||||||
crm_id = gsheet_row['CRM ID']
|
|
||||||
if crm_id not in d365_indexed.index: continue
|
if crm_id not in d365_indexed.index: continue
|
||||||
|
|
||||||
d365_row = d365_indexed.loc[crm_id]
|
d365_row = d365_indexed.loc[crm_id]
|
||||||
|
|
||||||
row_updates, conflict_messages, needs_reeval = {}, [], False
|
row_updates, conflict_messages, needs_reeval = {}, [], False
|
||||||
@@ -161,18 +154,27 @@ class SyncManager:
|
|||||||
gsheet_val = str(gsheet_row[gsheet_col]).strip()
|
gsheet_val = str(gsheet_row[gsheet_col]).strip()
|
||||||
|
|
||||||
is_different = False
|
is_different = False
|
||||||
|
|
||||||
|
# --- FINALE, KORREKTE PRÜFLOGIK-STRUKTUR ---
|
||||||
if gsheet_col == 'CRM Land':
|
if gsheet_col == 'CRM Land':
|
||||||
translated_d365_val = Config.COUNTRY_CODE_MAP.get(d365_val.lower(), d365_val)
|
translated_d365_val = Config.COUNTRY_CODE_MAP.get(d365_val.lower(), d365_val)
|
||||||
if translated_d365_val.lower() != gsheet_val.lower():
|
if translated_d365_val.lower() != gsheet_val.lower():
|
||||||
is_different = True
|
is_different = True
|
||||||
|
|
||||||
elif gsheet_col == 'CRM Anzahl Techniker':
|
elif gsheet_col == 'CRM Anzahl Techniker':
|
||||||
if d365_val == '-1' and gsheet_val == '': is_different = False
|
if d365_val == '-1' and gsheet_val == '':
|
||||||
elif d365_val != gsheet_val: is_different = True
|
pass # Explizit nichts tun, sie sind gleich
|
||||||
|
elif d365_val != gsheet_val:
|
||||||
|
is_different = True
|
||||||
|
|
||||||
elif gsheet_col == 'CRM Branche':
|
elif gsheet_col == 'CRM Branche':
|
||||||
if gsheet_row['Chat Vorschlag Branche'] == '' and d365_val != gsheet_val:
|
if gsheet_row['Chat Vorschlag Branche'] == '' and d365_val != gsheet_val:
|
||||||
is_different = True
|
is_different = True
|
||||||
else:
|
|
||||||
if d365_val != gsheet_val: is_different = True
|
else: # Standard-Vergleich für alle anderen Spalten
|
||||||
|
if d365_val != gsheet_val:
|
||||||
|
is_different = True
|
||||||
|
# --- ENDE DER PRÜFLOGIK-STRUKTUR ---
|
||||||
|
|
||||||
if is_different:
|
if is_different:
|
||||||
row_updates[gsheet_col] = d365_val
|
row_updates[gsheet_col] = d365_val
|
||||||
@@ -182,6 +184,7 @@ class SyncManager:
|
|||||||
for gsheet_col in self.smart_merge_cols:
|
for gsheet_col in self.smart_merge_cols:
|
||||||
d365_val = str(d365_row.get(gsheet_col, '')).strip()
|
d365_val = str(d365_row.get(gsheet_col, '')).strip()
|
||||||
gsheet_val = str(gsheet_row.get(gsheet_col, '')).strip()
|
gsheet_val = str(gsheet_row.get(gsheet_col, '')).strip()
|
||||||
|
|
||||||
if d365_val and not gsheet_val:
|
if d365_val and not gsheet_val:
|
||||||
row_updates[gsheet_col] = d365_val
|
row_updates[gsheet_col] = d365_val
|
||||||
needs_reeval = True
|
needs_reeval = True
|
||||||
@@ -192,8 +195,7 @@ class SyncManager:
|
|||||||
if needs_reeval: row_updates["ReEval Flag"] = "x"
|
if needs_reeval: row_updates["ReEval Flag"] = "x"
|
||||||
|
|
||||||
if row_updates:
|
if row_updates:
|
||||||
# Hier ist 'original_row_index' jetzt die korrekte Integer-Zeilennummer
|
sheet_row_number = row_idx + self.sheet_handler._header_rows + 1
|
||||||
sheet_row_number = original_row_index + self.sheet_handler._header_rows + 1
|
|
||||||
for col_name, value in row_updates.items():
|
for col_name, value in row_updates.items():
|
||||||
updates_to_batch.append({ "range": f"{COLUMN_MAP[col_name]['Titel']}{sheet_row_number}", "values": [[value]] })
|
updates_to_batch.append({ "range": f"{COLUMN_MAP[col_name]['Titel']}{sheet_row_number}", "values": [[value]] })
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user