from dataclasses import dataclass, field from typing import Dict, List from odoo_client import OdooClient from rich.table import Table @dataclass class Task: id: int name: str tags: List[str] stage: str priority: bool url: str = field(init=False) def __post_init__(self) -> None: self.url = f"https://www.odoo.com/odoo/49/tasks/{self.id}" def __rich__(self): table = Table(show_header=True, header_style="bold magenta", box=None) table.add_column("Field", style="cyan", justify="right") table.add_column("Value", style="bold green") table.add_row("ID", str(self.id)) table.add_row("Name", self.name) table.add_row("Tags", ", ".join(self.tags) if self.tags else "[dim]No tags[/dim]") table.add_row("Stage", f"[yellow]{self.stage}[/yellow]") table.add_row("Priority", "[bold red]High[/bold red]" if self.priority else "[dim]Low[/dim]") table.add_row("URL", f"[blue underline]{self.url}[/blue underline]") return table def map_record_to_task(record: Dict) -> Task: return Task( id=record["id"], name=record["name"], tags=[tag["display_name"] for tag in record["tag_ids"]], stage=record["stage_id"]["display_name"], priority=record["priority"] == "1", ) def fetch_tasks(client: OdooClient, domain: List[tuple[str, str, str]]) -> List[Task]: records = client.web_search_read( "project.task", domain, spec={ "name": {}, "priority": {}, "tag_ids": { "fields": { "display_name": {}, }, }, "stage_id": { "fields": { "display_name": {}, }, }, }, ) return [map_record_to_task(record) for record in records]