Skip to content
OpenDigitalCCPublic

About

Bridging Odoo Object Mapper

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

531 Commits

Folders and files

Repository files navigation

oom — Odoo Object Mapper (Perl)

Perl access to the whole Odoo object tree with as little pre-knowledge of the schema as possible. Successor to OpusVL's OpenERP-OOM (assessment: ANALYSIS.md; the inherited source is under inbox/archive/). No code generation: the schema comes from the server at runtime via fields_get.

OOM is a layer that exposes Odoo's workings outside Odoo, with some helpers to orchestrate; the calling program is responsible for its workflows and the management of their execution. docs/PURPOSE.md says where OOM's work stops; read it before writing a spec.

An AI agent driving oom-ops or the tools reads docs/AGENT-GUIDE.md first (installed in /usr/share/doc/libodoo-oom-perl/; oom-ops guide prints its path).

Status

Mapper: client, model read and write paths, record objects (Odoo::Record/Odoo::RecordSet with lazy loading, relation traversal, dirty-tracked saves), the per-model behaviour overlay, fault classes and HTTP policy. Operations layer and its packs: tested offline, and live on the disposable Odoo instances (16, 18 and 19; oom-ops matrix names the test and the series of each operation).

Layout

  • lib/Odoo/Client.pm — session, auth (API key), execute_kw, default context, transport-error retry ladder
  • lib/Odoo/Model.pm — lazy per-model handle: discovery (fields, describe, selections, relations) and reads (search, search_read, read, all stable paging, count, …)
  • lib/Odoo/Transport/JSONRPC.pm — default backend, core modules only
  • lib/Odoo/Transport/XMLRPC.pm — alternative backend (XML::LibXML codec); use where a proxy gates /jsonrpc
  • lib/Odoo/Transport/JSON2.pm — Odoo 19's /json/2 (API key as bearer); same execute_kw surface
  • lib/Odoo/Record.pm — one record: schema-driven field accessors, lazy loading (lean default read, on-demand fetch for binary/x2many/non-stored fields), relation traversal, dirty tracking with save-only-what-changed
  • lib/Odoo/RecordSet.pm — an ordered set: free construction, whole-set prefetch in one read (no N+1), iteration
  • lib/Odoo/Commands.pm — the x2many write-command grammar with names and validation (x2m_create, x2m_set, …) instead of bare [0,0,{…}] triplets
  • lib/Odoo/Error.pm — typed exceptions; only transport errors are retried

Operations layer (Odoo::Ops, bin/oom-ops)

Above the mapper: named operations that plan before they write, apply once through a journal, read their writes back, and can plan their own revert; a transport guard that refuses calls outside an operation's declared scope; per-series logical profiles (profiles/). First function packs: CRM (crm.inspect, crm.export, crm.import, crm.tag, crm.assign), messages (comms.render, comms.send) and mailing over Odoo's mass mailing (mailing.*: lists, contacts, a mailshot, its test, send and progress). Packs that ship apart from the library, in packs/ (packs/README.md): shop (an online shop page, Odoo 16 and 18.0), pay (a card payment taken outside Odoo, 18.0), credit, recon and crm_page. Guide: docs/OPS.md.

Three packages

The Debian build makes three binary packages from this tree. libodoo-oom-perl is OOM itself: the mapper, the operations layer and oom-ops. odoo-oom-packs holds the packs of packs/, without their tests. odoo-oom-tools is the workflow built on it: oom-accounts (accounts and roles for an external application) and oom-mailshot (a mailing from contacts to progress), modules Odoo::Tools::*. A tool composes operations and carries the rules around them; OOM stays the primitives. The tools package (which also holds oomd, the resident OOM, and its systemd user unit) depends on the library of the same version; the packs package on that version or later.

