#!/bin/bash cd "$(dirname "$0")" function help() { echo echo "$1 [options]" echo echo "commands:" echo column -t -s"|" ./task.md | tail -n +3 echo } # Set env vars PATH="$PATH:./odoo" GIT_TAG=0 GIT_BRANCH=$(git symbolic-ref --short -q HEAD) export POSTGRES_USER=odoo export POSTGRES_PASSWORD=odoo export ODOO_REVISION=$GIT_BRANCH export ODOO_LANGUAGE=de_CH export ODOO_DEVELOPMENT_CONFIG_DIR="$HOME/.config/odoo-development" if [[ -a ".env" ]]; then export $(cat .env | sed 's/#.*//g' | xargs) fi function update-readme() { if test -z "$1"; then echo "\$1 is empty."; exit; fi FILE_NAME=$(basename "$1") if [[ "$FILE_NAME" != "README.md" ]]; then echo "\$1 must point to README.md file."; exit; fi MODULES_DIR=$(dirname "$1") MANIFEST_FILES="$MODULES_DIR/*/__manifest__.py" # Find marker in readme and clear content after echo "Clear modules table for $1." MARKER="## Available modules" sed -i "/$MARKER/Q" $1 echo "$MARKER" >> $1 echo "" >> $1 echo "| Module | Summary |" >> $1 echo "| --- | --- |" >> $1 # Clear table after a marker for MANIFEST_FILE in $MANIFEST_FILES; do MODULE_DIR=$(dirname "$MANIFEST_FILE") MODULE_NAME=$(basename "$MODULE_DIR") echo "Add summary of $MODULE_NAME to readme file." SUMMARY=$(grep 'summary' "$MANIFEST_FILE" -A 1 | tail -1) echo "| [$MODULE_NAME]($MODULE_NAME) | $SUMMARY |" >> $1 done } function get-module-version() { if test -z "$1" then echo "\$1 is empty." else # get version of module VERSION=$(grep 'version' "$1/__manifest__.py" | sed "s;';\";g" | sed "s/,//g" ) VERSION=$(echo "{ $VERSION }" | jq .version | sed 's/"//g' | sed 's/null//g') # set default version [ -z "$VERSION" ] && VERSION=0.0 # check if oca version or enterprise version if echo "$VERSION" | grep -qe "^[0-9]\." then VERSION="$GIT_BRANCH.$VERSION.$GIT_TAG" fi echo $VERSION fi } function init-venv() { if [ ! -d "venv$GIT_BRANCH" ]; then echo "Init venv$GIT_BRANCH with $(python --version)." python -m venv "venv$GIT_BRANCH" fi } function activate-venv() { echo "Source virtualenv venv$GIT_BRANCH." source "venv$GIT_BRANCH/bin/activate" echo "$(python --version) is active." } function locale() { export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 } function load-env() { ENV_FILE="$ODOO_DEVELOPMENT_CONFIG_DIR/.env.$1" echo "Load env file $ENV_FILE" export $(cat "$ENV_FILE" | sed 's/#.*//g' | xargs) } function disable-auto-install() { echo "Disable auto install for all enterprise modules." find ./enterprise -type f -name '__manifest__.py' -exec sed -i'' $'s/\'auto_install\': True,/\'auto_install\': False,/g' {} + } function install-odoo-scripts() { curl -L https://raw.githubusercontent.com/mint-system/ansible-playbooks/master/roles/odoo-scripts/files/install | sh } function install-native() { init-venv activate-venv # Source: https://gist.github.com/faniska/37f896d5e9de5fee925925d7caf3cb9e echo "Install wkhtmltopdf" sudo apt remove wkhtmltopdf cd ~ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz tar xvf wkhtmltox*.tar.xz sudo mv wkhtmltox/bin/wkhtmlto* /usr/bin sudo apt-get install -y openssl build-essential libssl-dev libxrender-dev git-core libx11-dev libxext-dev libfontconfig1-dev libfreetype6-dev fontconfig echo "Install xmllint" sudo apt install libxml2-utils echo "Install pylint odoo" pip install --upgrade --pre pylint-odoo echo "Install odoo dependencies" pip install setuptools wheel watchdog phonenumbers pip install -r odoo/requirements.txt echo "Install oca dev tools" pip install pre-commit pyyaml rst2html5 odoorpc echo "Install graphql dependencies" pip install graphene graphql-server-core echo "Install rest dependencies" pip install cerberus pyquerystring parse-accept-language apispec>=4.0.0 marshmallow marshmallow-objects>=2.0.0 jsondiff echo "Install openupgrade functions" pip install git+https://github.com/OCA/openupgradelib.git@master#egg=openupgradelib echo "Install addon dependencies" pip install prometheus_client pika echo "Install edi dependencies" pip install pyzbar numpy pdf2image opencv-python } function open-url-with-delay(){ if test -z "$1"; then echo "\$1 is empty."; exit; fi sleep 2 xdg-open $1 } function start() { if test -z "$1"; then echo "Open http://localhost:8069 url in your browser." docker-compose up -d fi if [[ "$1" =~ "db" ]]; then docker-compose up -d db admin echo "Open http://localhost:8000 url in your browser." fi if [[ "$1" =~ "odoo" ]]; then docker-compose up -d odoo echo "Open http://localhost:8069 url in your browser." fi if [[ "$1" =~ "native" ]]; then locale activate-venv echo "Open http://localhost:8069 url in your browser." open-url-with-delay "http://localhost:8069/web?db=$GIT_BRANCH" & odoo-bin --config 'config/odoo-native.conf' --dev=all --log-handler odoo.tools.convert:DEBUG fi if [[ "$1" =~ "mail" ]]; then docker-compose up -d mail echo "Run \`docker exec -it mail setup email add odoo@example.com\`" echo "Run \`docker exec -it mail setup email add test@example.com\`" fi } function down() { if test -z "$1"; then docker-compose down -v fi if [[ "$1" =~ "mail" ]]; then docker-compose rm -f -s -v mail fi } function restart() { if test -z "$1"; then docker-compose restart fi if [[ "db|mail|odoo" =~ "$1" ]]; then docker-compose restart $1 fi } function stop() { if test -z "$1"; then docker-compose stop fi docker-compose stop $1 } function start-shell() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} locale activate-venv odoo-bin shell -d $DATABASE --config 'config/odoo-native.conf' --no-http } function start-psql() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} docker exec -it db psql postgres://odoo:odoo@localhost:5432/$DATABASE } function init-db() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} locale activate-venv echo "Make sure only one odoo process is running when initalizing the database." # odoo-bin --init base -d $DATABASE --db_host=localhost --db_password=odoo --db_user=odoo --no-http odoo-bin --init base -d $DATABASE --config 'config/odoo-native.conf' --stop-after-init --no-http --load-language $ODOO_LANGUAGE } function odoo-cloc() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} locale activate-venv odoo-bin cloc -d $DATABASE --config 'config/odoo-native.conf' --stop-after-init --no-http } function lint-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi activate-venv echo "Set file and folder permissions on $1" find $1 -type d -exec chmod u=rwx,go=rx {} \; find $1 -type f -exec chmod u=rw,go=r {} \; echo "Copy default .gignore" cp template/ms_custom_module/.gitignore "$1"/ echo "Run pylint in $1" pylint --load-plugins=pylint_odoo -d all -e odoolint $1 cd $1 echo "Run pre-commit in $1" pre-commit run --files ./* echo "Update index.html" rst2html5 README.rst static/description/index.html echo "Stage changes" git add . } function update-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi # if test -z "$2"; then echo "\$2 is empty."; exit; fi DATABASE=$1 MODULE_NAME=$(basename $2) # Use default database if second param is not given if test -z "$2"; then DATABASE="$GIT_BRANCH" MODULE_NAME=$(basename $1) fi locale activate-venv echo "Updating module $MODULE_NAME on $DATABASE ..." odoo-bin -d $DATABASE -u $MODULE_NAME --config 'config/odoo-native.conf' --stop-after-init --no-http } function generate-module-translation() { if test -z "$1"; then echo "\$1 is empty."; exit; fi # if test -z "$2"; then echo "\$2 is empty."; exit; fi DATABASE=$1 MODULE_PATH=$2 MODULE_NAME=$(basename $2) LANGUAGE=$3 if test -z "$2"; then DATABASE="$GIT_BRANCH" MODULE_PATH=$1 MODULE_NAME=$(basename $1) fi if test -z "$3"; then LANGUAGE="$ODOO_LANGUAGE" fi locale activate-venv echo "Generate $LANGUAGE tranlsation file for $MODULE_NAME on $DATABASE ..." mkdir -p "$MODULE_PATH/i18n/" odoo-bin -d $DATABASE --config 'config/odoo-native.conf' --modules $MODULE_NAME -l $LANGUAGE --i18n-export "$MODULE_PATH/i18n/$LANGUAGE.po" } function install-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi DATABASE=$1 MODULE_NAME=$(basename $2) # Use default database if second param is not given if test -z "$2"; then DATABASE="$GIT_BRANCH" MODULE_NAME=$(basename $1) fi locale activate-venv echo "Installing module $MODULE_NAME on $DATABASE ..." odoo-bin -d $DATABASE -i $MODULE_NAME --config 'config/odoo-native.conf' --stop-after-init --no-http } function test-module() { 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 $2) locale activate-venv odoo-bin -d $1 -i $MODULE_NAME --config 'config/odoo-native.conf' --stop-after-init --log-level=test --test-enable } function remove-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi DATABASE=$1 MODULE_NAME=$(basename $2) # Use default database if second param is not given if test -z "$2"; then DATABASE="$GIT_BRANCH" MODULE_NAME=$(basename $1) fi locale activate-venv echo "Remove module $MODULE_NAME" echo "self.env['ir.module.module'].search([('name', '=', '$MODULE_NAME')]).button_immediate_uninstall()" | odoo-bin shell -d $DATABASE --config 'config/odoo-native.conf' --no-http } function create-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi MODULE_NAME=$(basename "$1") PARENT_DIR=$(dirname "$1") locale activate-venv echo "Scaffolding module $MODULE_NAME in $PARENT_DIR ..." odoo-bin scaffold "$MODULE_NAME" "$PARENT_DIR" -t template/ms_custom_module } function drop-db() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} docker exec db psql postgres://odoo:odoo@localhost:5432/postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$DATABASE';" docker exec db psql postgres://odoo:odoo@localhost:5432/postgres -c "DROP DATABASE \"$DATABASE\";" } function set-admin() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} docker exec db psql postgres://odoo:odoo@localhost:5432/$DATABASE -c "UPDATE res_users SET active=true,password='\$pbkdf2-sha512\$25000\$JuScEwIg5JzTGqNUivFeqw\$yWTOcix2Afr3XGP2NPY7w4w49e9vpsu14NRndDYXAkbtMF4zkrmx6inVsoLl0zZY30xI/0GzhwonWsK9TUmjWA' WHERE id=2;" docker exec db psql postgres://odoo:odoo@localhost:5432/$DATABASE -c "SELECT login, password FROM res_users WHERE id=2;" } function clear-assets() { DATABASE=$1 DATABASE=${DATABASE:="$GIT_BRANCH"} echo "Delete these assets:" docker exec db psql postgres://odoo:odoo@localhost/$DATABASE -c "select id,name from ir_attachment where res_model='ir.ui.view' and name like '%assets_%';" docker exec db psql postgres://odoo:odoo@localhost/$DATABASE -c "delete from ir_attachment where res_model='ir.ui.view' and name like '%assets_%';" echo "Restart your docker service." } function convert-database() { if test -z "$1"; then echo "\$1 is empty."; exit; fi unzip "tmp/$1.zip" -d "./tmp/$1" sed -i'' 's/AS integer//g' "./tmp/$1/dump.sql" grep -i 'as integer' "./tmp/$1/dump.sql" cd "tmp/$1" ; zip -r "../${1}2.zip" . ; cd ../.. rm -r "tmp/$1" echo "Converted database file $1 to ${1}2" } function git-update-submodules() { echo "Update submodules." SUBMODULES=$(git config --file .gitmodules --get-regexp url | sed -e 's/submodule.//g' -e 's/.url.*//g') for SUBMODULE in $SUBMODULES; do git submodule update --init $SUBMODULE done } function switch-branch() { if test -z "$1"; then echo "\$1 is empty."; exit; fi echo "Switch branch on submodules." SUBMODULES=$(git config --file .gitmodules --get-regexp url | sed -e 's/submodule.//g' -e 's/.url.*//g') for SUBMODULE in $SUBMODULES; do CWD=$(pwd) cd $SUBMODULE git stash git switch $1 cd $CWD done } function checkout() { if test -z "$1"; then echo "\$1 is empty."; exit; fi : ${GIT_BRANCH:="$2"} echo "Switch branch." git switch $1 git-update-submodules switch-branch $1 echo "Checkout config files." git checkout $GIT_BRANCH config/checkout_files config/reset_files echo "Remove reset files." git rm -r $(tr '\n' ' ' < ./config/reset_files) >/dev/null 2>&1 echo "Sync checkout files." git checkout $GIT_BRANCH $(tr '\n' ' ' < ./config/checkout_files) } function checkout-revision() { if test -z "$1"; then echo "\$1 is empty."; exit; fi cd odoo git checkout $1 cd .. cd enterprise git checkout $1 cd .. cd themes git checkout $1 } function git-pull-submodules() { # Pull submodule if update config is not set SUBMODULES=$(git config --file .gitmodules --get-regexp url | sed -e 's/submodule.//g' -e 's/.url.*//g') for SUBMODULE in $SUBMODULES; do UPDATE=$(git config submodule.$SUBMODULE.update) CWD=$(pwd) cd $SUBMODULE if [ -z $UPDATE ]; then git pull fi; cd $CWD done } function release-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi VERSION=$(get-module-version $1) cd $1 LAST_TAG=$(git describe --tags) RELEASE_NOTES=$(git log $LAST_TAG..HEAD --oneline) echo "Tag with v$VERSION ..." git tag -a v$VERSION -m "v$VERSION" echo "Release notes:" echo $RELEASE_NOTES # echo "Create release $VERSION ..." # gh release create "v$VERSION" -t "Release $VERSION" } function zip-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi # Get version and module name VERSION=$(get-module-version $1) MODULE=$(basename "$1") # Copy module to tmp folder echo "Copy module $MODULE version $VERSION to tmp folder" MODULE_NAME="$MODULE-$VERSION" MODULE_PATH="tmp/$MODULE_NAME" rm -rf "$MODULE_PATH" mkdir -p "$MODULE_PATH" cp -r "$1/." "$MODULE_PATH" find "$MODULE_PATH" -type d -exec chmod u=rwx,go=rx {} \; find "$MODULE_PATH" -type f -exec chmod u=rw,go=r {} \; # Configure and zip module echo "Remove auto install option" sed -i'' -e "s/'auto_install': True,/'auto_install': False,/" "$MODULE_PATH/__manifest__.py" echo "Remove pycache and hidden folders" find $MODULE_PATH | grep -E "(\.git|__pycache__|\.pyc|\.pyo$)" | xargs rm -rf echo "Zip module $MODULE" cd tmp rm -f $MODULE_NAME.zip zip -q -r $MODULE_NAME.zip $MODULE_NAME cd .. } function clear-filestore() { echo "Remove directory ~/.local/share/Odoo/filestore/$1" rm -rf ~/.local/share/Odoo/filestore/$1 } function disable-mailserver() { if test -z "$1"; then echo "\$1 is empty."; exit; fi activate-venv load-env $1 scripts/odooctl --model 'ir.mail_server' --field 'active' --value False scripts/odooctl --model 'fetchmail.server' --field 'active' --value False } function change-uuid() { if test -z "$1"; then echo "\$1 is empty."; exit; fi activate-venv load-env $1 UUID=$(uuidgen) echo "Set uuid $UUID for $1." scripts/odooctl --model 'ir.config_parameter' --domain "['key', '=', 'database.uuid']" --field 'value' --value "'$UUID'" } function test-jsonrpc() { activate-venv [ -n "$1" ] && load-env $1 scripts/jsonrpc } function generate-admin-passwd() { activate-venv if test -z "$1"; then echo "\$1 is empty."; exit; fi ODOO_PASSWORD="$1" scripts/hash_password } function update-snippet() { if test -z "$1"; then echo "\$1 is empty."; exit; fi if test -z "$2"; then echo "\$2 is empty."; exit; fi # Generate view name from filename FILE=$(basename $2) NAME="mint_system.${FILE%.xml}" activate-venv load-env $1 echo "Update view with name $NAME" scripts/odooctl --model 'ir.ui.view' --domain "['name', '=', '$NAME']" --field 'arch_base' --value "'''$(cat $2)'''" } function install-snippet() { if test -z "$1"; then echo "\$1 is empty."; exit; fi if test -z "$2"; then echo "\$2 is empty."; exit; fi # Generate view name from filename FILE=$(basename $2) NAME="mint_system.${FILE%.xml}" INHERIT_ID=$(echo 'cat //data/@inherit_id' | xmllint --shell $2 | awk -F'[="]' '!/>/{print $(NF-1)}') TYPE=$(echo 'cat //data/@type' | xmllint --shell $2 | awk -F'[="]' '!/>/{print $(NF-1)}') MODEL=$(echo 'cat //data/@model' | xmllint --shell $2 | awk -F'[="]' '!/>/{print $(NF-1)}') PRIORITY=$(echo 'cat //data/@priority' | xmllint --shell $2 | awk -F'[="]' '!/>/{print $(NF-1)}') MODULE_NAME=$(echo $INHERIT_ID | cut -d. -f 1 ) XML_ID=$(echo $INHERIT_ID | cut -d. -f 2 ) # Set default values : ${TYPE:='qweb'} activate-venv load-env $1 echo "Search for view with name $MODULE_NAME.$XML_ID" INHERIT_ID=$(scripts/odooctl --method 'get_id' --model 'ir.model.data' --value "['$MODULE_NAME','$XML_ID']") echo "Found view id $INHERIT_ID" echo "Apply view $NAME" scripts/odooctl --method 'create' --model 'ir.ui.view' --value "{ 'name': '$NAME', 'type': '$TYPE', 'model': '$MODEL', 'mode': 'extension', 'priority': $PRIORITY, 'inherit_id': $INHERIT_ID, 'arch_base': '''$(cat $2)''' }" } function lint-snippets() { FILES="snippets/*.xml" for FILE in $FILES; do # Access various snippet parameters FILENAME=$(basename $FILE) SNIPPET_MODULE=$(echo $FILENAME | cut -d. -f1) REPORT=$(echo $FILENAME | cut -d. -f2) EDIT=$(echo $FILENAME | cut -d. -f3) INHERIT_ID=$(echo 'cat //data/@inherit_id' | xmllint --shell $FILE | awk -F'[="]' '!/>/{print $(NF-1)}') TYPE=$(echo 'cat //data/@type' | xmllint --shell $FILE | awk -F'[="]' '!/>/{print $(NF-1)}') MODEL=$(echo 'cat //data/@model' | xmllint --shell $FILE | awk -F'[="]' '!/>/{print $(NF-1)}') PRIORITY=$(echo 'cat //data/@priority' | xmllint --shell $FILE | awk -F'[="]' '!/>/{print $(NF-1)}') MODULE_NAME=$(echo $INHERIT_ID | cut -d. -f 1 ) XML_ID=$(echo $INHERIT_ID | cut -d. -f 2 ) # Check filename COUNT_DOTS=$(echo $FILENAME | grep -o "\." | wc -l) if [ $COUNT_DOTS -ge 4 ]; then echo "Linting failed for $FILE" echo "Dots count: $COUNT_DOTS" echo " Filename: $SNIPPET_MODULE.$REPORT" exit 1 fi # Check if inherit id matches the filename if [ -n "$INHERIT_ID" ]; then if [[ "$INHERIT_ID" != "$SNIPPET_MODULE.$REPORT" ]]; then echo "Linting failed for $FILE" echo " Inherit: $INHERIT_ID" echo "Filename: $SNIPPET_MODULE.$REPORT" exit 1 fi fi # Check if priority is set if [ -z "$PRIORITY" ] && [ -n "$INHERIT_ID" ]; then echo "Linting failed for $FILE" echo "No priority is set." exit 1 fi done echo "No problems with snippets found." } function update-app-list() { if test -z "$1"; then echo "\$1 is empty."; exit; fi locale activate-venv echo "env['ir.module.module'].update_list()" | odoo-bin shell -d $1 --config 'config/odoo-native.conf' --no-http } function init-config-dir() { echo "Ensure $ODOO_DEVELOPMENT_CONFIG_DIR exists" mkdir -p "$ODOO_DEVELOPMENT_CONFIG_DIR" } function init-odoo-env() { if test -z "$1"; then echo "\$1 is empty."; exit; fi init-config-dir ENV_FILEPATH="$ODOO_DEVELOPMENT_CONFIG_DIR/.env.$1" echo "Init env file: $ENV_FILEPATH" echo "#ODOO_URL=" > $ENV_FILEPATH echo "ODOO_DATABASE=" >> $ENV_FILEPATH echo "ODOO_USERNAME=" >> $ENV_FILEPATH echo "ODOO_PASSWORD=" >> $ENV_FILEPATH } function init-next-env() { if test -z "$1"; then echo "\$1 is empty."; exit; fi init-config-dir ENV_FILEPATH="$ODOO_DEVELOPMENT_CONFIG_DIR/.env.$1" echo "Init env file: $ENV_FILEPATH" echo "NEXTCLOUD_URL=" > $ENV_FILEPATH echo "NEXTCLOUD_USERNAME=" >> $ENV_FILEPATH echo "NEXTCLOUD_PASSWORD=" >> $ENV_FILEPATH } function edit-env() { if test -z "$1"; then echo "\$1 is empty."; exit; fi ENV_FILEPATH="$ODOO_DEVELOPMENT_CONFIG_DIR/.env.$1" $EDITOR $ENV_FILEPATH } function upload-module() { if test -z "$1"; then echo "\$1 is empty."; exit; fi if test -z "$2"; then echo "\$2 is empty."; exit; fi # Check if path is root folder MODULES=$2 if [ -f "$2/README.md" ]; then echo "Identified as root folder" MODULES="$MODULES/*" fi for MODULE in $MODULES; do if [ -f "$MODULE/__manifest__.py" ]; then # Create module zip zip-module $MODULE # Get path to zip file and upload url FILE_PATH="tmp/$MODULE_NAME.zip" load-env $1 NEXTCLOUD_UPLOAD_URL="$NEXTCLOUD_URL/remote.php/dav/files/$NEXTCLOUD_USERNAME/Odoo-Apps/" # Upload zip file curl -u "$NEXTCLOUD_USERNAME:$NEXTCLOUD_PASSWORD" -T "$FILE_PATH" "$NEXTCLOUD_UPLOAD_URL" echo "File $FILE_PATH uploaded to $NEXTCLOUD_UPLOAD_URL." UPLOADS+=" - name: $MODULE\n" UPLOADS+=" version: $VERSION\n" fi done echo "odoo_apps:" echo -e "$UPLOADS" } function save-config() { if test -z "$1"; then echo "\$1 is empty."; exit; fi locale activate-venv odoo-bin -s -d $1 --config 'config/odoo-native.conf' --stop-after-init --no-http } function remove-submodule() { if test -z "$1"; then echo "\$1 is empty."; exit; fi echo "Move submodule to tmp folder" mkdir -p tmp/$1 mv $1 tmp/$1 echo "Deinit submodule" git submodule deinit -f $1 echo "Remove submodule from .git folder" rm -rf .git/modules/$1 echo "Remove submodule from work tree" git rm -f $1 echo "Remove $1 submodule from .gitmodules files manually." } function update-config() { # Read addons path list ADDONS="$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | tr '\n' ',' | sed 's/,*$//g')" # Check if dir exists for ADDON in $ADDONS; do if [ -d "$ADDON" ]; then echo "Path does not exist: $ADDON" exit 1 fi done # Update native config sed -i'' -e "s|addons_path.*|addons_path = odoo/addons,$ADDONS|g" "./config/odoo-native.conf" ADDONS="$(echo "$ADDONS" | sed 's|,|,/mnt/|g' | sed 's|,/mnt/odoo||g')" # Update docker config sed -i'' -e "s|addons_path.*|addons_path = /mnt/$ADDONS|g" "./config/odoo.conf" echo "Config updated." } function git-list-submodules() { git config --file .gitmodules --get-regexp url | sed -e 's/submodule.//g' -e 's/.url//g' | awk '{ print $1 "," $2}' } function git-feature-branch(){ if test -z "$1"; then echo "\$1 is empty."; exit; fi MODULE_NAME=$(basename $1) MODULE_PATH=$(dirname $1) echo "Create feature branch for $MODULE_NAME in $MODULE_PATH ..." cd ./$MODULE_PATH pwd git switch -c "feature-$MODULE_NAME" } function git-mig-branch(){ if test -z "$1"; then echo "\$1 is empty."; exit; fi MODULE_NAME=$(basename $1) MODULE_PATH=$(dirname $1) echo "Create mig branch for $MODULE_NAME in $MODULE_PATH ..." cd ./$MODULE_PATH pwd git switch -c "$GIT_BRANCH-mig-$MODULE_NAME" } function patch-database() { if test -z "$1"; then echo "\$1 is empty."; exit; fi DATABASE=$1 FILENAME=$2 # Use default database if second param is not given if test -z "$2"; then DATABASE="$GIT_BRANCH" FILENAME=$1 fi echo "Apply patch $FILENAME to Database $DATABASE." cat $FILENAME | docker exec -i db psql postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost/$DATABASE echo "Patching database succeeded" } function update-docs() { lint-snippets echo "Update snippets README file." echo "# Snippets" > snippets.md echo "In Odoo everything is described as an XML document. \ Snippets are modifications (edits) for these XML documents. \ With a snippet you can e.g. hide a field on the contact form. \ A snippet name is unique and follows the \`\$COMPANY.\$MODULE.\$XML_ID.\$DESCRIPTION\` schema." >> snippets.md PATH_URL="https://github.com/Mint-System/Odoo-Development/tree/14.0" # Get all modules MODULES=$(ls snippets/*.xml | xargs -n 1 basename | cut -d. -f1 | sort | uniq) for MODULE in $MODULES; do TITLE="${MODULE^}" # Uppercase first letter TITLE=$(echo $TITLE | sed 's/_/ /g') # Replace underline with space TITLE=$(echo $TITLE | sed -r 's/\<./\U&/g') # Uppercase first letter after space # Create doc file for each module DOCFILE="snippets/$MODULE.md" echo -e "---\nprev: ./snippets\n---\n# $TITLE" > $DOCFILE echo "## [$TITLE](snippets/$MODULE.md)" >> snippets.md SIDEBAR_ENTRIES+="'/snippets/$MODULE.md'," # Get all xml ids XML_IDS=$(ls snippets/$MODULE.*.xml | xargs -n 1 basename | cut -d. -f2 | uniq) for XML_ID in $XML_IDS; do XML_ID_TITLE=$(echo $XML_ID | sed 's/_/ /g') # Replace underline with space XML_ID_TITLE=$(echo $XML_ID_TITLE | sed -r 's/\<./\U&/g') # Uppercase first letter after space echo "## $XML_ID_TITLE " >> $DOCFILE # Process each file FILES="snippets/$MODULE.$XML_ID.*.xml" for FILE in $FILES; do # Get snippet params FILENAME=$(basename $FILE) EDIT=$(echo $FILENAME | cut -d. -f3) EDIT_TITLE=$(echo $EDIT | sed 's/_/ /g') # Replace underline with space EDIT_TITLE=$(echo $EDIT_TITLE | sed -r 's/\<./\U&/g') # Uppercase first letter after space # Group by modules echo "### $EDIT_TITLE " >> $DOCFILE echo "ID: \`mint_system.$MODULE.$XML_ID.$EDIT\` " >> $DOCFILE echo -e '```xml' >> $DOCFILE cat "$FILE" >> $DOCFILE echo -e '\n```' >> $DOCFILE echo -e "Source: [$FILE]($PATH_URL/$FILE)\n" >> $DOCFILE done done done echo "module.exports = [$SIDEBAR_ENTRIES]" > .vuepress/sidebar_snippet.js } case "$1" in disable-auto-install) disable-auto-install ;; save-config) save-config $2 ;; checkout) checkout $2 $3 ;; checkout-revision) checkout-revision $2 ;; list) docker-compose config --services; echo "native" ;; ps) docker ps --format 'table {{.Names}}\t{{.Image}}\t{{(.Label "description")}}\t{{.Status}}' ;; start) start $2 ;; restart) restart $2 ;; stop) stop $2 ;; kill) down $2 ;; logs) docker logs odoo -f ;; init-venv) init-venv ;; install-odoo-scripts) install-odoo-scripts ;; install-native) install-native ;; init-db) init-db $2 ;; start-shell) start-shell $2 ;; start-psql) start-psql $2 ;; update-module) update-module $2 $3 ;; test-module) test-module $2 $3 ;; create-module) create-module $2 ;; drop-db) drop-db $2 ;; send-support-mail) send-support-mail ;; clear-assets) clear-assets $2 ;; generate-admin-passwd) generate-admin-passwd $2 ;; odoo-cloc) odoo-cloc $2 ;; restore-database) restore-database $2 $3 ;; convert-database) convert-database $2 ;; install-module) install-module $2 $3 ;; remove-module) remove-module $2 $3 ;; remove-submodule) remove-submodule $2 ;; git-update-submodules) git-update-submodules ;; release-module) release-module $2 ;; lint-module) lint-module $2 ;; update-readme) update-readme $2 ;; zip-module) zip-module $2 ;; clear-filestore) clear-filestore $2 ;; init-odoo-env) init-odoo-env $2 ;; list-odoo-env) ls -f "$ODOO_DEVELOPMENT_CONFIG_DIR" ;; edit-env) edit-env $2 ;; disable-mailserver) disable-mailserver $2 ;; change-uuid) change-uuid $2 ;; set-admin) set-admin $2 ;; switch-branch) switch-branch $2 ;; update-config) update-config ;; git-list-submodules) git-list-submodules ;; git-feature-branch) git-feature-branch $2 ;; git-mig-branch) git-mig-branch $2 ;; update-snippet) update-snippet $2 $3 ;; test-jsonrpc) test-jsonrpc $2 ;; install-snippet) install-snippet $2 $3 ;; lint-snippets) lint-snippets ;; update-app-list) update-app-list $2 ;; init-next-env) init-next-env $2 ;; upload-module) upload-module $2 $3 ;; generate-module-translation) generate-module-translation $2 $3 $4 ;; patch-database) patch-database $2 $3 ;; git-pull-submodules) git-pull-submodules ;; update-docs) update-docs ;; source) activate-venv ;; *) help task exit 1 ;; esac