diff --git a/.gitignore b/.gitignore index e1d90e14..f6fcafc4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__ addons tmp default.vim -managed-modules \ No newline at end of file +managed-modules +venv \ No newline at end of file diff --git a/README.md b/README.md index 5b899f5b..b6df72e0 100644 --- a/README.md +++ b/README.md @@ -5,39 +5,25 @@ The Mint System Odoo development environment. This projects provides a highly opiniated way to develope Odoo and Odoo modules. It supports the following scenarios: -**Docker Compose** - -Spin up a Odoo, Postgres and PGadmin Docker container and experiment locally. - -**Import and Export Database** - -Use Odoo scripts to copy and restore a remote customer database in the local development environment. Investigate issues and deploy the database at whish. - -**Community Edition** - -Checkout the Odoo Community Edition and start editing source code. - -**Enterprise Modules** - -Checkout the Odoo enterprise modules and deploy them into the Odoo Docker container or the Odoo source. - -**Develope Modules** - -Scaffold a new module and develope new Odoo features locally. +* **Docker Compose**: Spin up a Odoo, Postgres and pgAdmin Docker container and experiment locally. +* **Import and Export Database**: Use Odoo scripts to copy and restore a remote customer database in the local development environment. Investigate issues and deploy the database at whish. +* **Community Edition**: Checkout the Odoo Community Edition and start editing the source code. +* **Enterprise Modules**: Checkout the Odoo enterprise modules and deploy them into the Odoo Docker container or the Odoo source. +* **Develope Modules**: Scaffold a new module and develope new Odoo features locally. ## Requirements The Odoo development environment has the following requirements: -* [Odoo Scripts](https://github.com/Mint-System/Ansible-Playbooks/tree/master/roles/odoo-scripts/files) +* [Odoo Scripts](https://github.com/Mint-System/Ansible-Playbooks/tree/master/roles/odoo-scripts) * [Docker Compose](https://docs.docker.com/compose/) * Python 3.7.X -* wkhtmltopdf -* bash/zsh alias `task='task'` +* [wkhtmltopdf](https://wkhtmltopdf.org/) +* bash/zsh alias: `task='task'` ## Usage -The usage section is set of recipes. Pick the one required according the scenarios. +The usage section is set of recipes. Pick the one required according to your scenario. Clone this repository. @@ -48,9 +34,9 @@ cd odoo-development ### Docker -Run Odoo as Docker container. +Run Odoo with Docker container. -#### Install Odoo with Docker +#### Start and initialize Odoo with Docker Run docker compose. @@ -66,51 +52,12 @@ docker-odoo-install Open browser to [http://localhost:8069](http://localhost:8069) and login with `admin:admin`. -#### Create new module with Docker - -Scaffold a new module. - -```bash -task src-scaffold sales-customization -``` - -Restart Odoo. - -```bash -docker restart odoo -``` - #### Install custom module with Odoo scripts ```bash docker-odoo-install -m show_db_name ``` -#### Create new database with Docker - -```bash -docker exec -it odoo bin/bash -createdb -h $HOST -U $USER odoo2 --locale=de_CH.utf8 --template=template0 -# Enter password -psql -h $HOST -U $USER -l -# Enter password -odoo -i base,web -c /etc/odoo/odoo.conf -d odoo2 --db_host $HOST -r $USER -w $PASSWORD --without-demo=all --stop-after-init -# Exit -docker restart odoo -``` - -Open [http://localhost:8069/?db=Test](http://localhost:8069/?db=Test) in your browser. - -#### Delete database with Docker - -```bash -docker exec -it odoo bin/bash -psql -h $HOST -U $USER -l -# Enter password -dropdb -h $HOST -U $USER mint-system -# Enter password -``` - #### Save config with Docker ```bash @@ -125,9 +72,7 @@ Run Odoo from source. Create and activate the virutal env. ```bash -cd odoo -python3 -m venv venv -source venv/bin/activate +task venv-init ``` #### Install Odoo source requirements @@ -136,51 +81,57 @@ Pull the `odoo` submodule and install the python dependencies. ```bash git submodule update odoo -cd odoo -pip install setuptools wheel watchdog phonenumbers -pip install -r requirements.txt +task install-src ``` **Py3o Report Engine** -If you are using the py3o report engine additional packages are required: +If you are using the Py3o report engine additional packages are required: ```bash +cd odoo pip install py3o.template py3o.formats -# Macos +cd .. +# MacOS brew cask install libreoffice # Ubuntu apt-get --no-install-recommends install libreoffice ``` -#### Run database container only +#### Initialize and start Odoo from source + +Run database container only ```bash task start-db ``` -#### Install Odoo from source +Initialize database ```bash -task src-install +task install-src ``` -#### Start Odoo from source +Start Odoo from source ```bash task start-src ``` +Open browser to [http://localhost:8069](http://localhost:8069) and login with `admin:admin`. + #### Create a new module from source +Scaffold a new module. ```bash -cd odoo -./odoo-bin scaffold project_report ../addons +task scaffold-src project_report ``` ### Common +Instructions that are true for Docker and Source usage paths. + #### Enable developer mode Open this url [http://localhost:8069/web?debug=1](http://localhost:8069/web?debug=1), which contains the debug flag. @@ -203,10 +154,16 @@ docker-compose down -v task stop ``` +#### Remove database + +```bash +task drop-db odoo +``` + #### Install Odoo REST API dependencies ```bash -pip install -r addons/rest_api/requirements.txt +pip install -r addons/rest_api/requirements.txt ``` Or with Docker: @@ -216,6 +173,10 @@ docker exec odoo pip3 install -r /mnt/extra-addons/rest_api/requirements.txt docker restart odoo ``` +### Managed Modules + +Manage Odoo modules. + #### Setup managed modules Update the entries in the list `managed_modules.txt`. diff --git a/config/odoo-src.conf b/config/odoo-src.conf index d175ef7e..3c5405d6 100644 --- a/config/odoo-src.conf +++ b/config/odoo-src.conf @@ -1,3 +1,3 @@ [options] -;addons_path = addons -addons_path = addons,../addons,../oca/management-system,../oca/knowledge,../oca/crm,../oca/project,../oca/reporting-engine \ No newline at end of file +addons_path = addons,../addons +;addons_path = addons,../addons,../oca/management-system,../oca/knowledge,../oca/crm,../oca/project,../oca/reporting-engine \ No newline at end of file diff --git a/task b/task index 1dc163a9..d7756383 100755 --- a/task +++ b/task @@ -16,20 +16,43 @@ function log() { docker logs odoo -f } +function venv-init() { + python3 -m venv venv + source venv/bin/activate +} -function src-install() { +function activate-venv() { + source ../venv/bin/activate +} + +function locale() { + export LC_ALL=en_US.UTF-8 + export LANG=en_US.UTF-8 +} + +function install-src() { cd odoo - source venv/bin/activate && ./odoo-bin --addons-path=addons --init base,web -d odoo --db_host=localhost -r odoo -w odoo --dev all + activate-venv + pip install setuptools psycopg2-binary watchdog phonenumbers + pip install -r requirements.txt + cd .. +} + +function init-db() { + cd odoo + locale + activate-venv && ./odoo-bin --init base,web -d odoo --db_host=localhost -r odoo -w odoo --stop-after-init cd .. } function start-src() { cd odoo - source venv/bin/activate && ./odoo-bin --config=../config/odoo-src.conf --db_host=localhost -r odoo -w odoo --dev all + locale + activate-venv && ./odoo-bin --config=../config/odoo-src.conf --db_host=localhost -r odoo -w odoo --dev=all cd .. } -function src-scaffold() { +function scaffold-src() { if test -z "$1" then echo "\$1 is empty" @@ -40,6 +63,16 @@ function src-scaffold() { fi } +function drop-db() { + if test -z "$1" + then + echo "\$1 is empty" + else + psql postgres://odoo:odoo@localhost/postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$1';" + psql postgres://odoo:odoo@localhost/postgres -c "DROP DATABASE $1;" + fi +} + case "$1" in start) start @@ -53,14 +86,23 @@ case "$1" in start-db) start-db ;; - src-install) - src-install + venv-init) + venv-init + ;; + install-src) + install-src + ;; + init-db) + init-db ;; start-src) start-src ;; - src-scaffold) - src-scaffold $2 + scaffold-src) + scaffold-src $2 + ;; + drop-db) + drop-db $2 ;; compile-managed-modules) ./scripts/compile-managed-modules @@ -72,6 +114,6 @@ case "$1" in ./scripts/remove-managed-modules ;; *) - echo $"Usage: $0 {start||stop|start-db|src-install|start-src|src-scaffold|compile-managed-modules|copy-managed-modules|remove-managed-modules}" + echo $"Usage: $0 {start||stop|start-db|install-src|init-db|start-src|scaffold-src|drop-db|compile-managed-modules|copy-managed-modules|remove-managed-modules}" exit 1 esac