Fix retirement propagation and task counts

This commit is contained in:
A R R R Associates
2026-09-19 15:11:56 +05:30
parent f565e8309d
commit cc8691d4cd
4 changed files with 107 additions and 22 deletions
+35 -3
View File
@@ -1194,7 +1194,7 @@ def task_templates_list(request: Request):
tenant_id = _active_tenant_id(request, user)
enabled_rows = list_firm_services_payload(db, tenant_id=tenant_id)
for row in enabled_rows:
row['task_count'] = len(get_firm_task_templates(db, tenant_id=tenant_id, catalogue_id=row['catalogue'].id))
row['task_count'] = sum(1 for task in get_firm_task_templates(db, tenant_id=tenant_id, catalogue_id=row['catalogue'].id) if task.is_active)
return _render(request, 'modules/services/templates/services/task_templates_list.html', db, user, title='Firm Service Task Templates', rows=enabled_rows, can_manage_tasks=_can_manage_firm_tasks(db, user))
finally:
db.close()
@@ -1218,11 +1218,13 @@ def task_templates_detail(request: Request, catalogue_id: int):
return RedirectResponse(url='/services', status_code=303)
tasks = get_firm_task_templates(db, tenant_id=tenant_id, catalogue_id=catalogue_id)
system_update_diff_map = {}
system_update_retirement_map = {}
for firm_task in tasks:
if getattr(firm_task, "system_update_available", False) and getattr(firm_task, "source_system_task_id", None):
system_task = db.get(ServiceDefaultTaskTemplate, int(firm_task.source_system_task_id))
if system_task is not None:
system_update_diff_map[firm_task.id] = system_task_diff(system_task, firm_task)
system_update_retirement_map[firm_task.id] = not bool(system_task.is_active)
task_requirement_map = {
task.id: list_task_document_requirements(db, tenant_id=tenant_id, firm_task_template_id=task.id)
for task in tasks
@@ -1231,6 +1233,9 @@ def task_templates_detail(request: Request, catalogue_id: int):
task.id: list_task_document_templates(db, tenant_id=tenant_id, firm_task_template_id=task.id)
for task in tasks
}
default_tasks = get_default_task_templates(db, catalogue_id=catalogue_id)
show_retired = request.query_params.get("show_retired") == "1"
display_tasks = tasks if show_retired else [task for task in tasks if task.is_active]
return _render(
request,
'modules/services/templates/services/task_template_detail.html',
@@ -1240,11 +1245,20 @@ def task_templates_detail(request: Request, catalogue_id: int):
service=catalogue,
selection=selection,
task_templates=tasks,
display_task_templates=display_tasks,
show_retired=show_retired,
active_task_templates=[task for task in tasks if task.is_active],
retired_task_templates=[task for task in tasks if not task.is_active],
active_task_count=sum(1 for task in tasks if task.is_active),
retired_task_count=sum(1 for task in tasks if not task.is_active),
task_requirement_map=task_requirement_map,
task_template_file_map=task_template_file_map,
system_update_diff_map=system_update_diff_map,
system_update_retirement_map=system_update_retirement_map,
can_manage_tasks=_can_manage_firm_tasks(db, user),
default_tasks=get_default_task_templates(db, catalogue_id=catalogue_id),
default_tasks=default_tasks,
active_default_task_count=sum(1 for task in default_tasks if task.is_active),
retired_default_task_count=sum(1 for task in default_tasks if not task.is_active),
is_system_admin=_is_system_admin(db, user),
task_categories=list_task_categories(db, catalogue_id=catalogue_id, tenant_id=tenant_id, include_inactive=True),
)
@@ -1361,7 +1375,24 @@ def default_templates_detail(request: Request, catalogue_id: int):
if not catalogue:
return RedirectResponse(url='/services/defaults', status_code=303)
defaults = get_default_task_templates(db, catalogue_id=catalogue_id)
return _render(request, 'modules/services/templates/services/default_templates_detail.html', db, user, title=f'Default Tasks - {catalogue.service_name}', service=catalogue, default_tasks=defaults, task_categories=list_task_categories(db, catalogue_id=catalogue_id, tenant_id=None, include_inactive=True))
show_retired = request.query_params.get("show_retired") == "1"
display_defaults = defaults if show_retired else [task for task in defaults if task.is_active]
return _render(
request,
'modules/services/templates/services/default_templates_detail.html',
db,
user,
title=f'Default Tasks - {catalogue.service_name}',
service=catalogue,
default_tasks=defaults,
display_default_tasks=display_defaults,
show_retired=show_retired,
active_default_tasks=[task for task in defaults if task.is_active],
retired_default_tasks=[task for task in defaults if not task.is_active],
active_default_task_count=sum(1 for task in defaults if task.is_active),
retired_default_task_count=sum(1 for task in defaults if not task.is_active),
task_categories=list_task_categories(db, catalogue_id=catalogue_id, tenant_id=None, include_inactive=True),
)
finally:
db.close()
@@ -2628,6 +2659,7 @@ def sync_system_default_tasks_for_firm(request: Request, catalogue_id: int):
"updated": str(result.updated),
"unchanged": str(result.unchanged),
"duplicates_disabled": str(result.duplicates_disabled),
"custom_updates": str(result.custom_updates_available),
}
)