From 1f834160ca8e49ac85132ddfc4ab9553e806e2cd Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 3 Apr 2026 01:24:20 +0200 Subject: [PATCH] Add ability to change case customer from case detail --- app/modules/sag/backend/router.py | 12 +++++ app/modules/sag/templates/detail.html | 77 +++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/app/modules/sag/backend/router.py b/app/modules/sag/backend/router.py index e473006..47a50f0 100644 --- a/app/modules/sag/backend/router.py +++ b/app/modules/sag/backend/router.py @@ -161,6 +161,14 @@ def _validate_group_id(group_id: Optional[int], field_name: str = "assigned_grou if not exists: raise HTTPException(status_code=400, detail=f"Invalid {field_name}") + +def _validate_customer_id(customer_id: Optional[int], field_name: str = "customer_id") -> None: + if customer_id is None: + return + exists = execute_query("SELECT 1 FROM customers WHERE id = %s", (customer_id,)) + if not exists: + raise HTTPException(status_code=400, detail=f"Invalid {field_name}") + # ============================================================================ # QUICKCREATE AI ANALYSIS # ============================================================================ @@ -973,6 +981,9 @@ async def update_sag(sag_id: int, updates: dict): if "assigned_group_id" in updates: updates["assigned_group_id"] = _coerce_optional_int(updates.get("assigned_group_id"), "assigned_group_id") _validate_group_id(updates["assigned_group_id"]) + if "customer_id" in updates: + updates["customer_id"] = _coerce_optional_int(updates.get("customer_id"), "customer_id") + _validate_customer_id(updates["customer_id"]) # Build dynamic update query allowed_fields = [ @@ -980,6 +991,7 @@ async def update_sag(sag_id: int, updates: dict): "beskrivelse", "template_key", "status", + "customer_id", "ansvarlig_bruger_id", "assigned_group_id", "priority", diff --git a/app/modules/sag/templates/detail.html b/app/modules/sag/templates/detail.html index e5e5ee7..e8d7c41 100644 --- a/app/modules/sag/templates/detail.html +++ b/app/modules/sag/templates/detail.html @@ -2376,9 +2376,19 @@
Kunde
{% if customer %} - {{ customer.name }} +
+ {{ customer.name }} + +
{% else %} - Ingen +
+ Ingen + +
{% endif %}
@@ -2608,6 +2618,9 @@

{{ case.titel }}

+
@@ -2991,7 +3004,7 @@