feat: populate CRM Territory (Land → Bundesland/Kanton) on leads #6

Merged
forgejo-admin merged 4 commits from feature/crm-territory into main 2026-07-25 18:34:39 +00:00

Zusammenfassung

  • leadscraper/lead_scraper/region_names.py (neu): Code→Name-Tabelle für DE/AT/CH, aus dem alten Mautic-Projekt zurückportiert.
  • ensure_territory() in crm_lead_sync.py: legt bei Bedarf eine zweistufige CRM Territory-Hierarchie an (Land als Gruppenknoten, Bundesland/Kanton als Kindknoten) — analog zu ensure_lead_source().
  • build_lead_fields() setzt jetzt territory.

Verifikation

  • Kontrolliertes Zwei-Leads-Testskript gegen den laufenden Stack (danach frappe.db.rollback()): beide Leads bekommen territory="Bayern", Hierarchie Deutschland (Gruppe) → Bayern (Kind) korrekt angelegt, kein Duplikat beim zweiten Lead.

Closes #3

## Zusammenfassung - `leadscraper/lead_scraper/region_names.py` (neu): Code→Name-Tabelle für DE/AT/CH, aus dem alten Mautic-Projekt zurückportiert. - `ensure_territory()` in `crm_lead_sync.py`: legt bei Bedarf eine zweistufige `CRM Territory`-Hierarchie an (Land als Gruppenknoten, Bundesland/Kanton als Kindknoten) — analog zu `ensure_lead_source()`. - `build_lead_fields()` setzt jetzt `territory`. ## Verifikation - Kontrolliertes Zwei-Leads-Testskript gegen den laufenden Stack (danach `frappe.db.rollback()`): beide Leads bekommen `territory="Bayern"`, Hierarchie `Deutschland` (Gruppe) → `Bayern` (Kind) korrekt angelegt, **kein Duplikat** beim zweiten Lead. Closes #3
Adds region_names.py (REGION_NAMES lookup for DE/AT/CH, ported from the
old wsc_py_leadscraper project - dropped during the initial port,
needed again here) and ensure_territory() in crm_lead_sync.py, which
auto-creates a two-level CRM Territory tree (country as group node,
region as child) the same way ensure_lead_source() already handles
CRM Lead Source. build_lead_fields() now sets the territory field.

CRM Territory is a tree doctype with no single-root constraint in its
controller, so each country is its own top-level group - verified this
against the framework's generic nested-set implementation before
relying on it.

Verified end-to-end: two leads in the same region correctly share one
Deutschland/Bayern territory pair (no duplicates on the second insert),
both leads have territory="Bayern".

Closes #3
Two corrections found while actually switching frappe-crm-erp to the
dev-apps.yml overlay for the first time (previously only documented,
never used in anger):

- docker-compose.override.yml must be listed explicitly alongside
  dev-apps.yml - it's only auto-loaded when `docker compose up` runs
  with zero -f flags, not when other -f flags are already present.
  Omitting it leaves the stack running but with no local port mapping.
- The mount is the repo root, not the inner leadscraper/ package folder
  (bench/pip expect apps/leadscraper to look like a real git-clone
  target) - this was already correct in frappe-crm-erp's own compose
  file, just under-documented here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Points to the consolidated table there instead of only showing the
dev-mount command in isolation, so all three start scenarios (local,
dev-mount, live) are discoverable from one place.
custom_google_maps_url already stores the link as a Data field, but
given the CRM frontend's field visibility is already unpredictable (see
the tags-aren't-shown-anywhere finding), add it directly to the
"Herkunft: Google Places" note too, where we already know it's reliably
visible. FCRM Note.content is a Text Editor (rich-text) field, so a
plain <a> tag renders as a clickable link - verified end-to-end (Frappe
even auto-hardens the link with rel="noopener noreferrer" on save).

Refs #1
forgejo-admin deleted branch feature/crm-territory 2026-07-25 18:34:39 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Frappe-Projekte/LeadScraper-Google!6
No description provided.