Generate engagement tasks automatically and repair missing tasks

This commit is contained in:
A R R R Associates
2026-08-07 14:04:15 +05:30
parent b29a53b79f
commit 5ec7f7d446
5 changed files with 193 additions and 254 deletions
+25
View File
@@ -270,6 +270,31 @@ def generate_tasks_for_subscription(db: Session, *, subscription: ClientServiceS
def generate_tasks_for_subscription_if_ready(
db: Session,
*,
subscription: ClientServiceSubscription,
user_id: int,
) -> int:
"""Generate task instances when the engagement is allowed to execute.
Non-assurance engagements are ready immediately. Assurance engagements keep
the existing AQMM acceptance gate: no task is generated until acceptance is
approved. The underlying generator remains idempotent and will not duplicate
an existing subscription/template/year task instance.
"""
if (
quality_required_for_engagement(subscription.engagement_type)
and getattr(subscription, "quality_acceptance_status", None) != QUALITY_APPROVED
):
return 0
return generate_tasks_for_subscription(
db,
subscription=subscription,
user_id=user_id,
)
def _latest_task_documents(db: Session, task_id: int) -> list[EngagementDocument]:
return db.execute(