Files
I. Alcaraz Salazar 4363527c58 filter: exclude CAS 3D projects from dashboard
Add exclude_company_ids config in settings.yaml to filter out
projects by Odoo company_id. Currently excludes company_id=2
(CAS 3D), keeping only Consultoria AS and unassigned projects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 11:18:19 +00:00

46 lines
1.6 KiB
Python

from fastapi import APIRouter
router = APIRouter(prefix="/api/tasks", tags=["tasks"])
@router.get("/by-project")
async def get_tasks_by_project():
from main import odoo_client, app_config
settings = app_config.get_settings()
exclude_ids = settings.get("odoo", {}).get("exclude_company_ids", [])
projects = await odoo_client.get_projects()
tasks = await odoo_client.get_tasks()
# Filter out excluded companies
if exclude_ids:
projects = [
p for p in projects
if not (isinstance(p.get("company_id"), list) and p["company_id"][0] in exclude_ids)
]
project_ids = {p["id"] for p in projects}
tasks = [t for t in tasks if t.get("project_id") and t["project_id"][0] in project_ids]
result = []
for project in projects:
project_tasks = [t for t in tasks if t.get("project_id") and t["project_id"][0] == project["id"]]
stages: dict[str, list] = {}
for task in project_tasks:
stage_name = task["stage_id"][1] if task.get("stage_id") else "Sin etapa"
stages.setdefault(stage_name, []).append({
"id": task["id"],
"name": task["name"],
"assigned": task.get("user_ids", []),
"priority": task.get("priority", "0"),
"deadline": task.get("date_deadline"),
})
result.append({
"id": project["id"],
"name": project["name"],
"color": project.get("color", 0),
"stages": stages,
})
return {"projects": result}