Documentation

  • docs/use-cases/ — what OOM has been used for, each with its proof and example files: a migration project (docs/examples/migration/), Odoo as a headless ERP, configuration as code, CRM operations, a web platform (lazysite) on Odoo
  • docs/MIGRATION-TOOLS.md — the earlier migration tools read and mapped onto OOM
  • docs/AGENT-GUIDE.md — the guide an AI agent reads first: the loop, the errors, undo and the mailshot
  • docs/OPS.md — the operations layer, oom-ops, and the tools (oom-accounts, oom-mailshot)
  • docs/MAPPER-SPEC.md — draft specification for the lazysite Odoo extension (SM747's mapper seam)
  • docs/USAGE.md — configuration and usage guide (install, Odoo-side setup, client options, read/write patterns, auth, error handling)
  • docs/TEST-PLAN.md — the cross-version test plan (Odoo 16 → 20) for the disposable test instance
  • perldoc Odoo::Client (and friends) — API reference
  • ANALYSIS.md — design rationale and assessment of the inherited source

Quick start

use Odoo::Client;

my $odoo = Odoo::Client->new(
    url          => 'https://example.odoohost.net',
    db           => 'example-db',
    login        => 'integration-user',
    api_key_file => '/path/to/key',
    transport    => 'xmlrpc',
    context      => { lang => 'en_GB' },
);

my $so = $odoo->model('sale.order');          # nothing pre-declared
say for $so->field_names;                     # live schema
my $rows = $so->search_read([['state','=','sale']],
                            ['name','partner_id'], limit => 10);

# writes; x2many values through the named command grammar
use Odoo::Commands qw(:all);
my $partner = $odoo->model('res.partner');
my $id = $partner->create({
    name      => 'ACME',
    child_ids => [ x2m_create({ name => 'Billing', type => 'invoice' }) ],
});
$partner->write($id, { child_ids => [ x2m_set([42, 43]) ] });
$partner->unlink($id);

# records: lazy, traversable, dirty-tracked
my $rec = $partner->browse($id);          # free - loads on first touch
say $rec->name;
say $rec->parent_id->name if $rec->parent_id;      # many2one -> Record
say $_->name for $rec->child_ids->records;         # x2many -> RecordSet
$rec->name('Renamed');
$rec->save;                                        # writes only the dirty fields
my $order = $odoo->model('sale.order')->find([['name', '=', 'S01603']]);
say $order->dt('date_order')->ymd if $order;

Behaviour overlay

Business methods live in hand-written classes, discovered by convention — field plumbing never does. With Odoo::Client->new(..., overlay => 'MyApp::Odoo'), records of sale.order.line bless into MyApp::Odoo::SaleOrderLine (if it exists) in front of Odoo::Record: its methods win over field accessors, shadowed fields stay reachable via get/set, and models without an overlay class use the plain records.

Authenticating end users

An application can use its own service connection to check a person's Odoo credentials:

my $uid = $odoo->verify_credentials($login, $secret);   # uid or undef

$secret is the user's password or any of their Odoo API keys — the RPC surface accepts either, so no API key is required. The exception is a user with two-factor authentication enabled: Odoo refuses RPC password logins for them, and they must use an API key. Transport failures still die, so an unreachable server is never reported as a wrong password.

Tests

./scripts/run-tests.sh          # unit tests, offline, from any cwd

The integration tests auto-skip unless tmp/live-test.conf exists (or ODOO_OOM_TEST_CONF points elsewhere) — key=value lines: url, db, login, api_key_file or api_key, transport, lang. tmp/ is gitignored; keep credentials there or outside the tree.

t/98-integration-write.t additionally requires allow_writes = 1 in the config, so a read-only target can never be written to by accident. It cleans up everything it creates, even on failure.

Licence

Intended licence: the same terms as Perl itself (Artistic / GPL-1+). The library is an independent client of Odoo's published external RPC API: it contains no Odoo code, links against nothing from Odoo, and everything it knows about a schema it asks the server for at runtime. Communicating with an LGPL-3 program over a network protocol does not make a client a derivative work, so Odoo's licence places no constraint here. (The predecessor OpenERP-OOM shipped under the Perl terms on the same basis.) The archived Cygnus/Aquarius trees are under an OpusVL IP-assignment schedule and remain reference-for-intent only — no code from them is, or may be, copied into this tree.

Dependencies

Perl ≥ 5.36. Debian packages only: everything used is core (HTTP::Tiny, JSON::PP) or already installed (XML::LibXML, IO::Socket::SSL for https). Cpanel::JSON::XS (libcpanel-json-xs-perl) is recommended: it decodes Odoo's answers about a hundred times faster, and OOM uses JSON::PP without it.

About

Bridging Odoo Object Mapper

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages