Skip to content

API Reference parrot_tools.odoo.toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.odoo.toolkit

View source

OdooToolkit — exposes Odoo ERP operations as agent tools.

Composes an :class:~parrot_tools.odoo.transport.AbstractOdooTransport (JSON-2 for Odoo 19+, XML-RPC for 14-18, or auto-detected) and turns each public async method into a tool via :class:AbstractToolkit.

Inspired by:

  • pantalytics/odoo-mcp-pro — for the result-envelope pattern, the bulk CRUD layout and the binary upload helper.
  • phenobarbital/flowtask OdooInjector — for the import_records upsert use case (Odoo's load with external IDs).

Configuration falls back to the ODOO_* keys in :mod:parrot.conf when constructor arguments are omitted.

Alias OdooAuthenticationError

Re-exported from parrot.interfaces.odoointerface.OdooAuthenticationError.

Alias OdooConnectionError

Re-exported from parrot.interfaces.odoointerface.OdooConnectionError.

Alias OdooError

Re-exported from parrot.interfaces.odoointerface.OdooError.

Alias OdooRPCError

Re-exported from parrot.interfaces.odoointerface.OdooRPCError.

Class OdooToolkit

Toolkit exposing Odoo ERP CRUD + business helpers as agent tools.

Construction validates configuration via :class:OdooConfig but defers all I/O to the first tool call, which authenticates lazily through :meth:_pre_execute.

Parameter Type Default Description
url str | None None Odoo base URL. Falls back to ODOO_URL.
database str | None None Odoo database. Falls back to ODOO_DATABASE.
username str | None None Odoo login. Falls back to ODOO_USERNAME.
password str | None None Odoo password / API key. Falls back to ODOO_PASSWORD.
timeout int | None None Request timeout (seconds). Falls back to ODOO_TIMEOUT.
verify_ssl bool | None None Whether to verify SSL certificates.
protocol Protocol 'auto' 'auto' (default), 'json2', 'jsonrpc', or 'xmlrpc'.
transport AbstractOdooTransport | None None Pre-built transport (mainly for tests). When provided, protocol is ignored.
**kwargs Any {} Forwarded to :class:AbstractToolkit.

Attributes:

Attribute Type Description
confirming_tools frozenset
protocol Protocol
ALLOWED_AGGREGATORS frozenset[str]
SAFE_DOMAIN_OPERATORS frozenset[str]

Method OdooToolkit.stop

Release the transport's session if any.

stop() -> None

Method OdooToolkit.cleanup

cleanup() -> None

Method OdooToolkit.server_info

Return Odoo server version, transport, and connection status.

server_info() -> ServerInfoResult

Returns: ServerInfoResult

Method OdooToolkit.list_models

List the Odoo models the toolkit knows about with the user's ACLs.

list_models() -> ModelsResult

Returns: ModelsResult

Method OdooToolkit.fields_get

Return the field definitions for an Odoo model.

fields_get(model: str, attributes: Optional[list[str]] = None) -> dict[str, Any]

Parameter Type Default Description
model str
attributes Optional[list[str]] None

Returns: dict[str, Any]

Method OdooToolkit.search_records

Search records in any Odoo model with domain filters & pagination.

When fields is omitted, smart field selection automatically picks the top 15 most LLM-useful fields for the model (avoiding binary blobs and technical audit columns).

search_records(model: str, domain: Optional[list[Any]] = None, fields: Optional[list[str]] = None, limit: int = 100, offset: int = 0, order: Optional[str] = None) -> SearchResult

Parameter Type Default Description
model str
domain Optional[list[Any]] None
fields Optional[list[str]] None
limit int 100
offset int 0
order Optional[str] None

Returns: SearchResult

Method OdooToolkit.get_record

Read a single record by id.

When fields is omitted, smart field selection automatically picks the top 15 most LLM-useful fields for the model.

get_record(model: str, record_id: int, fields: Optional[list[str]] = None) -> RecordResult

Parameter Type Default Description
model str
record_id int
fields Optional[list[str]] None

Returns: RecordResult

Method OdooToolkit.create_record

Create one record and return the new id + a summary of the record.

create_record(model: str, values: dict[str, Any]) -> CreateResult

Parameter Type Default Description
model str
values dict[str, Any]

Returns: CreateResult

Method OdooToolkit.create_records

Create multiple records in a single round-trip (max 1000).

create_records(model: str, vals_list: list[dict[str, Any]]) -> BulkCreateResult

Parameter Type Default Description
model str
vals_list list[dict[str, Any]]

Returns: BulkCreateResult

Method OdooToolkit.update_record

Update a single record by id.

update_record(model: str, record_id: int, values: dict[str, Any]) -> UpdateResult

Parameter Type Default Description
model str
record_id int
values dict[str, Any]

Returns: UpdateResult

Method OdooToolkit.update_records

Apply the same patch to many records in one call (max 1000).

update_records(model: str, record_ids: list[int], values: dict[str, Any]) -> BulkUpdateResult

Parameter Type Default Description
model str
record_ids list[int]
values dict[str, Any]

Returns: BulkUpdateResult

Method OdooToolkit.delete_record

Delete a single record by id.

delete_record(model: str, record_id: int) -> DeleteResult

Parameter Type Default Description
model str
record_id int

Returns: DeleteResult

Method OdooToolkit.delete_records

Delete multiple records in one call (max 1000).

delete_records(model: str, record_ids: list[int]) -> BulkDeleteResult

Parameter Type Default Description
model str
record_ids list[int]

Returns: BulkDeleteResult

Method OdooToolkit.import_records

Idempotent upsert via Odoo's load (use 'id' field for external IDs).

This mirrors Odoo's CSV import semantics: rows whose external-id is already present are updated, new rows are created. Same operation Flowtask's OdooInjector relies on for ETL jobs.

import_records(model: str, fields: list[str], data: list[list[Any]], context: Optional[dict[str, Any]] = None) -> ImportResult

Parameter Type Default Description
model str
fields list[str]
data list[list[Any]]
context Optional[dict[str, Any]] None

Returns: ImportResult

Method OdooToolkit.find_partner

Search res.partner with friendly arguments and typed results.

find_partner(name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None, vat: Optional[str] = None, is_company: Optional[bool] = None, limit: int = 10) -> list[ResPartner]

Parameter Type Default Description
name Optional[str] None
email Optional[str] None
phone Optional[str] None
vat Optional[str] None
is_company Optional[bool] None
limit int 10

Returns: list[ResPartner]

Method OdooToolkit.create_partner

Create a res.partner and return it as a typed model.

create_partner(name: str, is_company: bool = False, email: Optional[str] = None, phone: Optional[str] = None, mobile: Optional[str] = None, website: Optional[str] = None, street: Optional[str] = None, street2: Optional[str] = None, city: Optional[str] = None, zip: Optional[str] = None, state_id: Optional[int] = None, country_id: Optional[int] = None, parent_id: Optional[int] = None, vat: Optional[str] = None, ref: Optional[str] = None, customer_rank: Optional[int] = None, supplier_rank: Optional[int] = None, extra: Optional[dict[str, Any]] = None) -> ResPartner

Parameter Type Default Description
name str
is_company bool False
email Optional[str] None
phone Optional[str] None
mobile Optional[str] None
website Optional[str] None
street Optional[str] None
street2 Optional[str] None
city Optional[str] None
zip Optional[str] None
state_id Optional[int] None
country_id Optional[int] None
parent_id Optional[int] None
vat Optional[str] None
ref Optional[str] None
customer_rank Optional[int] None
supplier_rank Optional[int] None
extra Optional[dict[str, Any]] None

Returns: ResPartner

Method OdooToolkit.update_partner_contact_info

Update contact / address fields on an existing partner.

update_partner_contact_info(partner_id: int, email: Optional[str] = None, phone: Optional[str] = None, mobile: Optional[str] = None, website: Optional[str] = None, street: Optional[str] = None, street2: Optional[str] = None, city: Optional[str] = None, zip: Optional[str] = None, state_id: Optional[int] = None, country_id: Optional[int] = None) -> ResPartner

Parameter Type Default Description
partner_id int
email Optional[str] None
phone Optional[str] None
mobile Optional[str] None
website Optional[str] None
street Optional[str] None
street2 Optional[str] None
city Optional[str] None
zip Optional[str] None
state_id Optional[int] None
country_id Optional[int] None

Returns: ResPartner

Method OdooToolkit.create_quotation

Create a draft sale.order (quotation) with one or more lines.

create_quotation(partner_id: int, order_lines: list[dict[str, Any]], date_order: Optional[str] = None, validity_date: Optional[str] = None, pricelist_id: Optional[int] = None, payment_term_id: Optional[int] = None, user_id: Optional[int] = None, team_id: Optional[int] = None, company_id: Optional[int] = None, client_order_ref: Optional[str] = None, extra: Optional[dict[str, Any]] = None) -> SaleOrder

Parameter Type Default Description
partner_id int
order_lines list[dict[str, Any]]
date_order Optional[str] None
validity_date Optional[str] None
pricelist_id Optional[int] None
payment_term_id Optional[int] None
user_id Optional[int] None
team_id Optional[int] None
company_id Optional[int] None
client_order_ref Optional[str] None
extra Optional[dict[str, Any]] None

Returns: SaleOrder

Method OdooToolkit.confirm_sale_order

Confirm a draft quotation, transitioning it to the 'sale' state.

confirm_sale_order(sale_order_id: int) -> SaleOrder

Parameter Type Default Description
sale_order_id int

Returns: SaleOrder

Method OdooToolkit.create_invoice

Create a draft invoice / vendor bill on account.move.

create_invoice(partner_id: int, invoice_lines: list[dict[str, Any]], move_type: Literal['out_invoice', 'in_invoice', 'out_refund', 'in_refund'] = 'out_invoice', invoice_date: Optional[str] = None, invoice_date_due: Optional[str] = None, journal_id: Optional[int] = None, currency_id: Optional[int] = None, invoice_origin: Optional[str] = None, ref: Optional[str] = None, extra: Optional[dict[str, Any]] = None) -> AccountMove

Parameter Type Default Description
partner_id int
invoice_lines list[dict[str, Any]]
move_type Literal['out_invoice', 'in_invoice', 'out_refund', 'in_refund'] 'out_invoice'
invoice_date Optional[str] None
invoice_date_due Optional[str] None
journal_id Optional[int] None
currency_id Optional[int] None
invoice_origin Optional[str] None
ref Optional[str] None
extra Optional[dict[str, Any]] None

Returns: AccountMove

Method OdooToolkit.post_invoice

Post a draft invoice (Odoo 13+: action_post).

post_invoice(invoice_id: int) -> AccountMove

Parameter Type Default Description
invoice_id int

Returns: AccountMove

Method OdooToolkit.register_payment

Register a payment on a posted invoice via account.payment.register.

Returns the dict of created account.payment records (keyed by id).

register_payment(invoice_id: int, journal_id: int, amount: Optional[float] = None, payment_date: Optional[str] = None, payment_method_line_id: Optional[int] = None, communication: Optional[str] = None) -> dict[str, Any]

Parameter Type Default Description
invoice_id int
journal_id int
amount Optional[float] None
payment_date Optional[str] None
payment_method_line_id Optional[int] None
communication Optional[str] None

Returns: dict[str, Any]

Method OdooToolkit.set_binary_field

Upload bytes (URL or base64 string) into a Binary/Image field.

set_binary_field(model: str, record_id: int, field_name: str, source: str) -> BinaryFieldResult

Parameter Type Default Description
model str
record_id int
field_name str
source str

Returns: BinaryFieldResult

Method OdooToolkit.attach_document

Create an ir.attachment linked to res_model/res_id.

attach_document(res_model: str, res_id: int, name: str, source: str, mimetype: Optional[str] = None, description: Optional[str] = None) -> BinaryFieldResult

Parameter Type Default Description
res_model str
res_id int
name str
source str
mimetype Optional[str] None
description Optional[str] None

Returns: BinaryFieldResult

Method OdooToolkit.aggregate_records

Group and aggregate records server-side using read_group (Odoo 16-18) or formatted_read_group (Odoo 19+).

aggregate_records(model: str, group_by: list[str], measures: Optional[list[str]] = None, domain: Optional[list[Any]] = None, lazy: bool = False, limit: Optional[int] = None, offset: int = 0, order: Optional[str] = None, having: Optional[list[Any]] = None) -> AggregateResult

Parameter Type Default Description
model str Odoo model technical name (e.g. "sale.order").
group_by list[str] Fields to group by (e.g. ["state", "partner_id"]). Pass an empty list for a global aggregation with no grouping (e.g. counting or summing across all matching records).
measures Optional[list[str]] None Aggregation specs as "field:agg" strings (e.g. ["amount_total:sum", "id:count"]). Supported aggregators: sum, avg, min, max, count, count_distinct.
domain Optional[list[Any]] None Optional domain filter.
lazy bool False When True, only the first group_by level is resolved. Honoured on Odoo 16-18 (read_group) only; Odoo 19+ formatted_read_group has no lazy mode and the flag is ignored (a debug log line records that).
limit Optional[int] None Max number of groups to return.
offset int 0 Groups to skip.
order Optional[str] None Sort order string.
having Optional[list[Any]] None Optional domain over the aggregates, filtering groups after aggregation (e.g. [["__count", ">", 5]] or [["amount_total:sum", ">", 1000]]). Odoo 19+ only.

Returns: AggregateResult — AggregateResult with groups list and metadata.

Raises:

  • ValueError — When an unsupported aggregator name is used, or when a non-empty having is given and the server is not Odoo 19+.

Method OdooToolkit.build_domain

Build and validate an Odoo domain array from structured conditions.

build_domain(conditions: list[dict[str, Any]], logical_operator: str = 'and') -> DomainBuildResult

Parameter Type Default Description
conditions list[dict[str, Any]] List of condition dicts, each with keys field, operator, and value. An empty list returns an empty (match-all) domain.
logical_operator str 'and' "and" (default, uses & prefix) or "or" (uses | prefix).

Returns: DomainBuildResult — DomainBuildResult with the domain array, warnings, and validity flag.

Method OdooToolkit.get_odoo_profile

Return a comprehensive Odoo server and environment snapshot.

Includes server version, transport, database, user context, and the list of installed modules (bounded by module_limit).

get_odoo_profile(include_modules: bool = True, module_limit: int = 100) -> OdooProfileResult

Parameter Type Default Description
include_modules bool True When True (default), queries ir.module.module for the installed module list.
module_limit int 100 Maximum number of installed modules to return (capped at 500).

Returns: OdooProfileResult — OdooProfileResult with version, transport, user context, and modules.

Method OdooToolkit.schema_catalog

List Odoo models with optional field metadata.

schema_catalog(query: Optional[str] = None, models: Optional[list[str]] = None, include_fields: bool = False, limit: int = 50) -> SchemaCatalogResult

Parameter Type Default Description
query Optional[str] None Substring to filter model names or display names.
models Optional[list[str]] None Explicit list of model technical names to include.
include_fields bool False When True, include fields_get metadata per model. Warning: each model's field metadata can be 50-200 KB; keep limit small (≤ 10) when using this option to avoid flooding the LLM context.
limit int 50 Maximum models to return (capped at 500).

Returns: SchemaCatalogResult — SchemaCatalogResult with model list and metadata.

Method OdooToolkit.inspect_model_relationships

Inspect relational fields and produce create/write hints for a model.

inspect_model_relationships(model: str) -> ModelRelationshipsResult

Parameter Type Default Description
model str Odoo model technical name (e.g. "sale.order").

Returns: ModelRelationshipsResult — ModelRelationshipsResult grouping fields by relation type with hints.

Method OdooToolkit.diagnose_access

Diagnose ACL and record-rule visibility for a model and operation.

diagnose_access(model: str, operation: str = 'read', domain: Optional[list[Any]] = None, record_ids: Optional[list[int]] = None) -> AccessDiagnosisResult

Parameter Type Default Description
model str Odoo model technical name.
operation str 'read' Operation to check ("read", "write", "create", or "unlink").
domain Optional[list[Any]] None Optional domain to check against record rules.
record_ids Optional[list[int]] None Specific record IDs to check visibility for.

Returns: AccessDiagnosisResult — AccessDiagnosisResult with ACL status, record rules, groups, and a human-readable diagnosis string.

Method OdooToolkit.health_check

Return a runtime posture report without making any Odoo network call.

Reports toolkit version, transport type, connection status, and the number of registered tools.

health_check() -> HealthCheckResult

Returns: HealthCheckResult — HealthCheckResult with runtime posture information.

Method OdooToolkit.search_employee

Search hr.employee records by name.

search_employee(name: str, limit: int = 20) -> list[HrEmployee]

Parameter Type Default Description
name str Employee name (partial match, case-insensitive).
limit int 20 Maximum employees to return (default 20).

Returns: list[HrEmployee] — List of typed :class:HrEmployee instances.

Raises:

  • OdooRPCError — When the HR module is not installed on the target instance (caught and re-raised with a clear message).

Method OdooToolkit.search_holidays

Search hr.leave (leave requests) within a date range.

search_holidays(start_date: str, end_date: str, employee_id: Optional[int] = None) -> list[HrLeave]

Parameter Type Default Description
start_date str Start of the date range (YYYY-MM-DD).
end_date str End of the date range (YYYY-MM-DD).
employee_id Optional[int] None Optional employee ID to filter results.

Returns: list[HrLeave] — List of typed :class:HrLeave instances.

Raises:

  • OdooRPCError — When the HR module is not installed.

Method OdooToolkit.diagnose_odoo_call

Preview and debug an execute_kw call without executing it.

Validates model name format, classifies method safety, checks transport compatibility, and flags Odoo 20 deprecation warnings.

diagnose_odoo_call(model: str, method: str, args: Optional[list[Any]] = None, kwargs: Optional[dict[str, Any]] = None, transport: str = 'auto', target_version: Optional[str] = None, observed_error: Optional[str] = None) -> OdooCallDiagnosisResult

Parameter Type Default Description
model str Odoo model technical name to validate.
method str ORM method name to classify.
args Optional[list[Any]] None Positional arguments (for payload shape analysis).
kwargs Optional[dict[str, Any]] None Keyword arguments (for payload shape analysis).
transport str 'auto' Transport type context for compatibility checks.
target_version Optional[str] None Target Odoo version (e.g. "20.0").
observed_error Optional[str] None Error message from a previous failed call attempt.

Returns: OdooCallDiagnosisResult — OdooCallDiagnosisResult with method safety, warnings, and next actions.

Method OdooToolkit.generate_json2_payload

Translate XML-RPC-style call into a JSON-2 endpoint + named body.

generate_json2_payload(model: str, method: str, args: Optional[list[Any]] = None, kwargs: Optional[dict[str, Any]] = None, base_url: Optional[str] = None, database: Optional[str] = None) -> Json2PayloadResult

Parameter Type Default Description
model str Odoo model technical name.
method str ORM method name.
args Optional[list[Any]] None Positional arguments (XML-RPC style list).
kwargs Optional[dict[str, Any]] None Keyword arguments.
base_url Optional[str] None Override base URL (defaults to toolkit config).
database Optional[str] None Override database name (defaults to toolkit config).

Returns: Json2PayloadResult — Json2PayloadResult with endpoint, headers, body, and notes.

Method OdooToolkit.scan_addons_source

Scan local Odoo addon directories for manifests and risky patterns.

Uses AST parsing — no addon code is imported or executed. The filesystem walk and AST parsing run in a thread pool to avoid blocking the event loop.

scan_addons_source(addons_paths: Optional[list[str]] = None, max_files: int = 200, max_file_bytes: int = 300000) -> AddonScanResult

Parameter Type Default Description
addons_paths Optional[list[str]] None Directories to scan. Must be under the server's configured allowed roots (path-traversal protection).
max_files int 200 Maximum Python files to parse (default 200).
max_file_bytes int 300000 Maximum bytes per file (default 300 KB).

Returns: AddonScanResult — AddonScanResult with discovered addons, model classes, risky methods, and any scan warnings.

Method OdooToolkit.fit_gap_report

Classify business requirements into fit/gap buckets.

fit_gap_report(requirements: list[dict[str, Any]], business_context: Optional[dict[str, Any]] = None) -> FitGapResult

Parameter Type Default Description
requirements list[dict[str, Any]] List of requirement dicts. Each should have at least a "description" key with the requirement text.
business_context Optional[dict[str, Any]] None Optional context metadata (industry, installed modules, etc.) to improve classification accuracy.

Returns: FitGapResult — FitGapResult with classified requirements, bucket summary, and recommended follow-up Odoo calls. Classification buckets: - "standard" — covered by a built-in Odoo module - "configuration" — achievable via settings/workflow changes - "studio" — no-code customization (Odoo Studio) - "custom_module" — requires a bespoke addon - "avoid" — anti-pattern (raw SQL, ORM bypass, etc.) - "unknown" — cannot be classified with available context

Method OdooToolkit.business_pack_report

Report expected modules, models, and live availability for a business pack.

business_pack_report(pack: str) -> BusinessPackResult

Parameter Type Default Description
pack str Business pack name — one of "sales", "crm", "inventory", "accounting", or "hr".

Returns: BusinessPackResult — BusinessPackResult with expected/installed/missing split.

Raises:

  • ValueError — When an unknown pack name is given.

Method OdooToolkit.odoo_shell_install_module

Install (or upgrade) one or more Odoo modules via odoo-bin.

Uses odoo-bin -d <db> -i <modules> --stop-after-init (or -u for upgrades). Requires the ODOO_BIN environment variable to point to the binary. This tool is HITL-gated: confirmation is required before execution.

odoo_shell_install_module(modules: list[str], database: Optional[str] = None, upgrade: bool = False) -> ShellResult

Parameter Type Default Description
modules list[str] Technical module names to install, e.g. ['sale', 'stock'].
database Optional[str] None Target database; defaults to ODOO_TEST_DATABASE.
upgrade bool False When True, upgrade (-u) instead of install (-i).

Returns: ShellResult — class:ShellResult with exit code, stdout, and stderr.

Method OdooToolkit.odoo_shell_upgrade_module

Upgrade one or more Odoo modules via odoo-bin -u.

Convenience wrapper around :meth:odoo_shell_install_module with upgrade=True. Requires the ODOO_BIN environment variable. This tool is HITL-gated: confirmation is required before execution.

Uses a dedicated :class:~parrot_tools.odoo.shell.OdooShellUpgradeInput schema that omits the upgrade flag — this tool always upgrades, and the LLM cannot accidentally set upgrade=False.

odoo_shell_upgrade_module(modules: list[str], database: Optional[str] = None) -> ShellResult

Parameter Type Default Description
modules list[str] Technical module names to upgrade.
database Optional[str] None Target database; defaults to ODOO_TEST_DATABASE.

Returns: ShellResult — class:ShellResult with exit code, stdout, and stderr.

Method OdooToolkit.odoo_cli_command

Run a whitelisted odoo-bin subcommand.

Allowed subcommands: scaffold, populate, db, shell, cloc, start. All other subcommands are rejected. This tool is HITL-gated: confirmation is required before execution.

odoo_cli_command(subcommand: str, args: Optional[list[str]] = None, database: Optional[str] = None) -> ShellResult

Parameter Type Default Description
subcommand str A whitelisted subcommand (see above).
args Optional[list[str]] None Additional positional arguments forwarded to the subcommand.
database Optional[str] None Target database; defaults to ODOO_TEST_DATABASE.

Returns: ShellResult — class:ShellResult with exit code, stdout, and stderr.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally