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:
|
||||
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]:
|
||||
"""Resolve username and API key: env vars take priority, then macOS Keychain."""
|
||||
username = ODOO_USERNAME or _keychain_get("odoo_username")
|
||||
@@ -257,11 +251,11 @@ def search_knowledge_articles(query: str = "", limit: int = 20) -> list:
|
||||
|
||||
@mcp.tool()
|
||||
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
|
||||
to keep the response size manageable."""
|
||||
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"])
|
||||
if not r:
|
||||
return {}
|
||||
@@ -275,21 +269,35 @@ def get_knowledge_article(article_id: int) -> dict:
|
||||
return article
|
||||
|
||||
@mcp.tool()
|
||||
def create_knowledge_article(name: str, body: str, parent_id: int = None) -> int:
|
||||
"""Create a new Knowledge article. body is HTML. Returns new article ID."""
|
||||
def create_knowledge_article(name: str, body: str, parent_id: int = None,
|
||||
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}
|
||||
if parent_id:
|
||||
vals["parent_id"] = parent_id
|
||||
if icon:
|
||||
vals["icon"] = icon
|
||||
return _create("knowledge.article", vals)
|
||||
|
||||
@mcp.tool()
|
||||
def update_knowledge_article(article_id: int, name: str = "", body: str = "") -> bool:
|
||||
"""Update a Knowledge article's title and/or body (HTML)."""
|
||||
def update_knowledge_article(article_id: int, name: str = "", body: str = "",
|
||||
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 = {}
|
||||
if name:
|
||||
vals["name"] = name
|
||||
if body:
|
||||
vals["body"] = body
|
||||
if icon:
|
||||
vals["icon"] = icon
|
||||
if not vals:
|
||||
return False
|
||||
return _write("knowledge.article", article_id, vals)
|
||||
|
||||
Reference in New Issue
Block a user