Skip to content

WIP: get current sprint tasks and add hours to the timesheet #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adrianlzt
Copy link
Contributor

This is a work in progress, because currently it has some hard coded values in the domain to get tasks.

The idea is to create a tool to be able to get your current tasks and another tool to add time to those tasks, so at the end you can do something like "add 2h to my tasks foobar". The LLM will get the active tasks and add 2 hours for that one.

What do you think? How that could be generalized?

I have only used ODOO in my current company so I do not exactly how it is used in other organizations.

In this implementation the filters used are fixed to some magic values.
Think how that could be generalized.
@tuanle96
Copy link
Owner

I think instead of hardcoding the values ​​into the function, pass it into the parameter and use LLM to process and build the parameter.

@mcp.tool(description="Get the tasks of the current sprint for the calling user.")
def get_current_sprint_tasks(
    ctx: Context,
    project_name: str = None,
    stage_ids: list[int] = None
) -> SprintTasksResponse:
    """
    Retrieves tasks for the current sprint and the user making the call.
    
    Args:
        project_name: Optional name of the project to filter tasks
        stage_ids: Optional list of stage IDs to filter tasks
    """
    odoo = ctx.request_context.lifespan_context.odoo
    user_id = odoo.uid

    if not user_id:
        return SprintTasksResponse(success=False, error="User ID not found in context.")

    try:
        user_id_int = int(user_id)
    except ValueError:
        return SprintTasksResponse(success=False, error=f"Invalid user ID: {user_id}")
    
    # Get default values from config if not provided
    if project_name is None:
        project_name = ctx.config.get("default_project_name", "EN CURSO")
    
    if stage_ids is None:
        stage_ids = ctx.config.get("sprint_stage_ids", [963, 962, 966])
    
    # Build domain dynamically
    domain = [
        "&",
        ["user_ids", "in", user_id_int],
    ]
    
    # Add project condition if provided
    if project_name:
        domain.append("&")
        domain.append(["project_id.name", "ilike", project_name])
    
    # Add stage conditions
    if stage_ids:
        stage_conditions = []
        for i, stage_id in enumerate(stage_ids):
            if i > 0:  # Add OR operator between stages
                stage_conditions.append("|")
            stage_conditions.append(["stage_id", "=", stage_id])
        
        # Add stage conditions to domain (in reverse order for Odoo's prefix notation)
        domain.extend(stage_conditions[::-1])
    
    try:
        tasks = odoo.search_read(model_name="project.task", domain=domain)
        parsed_tasks = [Task(**task) for task in tasks]
        return SprintTasksResponse(success=True, tasks=parsed_tasks)

    except Exception as e:
        return SprintTasksResponse(success=False, error=str(e))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants