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 @@