Adding logic to add updates.

This commit is contained in:
Yaro Kasear 2025-10-07 10:56:00 -05:00
parent 53cc90a74b
commit 598a9f7793
2 changed files with 56 additions and 21 deletions

View file

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