Skip to content

Task 1.2 Create the odf_core Odoo Module #10

@bosd

Description

@bosd

Task 1.2 Create the odf_core Odoo Module

Mission Context:
This task is based on the Project Constitution's vision for an Odoo-integrated "mission control" center. You will build the foundational module, odf_core, which allows users to configure and orchestrate odoo-data-flow operations directly from the Odoo user interface. This moves the system away from being a command-line-only utility and empowers functional users by providing a secure, manageable, and observable platform for data synchronization.

Core Objective:
Create a new, installable Odoo 18 module named odf_core that provides models, views, and logic to manage database connections and orchestrate data flow projects by directly invoking the odoo-data-flow Python library.

Desired Outcome:
A self-contained Odoo module located in the modules/ directory. When installed, a user will be able to configure database connections and define data flow projects through a dedicated "Data Flow" menu. A scheduled action will periodically run these projects, updating their status in the UI. The execution will be handled safely through direct Python library calls, with detailed logs created for any errors, ensuring the system is both secure and easy to debug.

Required inputs:

  • Project Constitution: Project Constitution_ odoo-data-flow Next-Generation v3.md
  • Git Branch: j-base

Visual Workflow (Mermaid):
This diagram illustrates the logic for the scheduled action that executes the data flow projects.

graph TD
    A[Start: Scheduled Action Triggers] --> B{Get active projects where status is NOT 'running'};
    B --> C[Loop through each project];
    C --> D[Set project status to 'running' & commit];
    D --> E{try...except block};
    E -- "try" --> F[Import 'odoo_data_flow' library];
    F --> G[Call library function with project config];
    G --> H[Set project status to 'done'];
    E -- "except Exception as e" --> I[Log detailed exception 'e'];
    I --> J[Set project status to 'failed'];
    J --> K[Next Project];
    H --> K;
    K --> C;
    C -- "End of Loop" --> L[End];
Loading

The Process / Workflow:

  1. Module Scaffolding:
    • Work from the j-base git branch.
    • Create the directory structure for a new Odoo module named odf_core inside the modules/ folder.
    • Create the __init__.py and __manifest__.py files.
    • In __manifest__.py, set version to 18.0.1.0.0, author to Odoo Data Flow, and declare dependencies on base.
  2. Model Definition - Connection: In models/odf_connection.py, define the odf.connection model:
    • name: fields.Char, required.
    • host: fields.Char, required.
    • port: fields.Integer, required, default 5432.
    • dbname: fields.Char, required.
    • user: fields.Char, required.
    • password: fields.Char, with the attribute password=True to obscure it in the UI.
    • Add a method with a button on the form view to test the connection.
  3. Model Definition - Flow Project: In models/odf_flow_project.py, define the odf.flow.project model:
    • name: fields.Char, required.
    • active: fields.Boolean, default True.
    • source_connection_id: fields.Many2one to odf.connection, required.
    • destination_connection_id: fields.Many2one to odf.connection, required.
    • flow_file_path: fields.Char, representing the path to the flows.yml file.
    • status: fields.Selection with states: [('new', 'New'), ('running', 'Running'), ('done', 'Done'), ('failed', 'Failed')]. Default to 'new'.
  4. Orchestration Logic: In the odf.flow.project model file, create a method to be called by the scheduled action.
    • This method must iterate through active projects whose status is not 'running'.
    • For each project, it must first update the status to 'running' and immediately commit the transaction (self.env.cr.commit()) to prevent race conditions.
    • Wrap the core logic in a try...except... block.
    • Inside the try block: Securely import the odoo_data_flow library and call its main execution function, passing the necessary configuration derived from the project and connection records.
    • Inside the except block: Catch any exceptions, log a detailed error message using _logger.error() including the project name and the full exception traceback, and set the project status to 'failed'.
    • If the try block completes successfully, set the project status to 'done'.
  5. Scheduled Action: In data/scheduled_actions.xml, create an ir.cron record that calls the orchestration method. Configure it to run hourly.
  6. User Interface:
    • In views/odf_connection_views.xml, create Form and Tree views for the odf.connection model.
    • In views/odf_flow_project_views.xml, create Form and Tree views for the odf.flow.project model. The tree view should display name and status. The form view should allow editing all fields.
    • In views/menus.xml, create a main menu "Data Flow" and sub-menus for "Projects" and "Configuration > Connections".
  7. Security: In security/ir.model.access.csv, provide full access (Read, Write, Create, Unlink) for the base.group_user group to both the odf.connection and odf.flow.project models.

Anticipated Pitfalls:

  • Security Vulnerability: The agent may be tempted to use os.system or subprocess. This is a critical failure. The implementation must use direct Python library imports.
  • Missing Dependency: The logic will assume the odoo-data-flow Python package is installed and available in the Python environment where Odoo is running. The prompt does not cover its installation.
  • Transaction Management: A long-running data flow process could hold a database transaction open for too long. Committing the status change to 'running' before starting the main work is essential.
  • Filesystem Brittleness: The flow_file_path is a known weakness that makes the system dependent on the server's filesystem. While required for this task, it is a design smell that will be addressed in a future task by storing the configuration in the database.

Acceptance Criteria / Verification Steps:

  1. The odf_core module is created in the modules/ directory of the j-base branch.
  2. The module installs cleanly in a fresh Odoo 18 database.
  3. The "Data Flow" menu and its submenus for "Projects" and "Connections" are visible and accessible.
  4. A user can successfully create, edit, and save a Connection record.
  5. A user can successfully create, edit, and save a Project record, linking it to two connections.
  6. When the scheduled action is triggered manually, the status of an active project changes from 'new' to 'running' and then to either 'done' or 'failed'.
  7. If the underlying library call were to fail, a detailed error message (including the Python exception) is written to the Odoo server log, and the project status is set to 'failed'.

Strict Constraints / Rules to Follow:

  • You are strictly forbidden from using os.system, subprocess.run, or any other method of executing shell commands. All execution must be done by importing odoo_data_flow as a Python library.
  • The module must target Odoo version 18.
  • The author in the manifest must be exactly "Odoo Data Flow".
  • All new files must be placed within the modules/odf_core/ directory structure.

Proceed with the task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    JulesGoogle Jules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions