Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions base_external_system_odoorpc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
=============================
Base External System Odoo-rpc
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:20d12d3cfcde25ec6b4bf6bbe373bcaf9912377ac081a1dff9d9b4e5e4d7d036
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
:target: https://github.com/OCA/server-backend/tree/16.0/base_external_system_odoorpc
:alt: OCA/server-backend
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_external_system_odoorpc
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

============================
Base External System OdooRPC
============================

This module adds an *external system adapter* for connecting to another Odoo instance
using the Python ``odoorpc`` client (JSON-RPC).

It is built on top of ``base_external_system`` and implements a new adapter model:

* ``external.system.odoo`` (System Type: *External System RPC*)

The adapter supports:

* Validating required connection parameters (host, port, database, username, password)
* Optional SSL transport (JSON-RPC over SSL)
* A context-managed client lifecycle via the ``base_external_system`` adapter contract
(open client, perform calls, logout/cleanup)

Typical use cases include:

* Reading data from a legacy Odoo (e.g. Odoo 8/9/10) into a newer Odoo (e.g. Odoo 16)
* Synchronizations, migrations, or import tools that must query remote models
(e.g. ``stock.production.lot``, ``stock.move``, ``res.partner``) via RPC

**Table of contents**

.. contents::
:local:

Installation
============

This module requires the Python package ``odoorpc`` to be installed in the same
environment as your Odoo server.

Install it with pip, for example::

pip install odoorpc

Then install the Odoo module in the Apps menu as usual.

If you run Odoo in Docker or another containerized setup, ensure the dependency
is present in the image that runs the Odoo server.

Configuration
=============

1. Go to *Settings → External Systems* (menu provided by ``base_external_system``).
2. Create a new record.
3. Set **System Type** to *External System RPC* (``external.system.odoo``).
4. Fill in the connection parameters:

* Host (e.g. ``odoo-test.odoo.org``)
* Port (e.g. ``443`` or ``8069``)
* Database name
* Username
* Password
* SSL toggle (if applicable)

5. Save the record.

After saving, the adapter interface record is created automatically by
``base_external_system`` and is available via the ``interface`` field.

Usage
=====

Test connection (UI)


Open an external system record configured with System Type *External System RPC*
and click the *Test Connection* button.

If successful, the adapter will report success (using the success mechanism
provided by ``base_external_system``).

Using the client in code


Use the standard context manager from ``base_external_system``::

system = self.env.ref("your_module.external_system_odoo_remote")
with system.client() as odoo:
partner_model = odoo.env["res.partner"]
ids = partner_model.search([("is_company", "=", True)], limit=10)
data = partner_model.read(ids, ["name"])

The yielded object is an ``odoorpc.ODOO`` client instance, so any remote model can be
accessed via ``odoo.env["model.name"]``.

Legacy helper (optional)


Some projects historically called a helper directly on the adapter record::

odoo = system.interface._connect()

If your adapter keeps that helper for backward compatibility, it returns the same
client object as ``external_get_client()``.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_external_system_odoorpc%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Therp BV

Contributors
~~~~~~~~~~~~

* Therp BV <https://therp.nl>
* Nikos Tsirintanis <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/16.0/base_external_system_odoorpc>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions base_external_system_odoorpc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions base_external_system_odoorpc/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2026 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Base External System Odoo-rpc",
"summary": "Connect to a remote Odoo instance via the odoorpc library.",
"version": "16.0.1.0.0",
"category": "Base",
"website": "https://github.com/OCA/server-backend",
"author": "Therp BV, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["base_external_system"],
"external_dependencies": {"python": ["odoorpc"]},
"data": [
"demo/external_system_odoo_demo.xml",
"security/ir.model.access.csv",
"views/external_system_views.xml",
],
}
18 changes: 18 additions & 0 deletions base_external_system_odoorpc/demo/external_system_odoo_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2026 Therp BV <https://therp.nl>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="external_system_rpc" model="external.system">
<field name="name">External connection via RPC</field>
<field name="system_type">external.system.odoo</field>
<field name="host">localhost</field>
<field name="port">8069</field>
<field name="db_name">odoo16</field>
<field name="username">admin</field>
<field name="password">admin</field>
<field name="is_ssl">0</field>
<field name="company_ids" eval="[(5, 0), (4, ref('base.main_company'))]" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions base_external_system_odoorpc/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import external_system
from . import external_system_odoo
19 changes: 19 additions & 0 deletions base_external_system_odoorpc/models/external_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2026 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ExternalSystem(models.Model):
"""Extend base external system"""

