Synchronise approved AQMM across staff and review boards
This commit is contained in:
@@ -18,7 +18,12 @@ from app.modules.core.rbac.deps import get_user_permissions, get_user_roles
|
||||
from app.modules.documents.models import EngagementDocument
|
||||
from app.modules.clients.models import Client, ClientBranch, ClientBusinessUnit
|
||||
from app.modules.registrations.models import ClientRegistration, RegistrationType
|
||||
from app.modules.services.execution import CLOSED_TASK_STATUSES, TASK_PRIORITIES, TASK_STATUSES
|
||||
from app.modules.services.execution import (
|
||||
CLOSED_TASK_STATUSES,
|
||||
TASK_PRIORITIES,
|
||||
TASK_STATUSES,
|
||||
synchronise_approved_engagement_acceptance_tasks,
|
||||
)
|
||||
from app.modules.services.engagement_resources import build_engagement_resource_context
|
||||
from app.modules.services.models import (
|
||||
ClientServiceSubscription,
|
||||
@@ -408,6 +413,21 @@ def build_partner_payload(
|
||||
)
|
||||
option_stmt = _subscription_scope_filter(option_stmt, tenant_id, branch_id, current_user, roles, financial_year=None)
|
||||
option_engagements = db.execute(option_stmt).scalars().all()
|
||||
|
||||
# Keep the Review Board in step with the engagement-level AQMM workflow.
|
||||
# Older generated task rows can retain their original AQMM gate flags even
|
||||
# after acceptance is approved; reconcile only those duplicated setup rows
|
||||
# before task buckets/counts are built.
|
||||
repaired_setup_rows = 0
|
||||
for subscription in option_engagements:
|
||||
repaired_setup_rows += synchronise_approved_engagement_acceptance_tasks(
|
||||
db,
|
||||
subscription=subscription,
|
||||
actor_user_id=int(current_user.id),
|
||||
)
|
||||
if repaired_setup_rows:
|
||||
db.commit()
|
||||
|
||||
financial_year_options = sorted({(row.financial_year or "").strip() for row in option_engagements if (row.financial_year or "").strip()}, reverse=True)
|
||||
period_options = sorted({(row.period_label or "").strip() for row in option_engagements if (row.period_label or "").strip()})
|
||||
service_map = {}
|
||||
@@ -697,6 +717,14 @@ def partner_engagement_detail(request: Request, engagement_id: int):
|
||||
if not engagement:
|
||||
return _redirect_denied()
|
||||
|
||||
repaired_setup_rows = synchronise_approved_engagement_acceptance_tasks(
|
||||
db,
|
||||
subscription=engagement,
|
||||
actor_user_id=int(current_user.id),
|
||||
)
|
||||
if repaired_setup_rows:
|
||||
db.commit()
|
||||
|
||||
task_stmt = select(ClientServiceTaskInstance).options(
|
||||
selectinload(ClientServiceTaskInstance.client),
|
||||
selectinload(ClientServiceTaskInstance.catalogue),
|
||||
|
||||
Reference in New Issue
Block a user