From c873aeef1fe4c43dcc283f914bb907ab2b7f679e Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Thu, 13 Jun 2024 10:14:33 +0200 Subject: [PATCH] feat: template and new task command --- addons/partner_contact | 2 +- task | 24 +++ task.md | 147 +++++++++--------- template/module/__manifest__.py | 2 +- .../demo/{demo.xml => document_demo.xml} | 0 template/module/models/__init__.py | 2 +- .../module/models/{models.py => document.py} | 0 template/module/views/sale_order.xml | 6 +- 8 files changed, 104 insertions(+), 79 deletions(-) rename template/module/demo/{demo.xml => document_demo.xml} (100%) rename template/module/models/{models.py => document.py} (100%) diff --git a/addons/partner_contact b/addons/partner_contact index 2754ada4..a0a649af 160000 --- a/addons/partner_contact +++ b/addons/partner_contact @@ -1 +1 @@ -Subproject commit 2754ada4e01471b77d03e7186ad7f7abf15af7ee +Subproject commit a0a649afee337bb3b55e916ec180f34847254866 diff --git a/task b/task index ca40ce0a..3b9f317a 100755 --- a/task +++ b/task @@ -588,6 +588,27 @@ function create-module() { odoo-bin scaffold "$MODULE_NAME" "$PARENT_DIR" -t template/module } +function generate-module-security() { + if test -z "$1"; then echo "\$1 is empty."; exit; fi + if test -z "$2"; then echo "\$2 is empty."; exit; fi + + MODULE_NAME=$(basename "$1") + PARENT_DIR=$(dirname "$1") + MODEL_DOT_NAME="$2" + MODEL_NAME=$(echo "$MODEL_DOT_NAME" | tr '.' '_') + + ACCESS_FILE="$PARENT_DIR/$MODULE_NAME/security/ir.model.access.csv" + + if [ ! -f "$ACCESS_FILE" ]; then + echo "Init security file: $ACCESS_FILE" + echo "id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink" > "$ACCESS_FILE" + fi + + echo "Add model access to $ACCESS_FILE" + echo "access_${MODEL_NAME}_user,$MODULE_NAME.$MODEL_DOT_NAME,model_${MODEL_NAME},base.group_user,1,0,0,0" >> "$ACCESS_FILE" + echo "access_${MODEL_NAME}_manager,$MODULE_NAME.$MODEL_DOT_NAME,model_${MODEL_NAME},base.group_erp_manager,1,1,1,1" >> "$ACCESS_FILE" +} + function drop-db() { DATABASE="$1" DATABASE=${DATABASE:="$GIT_BRANCH"} @@ -1240,6 +1261,9 @@ case "$1" in generate-admin-passwd) generate-admin-passwd "$2" ;; + generate-module-security) + generate-module-security "$2" "$3" + ;; get-module-version) get-module-version "$2" ;; diff --git a/task.md b/task.md index 55935ae9..ce8c15e9 100644 --- a/task.md +++ b/task.md @@ -1,75 +1,76 @@ # Help -| command | option | description | -| ---------------------- | ----------------- | ----------------------------------------------------------------------------------------- | -| build | | Build Odoo Docker image. | -| change-uuid | [env] | Change database uuid via xmlrpc. | -| checkout | [branch][branch] | Switch and merge from one branch to another. | -| checkout-config-files | [branch] | Checkout config files from another branch. | -| checkout-revision | [revision] | Run Odoo revision script or checkout revision set by env var. | -| clear-assets | [db] | Clear all assets of Odoo database. | -| clear-filestore | [db] | Clear local filestore folder. No param will clear all filestores. Default is branch name. | -| convert-database | [db] | Convert database backup file from PostgreSQL 9.5 to latest. Default is branch name. | -| create-module | [path] | Create new Odoo module from template. | -| deploy | [name] | Deploy to Kubernets cluster. Options: db, admin, odoo, mail. | -| disable-auto-install | | Disable auto install for enterprise modules. | -| disable-mailserver | [env] | Disable mail server settings via xmlrpc. | -| docker-login | | Setup Docker Hub login credentials. | -| drop-db | [db] | Drop target Odoo database. Default is branch name. | -| edit-env | [env] | Open env file in default editor. | -| generate-admin-passwd | [pass] | Generate hash for Odoo master password. | -| translate-module | [env][path][lang] | Generate translation for Odoo module. | -| get-module-version | [path] | Get module version from manifest. | -| git-feature-branch | [path] | Create feature branch for Odoo module. | -| git-mig-branch | [path] | Create migration branch for Odoo module. | -| git-submodule-add | [url] [path] | Add git submodule. | -| git-submodule-list | | List path and url of submodules. | -| git-submodule-pull | | Pull alls submodules. | -| git-submodule-remove | [path] | Remove git submodule. | -| git-submodule-switch | [branch] | Switch branch for all submodules. | -| git-submodule-update | | Update submodules from .gitmodules file. | -| import-csv | [db][path] | Import data from csv. Filename must match PostgreSQL table name. | -| info | | Show values of project env vars. | -| init-db | [db] | Initialize the Odoo database. Default is branch name. | -| init-nextcloud-env | [env] | Create env file for Nextcloud instance. | -| init-odoo-env | [env] | Create env file for Odoo Instance. | -| init-venv | | Initialize python virtual env. | -| install-module | [db][name,path] | Install target Odoo module. Default database is branch name. | -| install-native | | Install Odoo requirements in source folder. | -| install-odoo-scripts | | Install Odoo scripts. | -| install-requirements | [db][path] | Install python packages from requirements.txt. | -| install-snippet | [env][path] | Install snippet xml definition. | -| down | [name] | Remove docker containers and volumes. Options: none, db, admin, odoo, mail. | -| lint-module | [path] | Run pylint odoo for module. | -| lint-snippets | | Run checks for all snippets. | -| list | | List Docker containers. | -| list-addons | | List odoo addons. | -| list-env | | List env files. | -| logs | | Tail Odoo Docker container logs. | -| odoo-cloc | [db] | Count custom line of codes. Default is branch name. | -| patch-database | [db][path] | Apply sql file to database. Default database is branch name. | -| publish | | Publish Odoo Docker image. | -| ps | | List docker processes. | -| release-module | [path] | Create GitHub release for a module. | -| remove-module | [db][name] | Remove target Odoo module. | -| reset-views | [db][key] | Execute hard reset on views matching keys. | -| restart | [name] | Restart docker container. | -| save-config | [name] | Save Odoo database config | -| send-support-mail | | Sends an mail for support@local to smtp://localhost | -| set-admin | [db] | Sets the password for the first user in database. Default is branch name. | -| source | | Source the Python virtual env. | -| start | [name] [db] | Start docker container. Options: none, db, admin, odoo, native, mail. | -| start-psql | [db] | Start PSQL shell in Docker container. Default is branch name. | -| start-shell | [db] | Start Odoo shell from source folder. Default is branch name. | -| stop | [name] | Stop docker containers. | -| test-jsonrpc | [env] | Test json rpc connection. | -| test-module | [db][name,path] | Test target Odoo module. | -| update-app-list | [db] | Update app list. | -| update-docs | | Update project docs. | -| update-module | [db][name,path] | Update target Odoo module. | -| update-readme | [path] | Update Readme file of Odoo module collection. | -| update-snippet | [env][path] | Update snippet xml definition. | -| upload-module | [env][path] | Zip and upload Odoo module. | -| visualize-dependencies | [path] | Generate visualizations of module dependencies. | -| version | | Show version of required tools. | -| zip-module | [path] | Create zip file for module. | \ No newline at end of file +| command | option | description | +| ------------------------ | ----------------- | ----------------------------------------------------------------------------------------- | +| build | | Build Odoo Docker image. | +| change-uuid | [env] | Change database uuid via xmlrpc. | +| checkout | [branch][branch] | Switch and merge from one branch to another. | +| checkout-config-files | [branch] | Checkout config files from another branch. | +| checkout-revision | [revision] | Run Odoo revision script or checkout revision set by env var. | +| clear-assets | [db] | Clear all assets of Odoo database. | +| clear-filestore | [db] | Clear local filestore folder. No param will clear all filestores. Default is branch name. | +| convert-database | [db] | Convert database backup file from PostgreSQL 9.5 to latest. Default is branch name. | +| create-module | [path] | Create new Odoo module from template. | +| deploy | [name] | Deploy to Kubernets cluster. Options: db, admin, odoo, mail. | +| disable-auto-install | | Disable auto install for enterprise modules. | +| disable-mailserver | [env] | Disable mail server settings via xmlrpc. | +| docker-login | | Setup Docker Hub login credentials. | +| drop-db | [db] | Drop target Odoo database. Default is branch name. | +| edit-env | [env] | Open env file in default editor. | +| generate-admin-passwd | [pass] | Generate hash for Odoo master password. | +| translate-module | [env][path][lang] | Generate translation for Odoo module. | +| generate-module-security | [path][model] | Generate model access file for a selected model of a module. | +| get-module-version | [path] | Get module version from manifest. | +| git-feature-branch | [path] | Create feature branch for Odoo module. | +| git-mig-branch | [path] | Create migration branch for Odoo module. | +| git-submodule-add | [url] [path] | Add git submodule. | +| git-submodule-list | | List path and url of submodules. | +| git-submodule-pull | | Pull alls submodules. | +| git-submodule-remove | [path] | Remove git submodule. | +| git-submodule-switch | [branch] | Switch branch for all submodules. | +| git-submodule-update | | Update submodules from .gitmodules file. | +| import-csv | [db][path] | Import data from csv. Filename must match PostgreSQL table name. | +| info | | Show values of project env vars. | +| init-db | [db] | Initialize the Odoo database. Default is branch name. | +| init-nextcloud-env | [env] | Create env file for Nextcloud instance. | +| init-odoo-env | [env] | Create env file for Odoo Instance. | +| init-venv | | Initialize python virtual env. | +| install-module | [db][name,path] | Install target Odoo module. Default database is branch name. | +| install-native | | Install Odoo requirements in source folder. | +| install-odoo-scripts | | Install Odoo scripts. | +| install-requirements | [db][path] | Install python packages from requirements.txt. | +| install-snippet | [env][path] | Install snippet xml definition. | +| down | [name] | Remove docker containers and volumes. Options: none, db, admin, odoo, mail. | +| lint-module | [path] | Run pylint odoo for module. | +| lint-snippets | | Run checks for all snippets. | +| list | | List Docker containers. | +| list-addons | | List odoo addons. | +| list-env | | List env files. | +| logs | | Tail Odoo Docker container logs. | +| odoo-cloc | [db] | Count custom line of codes. Default is branch name. | +| patch-database | [db][path] | Apply sql file to database. Default database is branch name. | +| publish | | Publish Odoo Docker image. | +| ps | | List docker processes. | +| release-module | [path] | Create GitHub release for a module. | +| remove-module | [db][name] | Remove target Odoo module. | +| reset-views | [db][key] | Execute hard reset on views matching keys. | +| restart | [name] | Restart docker container. | +| save-config | [name] | Save Odoo database config | +| send-support-mail | | Sends an mail for support@local to smtp://localhost | +| set-admin | [db] | Sets the password for the first user in database. Default is branch name. | +| source | | Source the Python virtual env. | +| start | [name] [db] | Start docker container. Options: none, db, admin, odoo, native, mail. | +| start-psql | [db] | Start PSQL shell in Docker container. Default is branch name. | +| start-shell | [db] | Start Odoo shell from source folder. Default is branch name. | +| stop | [name] | Stop docker containers. | +| test-jsonrpc | [env] | Test json rpc connection. | +| test-module | [db][name,path] | Test target Odoo module. | +| update-app-list | [db] | Update app list. | +| update-docs | | Update project docs. | +| update-module | [db][name,path] | Update target Odoo module. | +| update-readme | [path] | Update Readme file of Odoo module collection. | +| update-snippet | [env][path] | Update snippet xml definition. | +| upload-module | [env][path] | Zip and upload Odoo module. | +| visualize-dependencies | [path] | Generate visualizations of module dependencies. | +| version | | Show version of required tools. | +| zip-module | [path] | Create zip file for module. | \ No newline at end of file diff --git a/template/module/__manifest__.py b/template/module/__manifest__.py index a76a6a1b..9283c865 100644 --- a/template/module/__manifest__.py +++ b/template/module/__manifest__.py @@ -21,7 +21,7 @@ "auto_install": False, "images": ["images/screen.png"], "qweb": ["static/src/xml/board.xml"], - "demo": ["demo/demo.xml"], + "demo": ["demo/document_demo.xml"], "assets": { "web.assets_backend": [ "{{ name }}/static/src/js/action_refresh.js", diff --git a/template/module/demo/demo.xml b/template/module/demo/document_demo.xml similarity index 100% rename from template/module/demo/demo.xml rename to template/module/demo/document_demo.xml diff --git a/template/module/models/__init__.py b/template/module/models/__init__.py index 0650744f..9c01ea24 100644 --- a/template/module/models/__init__.py +++ b/template/module/models/__init__.py @@ -1 +1 @@ -from . import models +from . import document diff --git a/template/module/models/models.py b/template/module/models/document.py similarity index 100% rename from template/module/models/models.py rename to template/module/models/document.py diff --git a/template/module/views/sale_order.xml b/template/module/views/sale_order.xml index e6f9306a..d2ca3196 100644 --- a/template/module/views/sale_order.xml +++ b/template/module/views/sale_order.xml @@ -36,8 +36,8 @@ - - {{ name }}.open_view_tree + + Documents {{ name }} tree,form @@ -61,7 +61,7 @@ + action="{{ name }}.action_view_tree" />