_inherit = "external.system"

db_name = fields.Char(
string="Database",
help="Input database name",
)
is_ssl = fields.Boolean(
string="SSL",
help="Change protocol if SSL",
)
79 changes: 79 additions & 0 deletions base_external_system_odoorpc/models/external_system_odoo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2026 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging
from urllib.error import URLError

import odoorpc

from odoo import _, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)


class ExternalSystemOdoo(models.Model):
"""This is an Interface implementing the RPC module."""

_name = "external.system.odoo"
_inherit = "external.system.adapter"
_description = "External System RPC"

def external_get_client(self):
"""Return a usable client representing the remote system."""
self.ensure_one()
return self._connect()

def external_destroy_client(self, client):
"""Cleanup the client connection"""
self.ensure_one()
try:
if client:
client.logout()
except Exception as exc:
_logger.debug(
"Failed to logout OdooRPC client for %s: %s", self.display_name, exc
)
return super().external_destroy_client(client)

def external_test_connection(self):
"""Test connection in the UI."""
self.ensure_one()
try:
with self.client() as odoo:
user_model = odoo.env["res.users"]
ids = user_model.search([("login", "=", "admin")])
if not ids:
raise ValidationError(
_("Connected, but could not find admin user.")
)
user_model.read([ids[0]], ["name"])[0]
except ValidationError:
raise
except Exception as e:
raise ValidationError(_("Connection failed.\n\nDETAIL: %s") % e) from e
return super().external_test_connection()

def _connect(self):
"""Return connection object"""
self.ensure_one()
if not all([self.host, self.port, self.db_name, self.username, self.password]):
raise ValidationError(
_(
"Connection failed. Please make sure that all fields "
"are filled: Database, Host, Port, Username, Password."
)
)
try:
odoo = odoorpc.ODOO(
self.host,
port=self.port,
protocol="jsonrpc+ssl" if self.is_ssl else "jsonrpc",
)
except URLError as exc:
raise ValidationError(
_("Could not connect the Odoo server at %(host)s:%(port)s")
% {"host": self.host, "port": self.port}
) from exc
odoo.login(self.db_name, self.username, self.password)
return odoo
16 changes: 16 additions & 0 deletions base_external_system_odoorpc/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. Go to *Settings → External Systems* (menu provided by ``base_external_system``).
2. Create a new record.
3. Set **System Type** to *External System RPC* (``external.system.odoo``).
4. Fill in the connection parameters:

* Host (e.g. ``odoo-test.odoo.org``)
* Port (e.g. ``443`` or ``8069``)
* Database name
* Username
* Password
* SSL toggle (if applicable)

5. Save the record.

After saving, the adapter interface record is created automatically by
``base_external_system`` and is available via the ``interface`` field.
2 changes: 2 additions & 0 deletions base_external_system_odoorpc/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Therp BV <https://therp.nl>
* Nikos Tsirintanis <[email protected]>
23 changes: 23 additions & 0 deletions base_external_system_odoorpc/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
============================
Base External System OdooRPC
============================

This module adds an *external system adapter* for connecting to another Odoo instance
using the Python ``odoorpc`` client (JSON-RPC).

It is built on top of ``base_external_system`` and implements a new adapter model:

* ``external.system.odoo`` (System Type: *External System RPC*)

The adapter supports:

* Validating required connection parameters (host, port, database, username, password)
* Optional SSL transport (JSON-RPC over SSL)
* A context-managed client lifecycle via the ``base_external_system`` adapter contract
(open client, perform calls, logout/cleanup)

Typical use cases include:

* Reading data from a legacy Odoo (e.g. Odoo 8/9/10) into a newer Odoo (e.g. Odoo 16)
* Synchronizations, migrations, or import tools that must query remote models
(e.g. ``stock.production.lot``, ``stock.move``, ``res.partner``) via RPC
11 changes: 11 additions & 0 deletions base_external_system_odoorpc/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module requires the Python package ``odoorpc`` to be installed in the same
environment as your Odoo server.

Install it with pip, for example::

pip install odoorpc

Then install the Odoo module in the Apps menu as usual.

If you run Odoo in Docker or another containerized setup, ensure the dependency
is present in the image that runs the Odoo server.
Loading