-
Notifications
You must be signed in to change notification settings - Fork 1
Task 1.2 Create the odf_core Odoo Module #10
Description
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];
The Process / Workflow:
- Module Scaffolding:
- Work from the
j-basegit branch. - Create the directory structure for a new Odoo module named
odf_coreinside themodules/folder. - Create the
__init__.pyand__manifest__.pyfiles. - In
__manifest__.py, setversionto18.0.1.0.0,authortoOdoo Data Flow, and declare dependencies onbase.
- Work from the
- Model Definition - Connection: In
models/odf_connection.py, define theodf.connectionmodel:name:fields.Char, required.host:fields.Char, required.port:fields.Integer, required, default5432.dbname:fields.Char, required.user:fields.Char, required.password:fields.Char, with the attributepassword=Trueto obscure it in the UI.- Add a method with a button on the form view to test the connection.
- Model Definition - Flow Project: In
models/odf_flow_project.py, define theodf.flow.projectmodel:name:fields.Char, required.active:fields.Boolean, defaultTrue.source_connection_id:fields.Many2onetoodf.connection, required.destination_connection_id:fields.Many2onetoodf.connection, required.flow_file_path:fields.Char, representing the path to theflows.ymlfile.status:fields.Selectionwith states:[('new', 'New'), ('running', 'Running'), ('done', 'Done'), ('failed', 'Failed')]. Default to'new'.
- Orchestration Logic: In the
odf.flow.projectmodel 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
tryblock: Securely import theodoo_data_flowlibrary and call its main execution function, passing the necessary configuration derived from the project and connection records. - Inside the
exceptblock: 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
tryblock completes successfully, set the project status to'done'.
- This method must iterate through active projects whose status is not
- Scheduled Action: In
data/scheduled_actions.xml, create anir.cronrecord that calls the orchestration method. Configure it to run hourly. - User Interface:
- In
views/odf_connection_views.xml, create Form and Tree views for theodf.connectionmodel. - In
views/odf_flow_project_views.xml, create Form and Tree views for theodf.flow.projectmodel. The tree view should displaynameandstatus. 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".
- In
- Security: In
security/ir.model.access.csv, provide full access (Read, Write, Create, Unlink) for thebase.group_usergroup to both theodf.connectionandodf.flow.projectmodels.
Anticipated Pitfalls:
- Security Vulnerability: The agent may be tempted to use
os.systemorsubprocess. This is a critical failure. The implementation must use direct Python library imports. - Missing Dependency: The logic will assume the
odoo-data-flowPython 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_pathis 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:
- The
odf_coremodule is created in themodules/directory of thej-basebranch. - The module installs cleanly in a fresh Odoo 18 database.
- The "Data Flow" menu and its submenus for "Projects" and "Connections" are visible and accessible.
- A user can successfully create, edit, and save a Connection record.
- A user can successfully create, edit, and save a Project record, linking it to two connections.
- When the scheduled action is triggered manually, the
statusof an active project changes from 'new' to 'running' and then to either 'done' or 'failed'. - 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 importingodoo_data_flowas 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.