From 598a9f779367cbb3c73596b683dddf959e355695 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Tue, 7 Oct 2025 10:56:00 -0500 Subject: [PATCH] Adding logic to add updates. --- inventory/routes/entry.py | 11 +++-- inventory/templates/update_list.html | 66 +++++++++++++++++++++------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/inventory/routes/entry.py b/inventory/routes/entry.py index f434c0f..6b0c912 100644 --- a/inventory/routes/entry.py +++ b/inventory/routes/entry.py @@ -274,7 +274,6 @@ def init_entry_routes(app): for k in ("brand_id", "type_id", "owner_id", "location_id", "image_id"): if payload.get(k) == "": payload[k] = None - # payload["timestamp"] = datetime.now() if model == "worklog": if "contact" in payload and "contact_id" not in payload: @@ -285,13 +284,17 @@ def init_entry_routes(app): # Parent first, no commit yet obj = svc.create(payload, actor="create_entry", commit=False) + # Ensure PK is available for children and relationship auto-FK works + sess.flush() + # Children if model == "worklog" and updates: - note_cls = type(obj).updates.property.mapper.class_ + note_mapper = type(obj).updates.property.mapper + note_cls = note_mapper.class_ for item in updates: - content = (item.get("content") or "").trim() if hasattr(str, 'trim') else (item.get("content") or "").strip() + content = (item.get("content") or "").strip() if content: - sess.add(note_cls(work_log_id=obj.id, content=content)) + obj.updates.append(note_cls(content=content)) sess.commit() return {"status": "success", "id": obj.id} diff --git a/inventory/templates/update_list.html b/inventory/templates/update_list.html index 92f04b8..eda6293 100644 --- a/inventory/templates/update_list.html +++ b/inventory/templates/update_list.html @@ -14,7 +14,8 @@
- +
@@ -25,30 +26,61 @@ {% endfor %} +
+ + +
+ + +
+ +
+
Pending new updates
+
    +
    +
    + + \ No newline at end of file