# Odoo Workflow Automation Suite: CC

A suite of tools to streamline Odoo development — project switching, database management, tickets, Odoo SH, and more. Includes a CLI and a VS Code extension.

## Features

* **Project Switching**: Switch between Odoo projects, auto-updating `launch.json` and `odoo.cfg`.
* **Multi-version Support**: Optionally maintain one active project per Odoo version simultaneously.
* **Module Management**: Interactively update the module list for the active project.
* **Database Management**: Initialize, copy, and restore databases.
* **Ticket & GitHub**: Open project tickets and GitHub repos from the terminal.
* **Odoo SH**: Open the Odoo SH environment for the current project.
* **Configuration Wizard**: Auto-detect Odoo versions, download paths, IDE, and more via `cc config`.

## How it works

CC detects your Odoo codebase by locating `odoo-bin` and resolving the correct addons paths (enterprise, odoo/addons, design-themes, project internals). As long as `odoo-bin` is found, `cc` will configure your `launch.json` correctly.

> **Multiple Odoo versions**: CC supports multiple codebases side by side (e.g. v16, v17, v18). Enable multi-version mode via `cc config` to keep one active project per version.

## CLI Commands

| Command   | Description                                                                                                                                                                                                   |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cd`      | Change directory to the active project's path.                                                                                                                                                                |
| `cloc`    | Get code line count statistics for a project.                                                                                                                                                                 |
| `config`  | Configure CC settings and Odoo versions. Runs an interactive wizard with no args. Use `-l` to list values, `-v NAME PATH` to add a version, `-r NAME` to remove one, or `KEY VALUE` to set non-interactively. |
| `copy`    | Create a copy of a database.                                                                                                                                                                                  |
| `db`      | Manage the database parameter in `launch.json` for the active environment.                                                                                                                                    |
| `env`     | Manage project environments (add, list, remove).                                                                                                                                                              |
| `fetch`   | Fetch all Git versions of the Odoo source code.                                                                                                                                                               |
| `github`  | Open the GitHub repository for the current project.                                                                                                                                                           |
| `initdb`  | Initialize a database from a zip file dump.                                                                                                                                                                   |
| `module`  | Update the module list in `launch.json` for the active project.                                                                                                                                               |
| `new`     | Create a new Odoo module from a template.                                                                                                                                                                     |
| `psx`     | Open PSX runbot for tests.                                                                                                                                                                                    |
| `restore` | Restore a database from a previously created copy.                                                                                                                                                            |
| `sh`      | Open the Odoo SH page for the current project.                                                                                                                                                                |
| `stat`    | Show the status of the active project environments.                                                                                                                                                           |
| `switch`  | Switch the active project, updating `launch.json` and `odoo.cfg`. Use `-s` to switch without opening the IDE.                                                                                                 |
| `time`    | View today's project switching log for timesheet generation. Use `-d YYYY-MM-DD` for a specific date, `--stop` to punch out, `--clear-flags` to review flagged spans.                                         |
| `ticket`  | Open an Odoo ticket from the current Git branch or manifest `odoo_task_ids`.                                                                                                                                  |
| `version` | Switch between Odoo versions in VS Code.                                                                                                                                                                      |

## VS Code Extension

The `cc-vscode-extension` provides quick-pick menus for switching projects, updating modules, and changing databases directly from VS Code. Still a WIP.

**Installation:**

1. Install the CLI tool as described below.
2. In VS Code, open the Extensions view.
3. Click `...` → `Install from VSIX...`.
4. Select the `.vsix` file from the `cc-vscode-extension` directory.
5. Set `cc.cliPath` in VS Code settings to the absolute path of the `cc` CLI folder.

## Installation

**Prerequisites:** Python (Pyenv recommended), Git, an Odoo environment.

1. **Clone the repository:**

   ```bash
   git clone git@github.com:chronofeldyx/cc.git
   ```
2. **Run the installer:**

   ```bash
   chmod +x installer.sh
   ./installer.sh
   ```
3. **Enable autocomplete** — add to your `.bashrc` or `.zshrc`:

   ```bash
   eval "$(register-python-argcomplete cc)"
   ```

## Usage

All CC data is stored in a SQLite database at `~/.cc-cli/cc_cli.db`.

### Configure

```bash
cc config
```

Runs the interactive setup wizard — auto-detects Odoo versions and download path, prompts for IDE and other settings. Run `cc config -l` to inspect current values at any time.

### Switch Projects

```bash
cc switch <project_alias>
```

Switches the active project and opens it in your IDE. If the alias doesn't exist it will be discovered and created. Use `-s` to switch silently (no IDE open).

### Manage Modules

```bash
cc module
```

Interactive prompt to select which modules to add for the current project. Use `-r` to replace the module list entirely.

### Initialize a Database

```bash
cc initdb <database_name>
```

Prompts you to select a `.zip` dump from your downloads folder and initializes it as a new database.

### Copy a Database

```bash
cc copy <database_name>
```

Creates a new PostgreSQL database named `<database_name>-CC-COPY`.

### Restore a Database

```bash
cc restore <database_name>
```

Restores from a copy named `<database_name>-CC-COPY`.

### Open Odoo SH

```bash
cc sh
```

Opens the Odoo SH page for the current project. Use `-u` to sync new projects.

### Open a Ticket

```bash
cc ticket
```

Opens the ticket associated with the current Git branch or the project's manifest `odoo_task_ids`.

### Open GitHub

```bash
cc github
```

Opens the GitHub repository for the project in the current working directory.
