Add locations (Filialen) as a grouping layer above resources
Test backoffice (smb-crm) / test (push) Successful in 1m46s
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:
@@ -56,10 +56,10 @@
|
||||
<h1>{{ client.business_name if client else 'Kalender' }}</h1>
|
||||
|
||||
<div class="filiale-filter" id="filialeFilter">
|
||||
{% if resources|length > 1 %}
|
||||
{% if locations|length > 1 %}
|
||||
<p class="flabel">Filialen:</p>
|
||||
{% for r in resources %}
|
||||
<label><input type="checkbox" class="res-toggle" value="{{ r.resource_id }}" checked> {{ r.name }}</label>
|
||||
{% for loc in locations %}
|
||||
<label><input type="checkbox" class="loc-toggle" value="{{ loc.location_id }}" checked> {{ loc.name }}</label>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<label><input type="checkbox" id="showCancelled"> Stornierte anzeigen</label>
|
||||
@@ -98,7 +98,7 @@
|
||||
<thead><tr><th>Zeit</th><th>Kunde</th><th>Leistung</th><th>Ressource</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for b in bookings %}
|
||||
<tr class="status-{{ b.status }}" data-resource="{{ b.resource_id }}">
|
||||
<tr class="status-{{ b.status }}" data-resource="{{ b.resource_id }}" data-location="{{ b.location_id }}">
|
||||
<td>{{ b.start_local.strftime('%H:%M') }}</td>
|
||||
<td>{{ b.customer_name }}</td>
|
||||
<td>{{ b.service }}</td>
|
||||
@@ -135,8 +135,12 @@
|
||||
<div class="field">
|
||||
<label>Ressource</label>
|
||||
<select name="resource_id" required>
|
||||
{% for r in resources %}
|
||||
<option value="{{ r.resource_id }}">{{ r.name }}</option>
|
||||
{% for loc in locations %}
|
||||
<optgroup label="{{ loc.name }}">
|
||||
{% for r in resources_by_location.get(loc.location_id, []) %}
|
||||
<option value="{{ r.resource_id }}">{{ r.name }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
@@ -174,7 +178,7 @@
|
||||
(function () {
|
||||
var RES_KEY = 'ownerAgendaFilialeFilter';
|
||||
var CANCELLED_KEY = 'ownerAgendaShowCancelled';
|
||||
var checkboxes = document.querySelectorAll('.res-toggle');
|
||||
var checkboxes = document.querySelectorAll('.loc-toggle');
|
||||
var showCancelledCb = document.getElementById('showCancelled');
|
||||
if (!checkboxes.length && !showCancelledCb) return;
|
||||
|
||||
@@ -197,9 +201,9 @@
|
||||
var showCancelled = !!(showCancelledCb && showCancelledCb.checked);
|
||||
|
||||
document.querySelectorAll('table tbody tr[data-resource]').forEach(function (tr) {
|
||||
var resOk = !checkboxes.length || active.indexOf(tr.getAttribute('data-resource')) !== -1;
|
||||
var locOk = !checkboxes.length || active.indexOf(tr.getAttribute('data-location')) !== -1;
|
||||
var statusOk = showCancelled || !tr.classList.contains('status-cancelled');
|
||||
tr.classList.toggle('res-hidden', !(resOk && statusOk));
|
||||
tr.classList.toggle('res-hidden', !(locOk && statusOk));
|
||||
});
|
||||
document.querySelectorAll('.day').forEach(function (dayEl) {
|
||||
var table = dayEl.querySelector('table');
|
||||
|
||||
@@ -46,7 +46,9 @@
|
||||
{% if error == "invalid_service" %}
|
||||
<div class="error">Bitte Name und eine gültige Dauer angeben.</div>
|
||||
{% elif error == "invalid_resource" %}
|
||||
<div class="error">Vorlaufzeit, Vorausbuchung und Puffer müssen 0 oder größer sein.</div>
|
||||
<div class="error">Bitte einen Namen angeben; Vorlaufzeit, Vorausbuchung und Puffer müssen 0 oder größer sein.</div>
|
||||
{% elif error == "invalid_location" %}
|
||||
<div class="error">Bitte einen Namen für die Filiale angeben.</div>
|
||||
{% elif error == "invalid_hours" %}
|
||||
<div class="error">Bitte gültige Öffnungszeiten angeben (Ende nach Beginn).</div>
|
||||
{% elif error == "invalid_notify_channel" %}
|
||||
@@ -95,48 +97,94 @@
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{% for r in resources %}
|
||||
{% for loc in locations %}
|
||||
<section>
|
||||
<h2>Verfügbarkeit — {{ r.name }}</h2>
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.update_resource', resource_id=r.resource_id) }}">
|
||||
<h2 style="font-size:1.05rem;color:var(--ink);">Filiale — {{ loc.name }}</h2>
|
||||
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.update_location', location_id=loc.location_id) }}">
|
||||
<div class="field">
|
||||
<label>Vorlaufzeit (Min.)</label>
|
||||
<input type="number" name="min_notice_minutes" value="{{ r.min_notice_minutes }}" min="0" required />
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" value="{{ loc.name }}" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Vorausbuchung (Tage)</label>
|
||||
<input type="number" name="max_advance_days" value="{{ r.max_advance_days }}" min="0" required />
|
||||
<label>Aktiv</label>
|
||||
<input type="checkbox" name="active" {{ 'checked' if loc.active }} />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Puffer (Min.)</label>
|
||||
<input type="number" name="buffer_minutes" value="{{ r.buffer_minutes }}" min="0" required />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-small">Speichern</button>
|
||||
<button type="submit" class="btn btn-small">Filiale speichern</button>
|
||||
</form>
|
||||
|
||||
<form method="post" action="{{ url_for('owner_settings.update_resource_hours', resource_id=r.resource_id) }}">
|
||||
{% set hours = hours_by_resource.get(r.resource_id, {}) %}
|
||||
{% set day_names = {0: 'Montag', 1: 'Dienstag', 2: 'Mittwoch', 3: 'Donnerstag',
|
||||
4: 'Freitag', 5: 'Samstag', 6: 'Sonntag'} %}
|
||||
{% for weekday in weekdays %}
|
||||
{% set day_hours = hours.get(weekday) %}
|
||||
<div class="weekday-row">
|
||||
<span class="day-name">{{ day_names[weekday] }}</span>
|
||||
<input type="time" name="opens_at_{{ weekday }}"
|
||||
value="{{ day_hours[0].strftime('%H:%M') if day_hours else '' }}" />
|
||||
<span>–</span>
|
||||
<input type="time" name="closes_at_{{ weekday }}"
|
||||
value="{{ day_hours[1].strftime('%H:%M') if day_hours else '' }}" />
|
||||
<input type="checkbox" name="closed_{{ weekday }}" id="closed_{{ r.resource_id }}_{{ weekday }}"
|
||||
{{ 'checked' if not day_hours }} />
|
||||
<label for="closed_{{ r.resource_id }}_{{ weekday }}">Geschlossen</label>
|
||||
{% for r in resources_by_location.get(loc.location_id, []) %}
|
||||
<div style="border-top:1px solid var(--line); margin-top:14px; padding-top:14px;">
|
||||
<h2>Mitarbeiter — {{ r.name }}</h2>
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.update_resource', resource_id=r.resource_id) }}">
|
||||
<div class="field">
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" value="{{ r.name }}" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Aktiv</label>
|
||||
<input type="checkbox" name="active" {{ 'checked' if r.active }} />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Vorlaufzeit (Min.)</label>
|
||||
<input type="number" name="min_notice_minutes" value="{{ r.min_notice_minutes }}" min="0" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Vorausbuchung (Tage)</label>
|
||||
<input type="number" name="max_advance_days" value="{{ r.max_advance_days }}" min="0" required />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Puffer (Min.)</label>
|
||||
<input type="number" name="buffer_minutes" value="{{ r.buffer_minutes }}" min="0" required />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-small">Speichern</button>
|
||||
</form>
|
||||
|
||||
<form method="post" action="{{ url_for('owner_settings.update_resource_hours', resource_id=r.resource_id) }}">
|
||||
{% set hours = hours_by_resource.get(r.resource_id, {}) %}
|
||||
{% set day_names = {0: 'Montag', 1: 'Dienstag', 2: 'Mittwoch', 3: 'Donnerstag',
|
||||
4: 'Freitag', 5: 'Samstag', 6: 'Sonntag'} %}
|
||||
{% for weekday in weekdays %}
|
||||
{% set day_hours = hours.get(weekday) %}
|
||||
<div class="weekday-row">
|
||||
<span class="day-name">{{ day_names[weekday] }}</span>
|
||||
<input type="time" name="opens_at_{{ weekday }}"
|
||||
value="{{ day_hours[0].strftime('%H:%M') if day_hours else '' }}" />
|
||||
<span>–</span>
|
||||
<input type="time" name="closes_at_{{ weekday }}"
|
||||
value="{{ day_hours[1].strftime('%H:%M') if day_hours else '' }}" />
|
||||
<input type="checkbox" name="closed_{{ weekday }}" id="closed_{{ r.resource_id }}_{{ weekday }}"
|
||||
{{ 'checked' if not day_hours }} />
|
||||
<label for="closed_{{ r.resource_id }}_{{ weekday }}">Geschlossen</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-small">Öffnungszeiten speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.create_resource') }}" style="margin-top:14px;">
|
||||
<input type="hidden" name="location_id" value="{{ loc.location_id }}" />
|
||||
<div class="field">
|
||||
<label>Neuer Mitarbeiter</label>
|
||||
<input type="text" name="name" placeholder="Name" required />
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-small">Öffnungszeiten speichern</button>
|
||||
<button type="submit" class="btn">Hinzufügen</button>
|
||||
</form>
|
||||
</section>
|
||||
{% endfor %}
|
||||
|
||||
<section>
|
||||
<h2>Neue Filiale</h2>
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.create_location') }}">
|
||||
<div class="field">
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" placeholder="z. B. Innenstadt" required />
|
||||
</div>
|
||||
<button type="submit" class="btn">Hinzufügen</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Buchungen & Benachrichtigung</h2>
|
||||
<form class="row" method="post" action="{{ url_for('owner_settings.update_client') }}">
|
||||
|
||||
Reference in New Issue
Block a user