feat: add icon field support to knowledge article tools
- get_knowledge_article: returns icon field - create_knowledge_article: accepts optional icon parameter - update_knowledge_article: accepts optional icon parameter (empty string = no change, preserves existing icon) Refs: odoo-plugin-icon-field-request
This commit is contained in:
+20
-12
@@ -76,12 +76,6 @@ def _keychain_delete(account: str) -> bool:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_credentials() -> tuple[str, str]:
|
|
||||||
"""Resolve username and API key: env vars take priority, then system keystore."""
|
|
||||||
username = ODOO_USERNAME or _keychain_get("odoo_username")
|
|
||||||
api_key = ODOO_API_KEY or _keychain_get("odoo_api_key")
|
|
||||||
return username, api_key
|
|
||||||
|
|
||||||
def _get_credentials() -> tuple[str, str]:
|
def _get_credentials() -> tuple[str, str]:
|
||||||
"""Resolve username and API key: env vars take priority, then macOS Keychain."""
|
"""Resolve username and API key: env vars take priority, then macOS Keychain."""
|
||||||
username = ODOO_USERNAME or _keychain_get("odoo_username")
|
username = ODOO_USERNAME or _keychain_get("odoo_username")
|
||||||
@@ -257,11 +251,11 @@ def search_knowledge_articles(query: str = "", limit: int = 20) -> list:
|
|||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def get_knowledge_article(article_id: int) -> dict:
|
def get_knowledge_article(article_id: int) -> dict:
|
||||||
"""Get the full content of a Knowledge article by ID.
|
"""Get the full content of a Knowledge article by ID, including its icon emoji.
|
||||||
Note: Inline base64 images are replaced with [embedded image] placeholders
|
Note: Inline base64 images are replaced with [embedded image] placeholders
|
||||||
to keep the response size manageable."""
|
to keep the response size manageable."""
|
||||||
r = _read("knowledge.article", [article_id],
|
r = _read("knowledge.article", [article_id],
|
||||||
["id", "name", "body", "parent_id", "child_ids",
|
["id", "name", "icon", "body", "parent_id", "child_ids",
|
||||||
"is_published", "write_date", "write_uid"])
|
"is_published", "write_date", "write_uid"])
|
||||||
if not r:
|
if not r:
|
||||||
return {}
|
return {}
|
||||||
@@ -275,21 +269,35 @@ def get_knowledge_article(article_id: int) -> dict:
|
|||||||
return article
|
return article
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def create_knowledge_article(name: str, body: str, parent_id: int = None) -> int:
|
def create_knowledge_article(name: str, body: str, parent_id: int = None,
|
||||||
"""Create a new Knowledge article. body is HTML. Returns new article ID."""
|
icon: str = "") -> int:
|
||||||
|
"""Create a new Knowledge article. body is HTML. Returns new article ID.
|
||||||
|
|
||||||
|
icon: optional Unicode emoji to display as the article icon in the KB tree
|
||||||
|
(e.g. '⚙️', '🔌', '🖥️'). Leave empty to use Odoo's default.
|
||||||
|
Browse available emojis at: https://emojipedia.org"""
|
||||||
vals = {"name": name, "body": body}
|
vals = {"name": name, "body": body}
|
||||||
if parent_id:
|
if parent_id:
|
||||||
vals["parent_id"] = parent_id
|
vals["parent_id"] = parent_id
|
||||||
|
if icon:
|
||||||
|
vals["icon"] = icon
|
||||||
return _create("knowledge.article", vals)
|
return _create("knowledge.article", vals)
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def update_knowledge_article(article_id: int, name: str = "", body: str = "") -> bool:
|
def update_knowledge_article(article_id: int, name: str = "", body: str = "",
|
||||||
"""Update a Knowledge article's title and/or body (HTML)."""
|
icon: str = "") -> bool:
|
||||||
|
"""Update a Knowledge article's title, body (HTML), and/or icon emoji.
|
||||||
|
|
||||||
|
icon: Unicode emoji to set as the article icon in the KB tree
|
||||||
|
(e.g. '⚙️', '🔌', '🖥️'). Empty string = no change (preserves existing icon).
|
||||||
|
Browse available emojis at: https://emojipedia.org"""
|
||||||
vals = {}
|
vals = {}
|
||||||
if name:
|
if name:
|
||||||
vals["name"] = name
|
vals["name"] = name
|
||||||
if body:
|
if body:
|
||||||
vals["body"] = body
|
vals["body"] = body
|
||||||
|
if icon:
|
||||||
|
vals["icon"] = icon
|
||||||
if not vals:
|
if not vals:
|
||||||
return False
|
return False
|
||||||
return _write("knowledge.article", article_id, vals)
|
return _write("knowledge.article", article_id, vals)
|
||||||
|
|||||||
Reference in New Issue
Block a user