Skip to content

Extending and modifying Cetmix Tower

As Cetmix Tower is an Odoo app, you can extend and modify it the same way as any other Odoo module. Refer to the official Odoo documentation on extending modules.

Adding custom Python libraries

A typical use case: adding custom Python libraries to make them available in Python commands.

Prerequisites

Create a custom Odoo module that depends on cetmix_tower_server and inherit cx.tower.command.

Implementation

Override the _custom_python_libraries() method on the cx.tower.command model (see Commands). It must return a dict in this format:

{
    "<module_name>": {
        "<library_name>": {
            "import": <library_object>,
            "help": "<html_help_text>",  # Shown in the Help tab
        },
    },
}
  • module_name: Odoo module technical name
  • library_name: Name used in Python command code (e.g. boto3)
  • import: The library object to expose
  • help: HTML string shown in the command Help tab (use _() for translatable text)

Security

Python commands run in Odoo's safe_eval context. Use odoo.tools.safe_eval.wrap_module() to allow only the methods/attributes that should be accessible. Raw imports may expose unsafe APIs.

Example from the cetmix_tower_aws module:

from odoo import _, models
from odoo.tools.safe_eval import wrap_module

# Wrap boto3 at module level so the wrapping runs once, not on every command execution
boto3 = wrap_module(__import__("boto3"), ["client", "resource", "Session"])


class CxTowerCommand(models.Model):
    """Extends cx.tower.command to add AWS boto3 functionality."""

    _inherit = "cx.tower.command"

    def _custom_python_libraries(self):
        """
        Add the boto3 library to the available libraries.
        """
        custom_python_libraries = super()._custom_python_libraries()
        custom_python_libraries.update(
            {
                "cetmix_tower_aws": {
                    "boto3": {
                        "import": boto3,
                        "help": _(
                            "Python 'boto3' library for AWS services. "
                            "Available methods: 'client', 'resource', 'Session'<br/>"
                            "Supports AWS services like EC2, S3, RDS, Lambda, "
                            "CloudWatch, etc.<br/>"
                            "Please check the <a "
                            "href='https://boto3.amazonaws.com/v1/documentation/api/latest/index.html'"
                            " target='_blank'>Boto3 Documentation</a> for the detailed "
                            "information about the services and methods."
                        ),
                    },
                }
            }
        )
        return custom_python_libraries