Files
motia/bitbylaw/scripts/test_hauptadresse_explizit.py
bitbylaw c770f2c8ee feat: Implement address synchronization between EspoCRM and Advoware
- Add AdressenMapper for transforming addresses between EspoCRM and Advoware formats.
- Create AdressenSync class to handle address creation, update, and deletion synchronization.
- Introduce NotificationManager for managing manual intervention notifications in case of sync issues.
- Implement detailed logging for address sync operations and error handling.
- Ensure READ-ONLY field changes are detected and notified for manual resolution.
2026-02-08 14:29:29 +00:00

152 lines
4.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
Test: Hauptadresse explizit setzen
===================================
Teste:
1. Kann standardAnschrift beim POST gesetzt werden?
2. Kann es mehrere Hauptadressen geben?
3. Wird alte Hauptadresse automatisch deaktiviert?
"""
import asyncio
import sys
import os
from datetime import datetime
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from services.advoware import AdvowareAPI
TEST_BETNR = 104860
BOLD = '\033[1m'
GREEN = '\033[92m'
RED = '\033[91m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
RESET = '\033[0m'
def print_success(text):
print(f"{GREEN}{text}{RESET}")
def print_error(text):
print(f"{RED}{text}{RESET}")
def print_info(text):
print(f"{BLUE} {text}{RESET}")
class SimpleLogger:
def info(self, msg): pass
def error(self, msg): pass
def debug(self, msg): pass
class SimpleContext:
def __init__(self):
self.logger = SimpleLogger()
async def main():
print(f"\n{BOLD}TEST: standardAnschrift explizit setzen{RESET}\n")
context = SimpleContext()
advo = AdvowareAPI(context=context)
# Test 1: Erstelle mit standardAnschrift = true
print_info("Test 1: Erstelle Adresse mit standardAnschrift = true")
address_data = {
"strasse": "Hauptadresse Explizit Test",
"plz": "11111",
"ort": "Hauptstadt",
"land": "DE",
"standardAnschrift": True, # ← EXPLIZIT gesetzt!
"bemerkung": f"TEST-HAUPT-EXPLIZIT: {datetime.now()}"
}
result = await advo.api_call(
f'/api/v1/advonet/Beteiligte/{TEST_BETNR}/Adressen',
method='POST',
json_data=address_data
)
created = result[0]
print(f" Response standardAnschrift: {created.get('standardAnschrift')}")
# GET und prüfen
print_info("\nHole alle Adressen und prüfe...")
all_addresses = await advo.api_call(
f'/api/v1/advonet/Beteiligte/{TEST_BETNR}/Adressen',
method='GET'
)
hauptadressen = [a for a in all_addresses if a.get('standardAnschrift')]
print(f"\n{BOLD}Ergebnis:{RESET}")
print(f" Anzahl Hauptadressen: {len(hauptadressen)}")
if len(hauptadressen) > 0:
print_success(f"\n{len(hauptadressen)} Adresse(n) mit standardAnschrift = true:")
for ha in hauptadressen:
print(f" Index {ha.get('reihenfolgeIndex')}: {ha.get('strasse')}")
print(f" bemerkung: {ha.get('bemerkung', 'N/A')[:50]}")
else:
print_error("\n✗ KEINE Hauptadresse trotz standardAnschrift = true beim POST!")
# Test 2: Erstelle ZWEITE mit standardAnschrift = true
print(f"\n{BOLD}Test 2: Erstelle ZWEITE Adresse mit standardAnschrift = true{RESET}")
address_data2 = {
"strasse": "Zweite Hauptadresse Test",
"plz": "22222",
"ort": "Zweitstadt",
"land": "DE",
"standardAnschrift": True,
"bemerkung": f"TEST-HAUPT-ZWEI: {datetime.now()}"
}
await advo.api_call(
f'/api/v1/advonet/Beteiligte/{TEST_BETNR}/Adressen',
method='POST',
json_data=address_data2
)
# GET erneut
all_addresses = await advo.api_call(
f'/api/v1/advonet/Beteiligte/{TEST_BETNR}/Adressen',
method='GET'
)
hauptadressen = [a for a in all_addresses if a.get('standardAnschrift')]
print(f"\n{BOLD}Ergebnis nach 2. Adresse:{RESET}")
print(f" Anzahl Hauptadressen: {len(hauptadressen)}")
if len(hauptadressen) == 1:
print_success("\n✓ Es gibt nur EINE Hauptadresse!")
print_success("✓ Alte Hauptadresse wurde automatisch deaktiviert")
print(f" Aktuelle Hauptadresse: {hauptadressen[0].get('strasse')}")
elif len(hauptadressen) == 2:
print_error("\n✗ Es gibt ZWEI Hauptadressen!")
print_error("✗ Advoware erlaubt mehrere Hauptadressen")
for ha in hauptadressen:
print(f" - {ha.get('strasse')}")
elif len(hauptadressen) == 0:
print_error("\n✗ KEINE Hauptadresse!")
print_error("✗ standardAnschrift wird nicht gespeichert")
print(f"\n{BOLD}FAZIT:{RESET}")
if len(hauptadressen) == 1:
print_success("✓ Advoware verwaltet automatisch EINE Hauptadresse")
print_success("✓ Neue Hauptadresse deaktiviert alte automatisch")
elif len(hauptadressen) > 1:
print_error("✗ Mehrere Hauptadressen möglich")
else:
print_error("✗ standardAnschrift ist möglicherweise READ-ONLY")
print(f"\n{YELLOW}⚠️ Test-Adressen mit 'TEST-HAUPT' bereinigen{RESET}\n")
if __name__ == "__main__":
asyncio.run(main())