Add optional task categories resequencing and requirement aware documents

This commit is contained in:
A R R R Associates
2026-08-12 14:57:20 +05:30
parent eb18a5695f
commit 74586d60ed
5 changed files with 128 additions and 4 deletions
+58
View File
@@ -1664,6 +1664,64 @@ def sync_firm_tasks_to_open_engagements(
db.close()
@router.post('/templates/{catalogue_id}/tasks/{task_id}/move')
def firm_task_template_move(
request: Request,
catalogue_id: int,
task_id: int,
direction: str = Form(...),
csrf_token: str = Form(...),
):
"""Move one firm task one position up/down without changing task identity."""
validate_csrf(request, csrf_token)
db = CommonSessionLocal()
try:
user = get_current_user(request, db=db)
if not user:
return RedirectResponse(url='/login', status_code=303)
if not _can_manage_firm_tasks(db, user):
return _redirect_denied()
tenant_id = _active_tenant_id(request, user)
catalogue = get_catalogue(db, catalogue_id)
if not catalogue:
return RedirectResponse(url='/services/templates', status_code=303)
selection = get_firm_selection(db, tenant_id=tenant_id, catalogue_id=catalogue_id)
if not selection or not selection.is_enabled:
return RedirectResponse(url='/services', status_code=303)
tasks = get_firm_task_templates(db, tenant_id=tenant_id, catalogue_id=catalogue_id)
index = next((i for i, row in enumerate(tasks) if int(row.id) == int(task_id)), None)
direction_value = (direction or '').strip().lower()
if index is None or direction_value not in {'up', 'down'}:
return RedirectResponse(url=f'/services/templates/{catalogue_id}?move_error=1', status_code=303)
other_index = index - 1 if direction_value == 'up' else index + 1
if other_index < 0 or other_index >= len(tasks):
return RedirectResponse(url=f'/services/templates/{catalogue_id}', status_code=303)
current = tasks[index]
other = tasks[other_index]
current_seq = int(current.sequence_no)
other_seq = int(other.sequence_no)
# Swap safely across the existing unique tenant/service/sequence constraint.
min_seq = min(int(row.sequence_no) for row in tasks)
current.sequence_no = min_seq - 1000000 - int(current.id)
current.updated_by_user_id = user.id
db.flush()
other.sequence_no = current_seq
other.updated_by_user_id = user.id
db.flush()
current.sequence_no = other_seq
db.commit()
return RedirectResponse(url=f'/services/templates/{catalogue_id}?moved=1', status_code=303)
finally:
db.close()
@router.get('/templates/{catalogue_id}/tasks/{task_id}/edit')
def firm_task_template_edit_page(request: Request, catalogue_id: int, task_id: int):
db = CommonSessionLocal()