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
+58 -3
View File
@@ -48,6 +48,17 @@
<div class="error" id="error-banner"></div>
{% if locations|length > 1 %}
<section>
<h2>Filiale</h2>
<div class="options" id="location-options">
{% for l in locations %}
<button type="button" class="opt" data-location-id="{{ l.location_id }}">{{ l.name }}</button>
{% endfor %}
</div>
</section>
{% endif %}
<section>
<h2>Leistung</h2>
<div class="options" id="service-options">
@@ -61,11 +72,12 @@
</section>
{% if resources|length > 1 %}
<section>
<section id="resource-section">
<h2>Mitarbeiter</h2>
<div class="options" id="resource-options">
{% for r in resources %}
<button type="button" class="opt" data-resource-id="{{ r.resource_id }}">{{ r.name }}</button>
<button type="button" class="opt" data-resource-id="{{ r.resource_id }}"
data-location-id="{{ r.location_id }}">{{ r.name }}</button>
{% endfor %}
</div>
</section>
@@ -108,12 +120,45 @@
<script>
(function () {
var CLIENT_ID = {{ client_id|tojson }};
var LOCATIONS = {{ locations|tojson }};
var RESOURCES = {{ resources|tojson }};
var services = {{ services|tojson }};
var selectedService = null;
var selectedLocation = LOCATIONS.length === 1 ? LOCATIONS[0].location_id : null;
var selectedResource = RESOURCES.length === 1 ? RESOURCES[0].resource_id : null;
var selectedSlot = null;
var resourceSection = document.getElementById('resource-section');
var resourceOptionsEl = document.getElementById('resource-options');
// Filters the pre-rendered Mitarbeiter buttons down to the selected
// Filiale (all of them if there's only one Filiale, i.e. selectedLocation
// is null), auto-selecting/hiding the whole section when exactly one
// barber matches -- same "no extra click" behavior as the single-
// resource case already had before Filialen existed.
function applyLocationFilter() {
if (!resourceOptionsEl) {
return;
}
var visible = [];
resourceOptionsEl.querySelectorAll('.opt').forEach(function (btn) {
var matches = !selectedLocation || btn.getAttribute('data-location-id') === selectedLocation;
btn.hidden = !matches;
if (matches) {
visible.push(btn);
}
});
if (resourceSection) {
resourceSection.style.display = visible.length > 1 ? '' : 'none';
}
if (visible.length === 1) {
selectedResource = visible[0].getAttribute('data-resource-id');
} else if (selectedResource && !visible.some(function (b) {
return b.getAttribute('data-resource-id') === selectedResource;
})) {
selectedResource = null;
}
}
var errorBanner = document.getElementById('error-banner');
var dateInput = document.getElementById('date-input');
@@ -155,18 +200,28 @@
});
}
wireOptionGroup(document.getElementById('location-options'), function (btn) {
selectedLocation = btn.getAttribute('data-location-id');
selectedResource = null;
selectedSlot = null;
applyLocationFilter();
loadSlots();
});
wireOptionGroup(document.getElementById('service-options'), function (btn) {
selectedService = btn.getAttribute('data-service-id');
selectedSlot = null;
loadSlots();
});
wireOptionGroup(document.getElementById('resource-options'), function (btn) {
wireOptionGroup(resourceOptionsEl, function (btn) {
selectedResource = btn.getAttribute('data-resource-id');
selectedSlot = null;
loadSlots();
});
applyLocationFilter();
dateInput.addEventListener('change', function () {
selectedSlot = null;
loadSlots();