Auto generate engagement tasks after AQMM activation

This commit is contained in:
A R R R Associates
2026-09-22 16:22:08 +05:30
parent cb3da81f6f
commit de47ceb72d
5 changed files with 579 additions and 375 deletions
+12
View File
@@ -905,6 +905,14 @@ def subscription_detail(request: Request, subscription_id: int):
db.refresh(row)
ensure_engagement_quality_workflow(db, subscription=row, actor_user_id=user.id, create_declarations=False)
# Self-heal existing active engagements that became executable after AQMM approval
# but were created before automatic post-approval task generation was wired in.
# The generator is idempotent and only inserts missing template-backed tasks.
if row.is_active and row.status == "active" and not row.is_locked:
created_tasks = generate_tasks_for_subscription_if_ready(db, subscription=row, user_id=user.id)
if created_tasks:
db.commit()
db.refresh(row)
db.flush()
declarations = list_engagement_quality_declarations(db, subscription_id=row.id)
my_pending_declarations = [d for d in declarations if d.requested_user_id == user.id and d.status == "pending"]
@@ -1088,6 +1096,10 @@ def subscription_aqmm_approve(request: Request, subscription_id: int, csrf_token
if row:
try:
approve_engagement_quality_workflow(db, subscription=row, actor_user_id=user.id)
# Approval removes the assurance quality gate. Create any missing execution
# tasks immediately so the assigned staff member sees the engagement in My Work.
# Existing task instances are preserved because the generator is idempotent.
generate_tasks_for_subscription_if_ready(db, subscription=row, user_id=user.id)
db.commit()
except ValueError:
db.rollback()