Add locations (Filialen) as a grouping layer above resources
Test backoffice (smb-crm) / test (push) Successful in 1m46s

Enables multiple barbers/staff bookable at the same location and time
-- previously "resource" conflated "location" and "the thing that
can't double-book itself" into one row, so a Filiale could only ever
have exactly one bookable slot at once.

- New `locations` table; `resources.location_id` with a generic,
  idempotent backfill migration (any resource without a location gets
  one auto-created matching its name -- not a one-off for any single
  client, protects any future resource stuck in the old flat shape too)
- `resources`/`resource_hours`/services keep everything they already
  had (hours, min-notice, max-advance, buffer, the no-overlap
  constraint) scoped to resource_id, not location_id -- two barbers at
  one location must stay independently bookable at the same time
- booking_db.py: new locations CRUD mirroring the existing
  resources/services pattern; create_resource now requires a
  location_id, guarded the same way every other tenant check here is
  (get_location existence check, no real FK -- matches this schema's
  existing no-FK convention throughout)
- app.py: new POST /api/locations provisioning route; POST
  /api/resources now requires location_id
- owner_settings.py + settings.html: new self-service "add a Filiale"
  / "add a barber" UI -- there was previously no way to create a
  resource at all outside the CRM/n8n provisioning API
- public_booking.py + book.html: new Filiale picker (reuses the
  existing wireOptionGroup button-group pattern), filtering the
  Mitarbeiter picker to the selected location -- a single-location
  client sees no extra click, same as before Filialen existed
- owner_booking.py + agenda.html: the Filiale show/hide toggle and
  hide-cancelled toggle (shipped earlier this session) now key off
  location_id instead of resource_id, so hiding a Filiale hides every
  barber's bookings at it; manual-booking dropdown grouped by Filiale
- n8n/onboarding.json: default provisioning now creates a "Hauptfiliale"
  location before its resource (inert until re-imported into the live
  n8n instance)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-12 03:02:56 +02:00
parent a56a238e81
commit 456ca3872f
19 changed files with 585 additions and 99 deletions
+13 -5
View File
@@ -22,17 +22,25 @@ def book_page(slug):
client = bdb.get_client_by_slug(slug)
if client is None:
abort(404)
resources = bdb.list_active_resources(client["client_id"])
services = bdb.list_active_services(client["client_id"])
if not resources or not services:
client_id = client["client_id"]
locations = bdb.list_active_locations(client_id)
active_location_ids = {l["location_id"] for l in locations}
# A resource whose Filiale was deactivated shouldn't stay bookable even if
# the resource row itself is still active.
resources = [r for r in bdb.list_active_resources(client_id)
if r["location_id"] in active_location_ids]
services = bdb.list_active_services(client_id)
if not locations or not resources or not services:
# No bookable services/resources configured yet -- nothing to show a
# customer rather than a broken/empty booking form.
abort(404)
return render_template(
"book.html",
client_id=client["client_id"],
client_id=client_id,
business_name=client.get("business_name") or slug,
resources=[{"resource_id": r["resource_id"], "name": r["name"]} for r in resources],
locations=[{"location_id": l["location_id"], "name": l["name"]} for l in locations],
resources=[{"resource_id": r["resource_id"], "name": r["name"],
"location_id": r["location_id"]} for r in resources],
services=[{"service_id": s["service_id"], "name": s["name"],
"duration_minutes": s["duration_minutes"],
"price": float(s["price"]) if s["price"] is not None else None}