forked from Mint-System/Odoo-Build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task
executable file
·1173 lines (970 loc) · 33 KB
/
task
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
cd "$(dirname "$0")" || exit
function help() {
echo
echo "$1 <command> [options]"
echo
echo "commands:"
echo
column -t -s"|" ./task.md | tail -n +3
echo
}
if [[ -a ".env" && "$(cat .env | sed 's/^#.*//g')" ]]; then
export $(cat .env | sed 's/^#.*//g' | xargs)
fi
# Set env vars
PATH="$PATH:./odoo"
OS_RELEASE=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
GIT_BRANCH=$(git symbolic-ref --short -q HEAD)
ODOO_REVISION=${ODOO_REVISION:="$GIT_BRANCH"}
ODOO_LANGUAGE=de_CH
ODOO_DEVELOPMENT_CONFIG_DIR="$HOME/.config/odoo-build"
DOCKER_TAG="odoo:$ODOO_REVISION"
: ${DOCKER_REGISTRY:=""}
TARGETARCH=amd64
function set-addons-path() {
# Read addons path list
SUBMODULES_PATH="$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | tr '\n' ',' | sed 's/,*$//g')"
EXCLUDES="addons/theme_mint_system addons/company addons/web"
for EXCLUDE in $EXCLUDES; do
SUBMODULES_PATH=$(echo "$SUBMODULES_PATH" | sed "s|${EXCLUDE},||g")
done
# Check if dir exists
for ADDON in $SUBMODULES_PATH; do
if [ -d "$ADDON" ]; then
echo "Path does not exist: $ADDON"
exit 1
fi
done
# Convert to docker paths
DOCKER_ADDONS_PATH="$(echo $SUBMODULES_PATH | sed 's|enterprise|/mnt/enterprise|g'| sed 's|,|,/mnt/|g' | sed 's|,/mnt/odoo||g')"
# Convert to native paths
ADDONS_PATH="$(echo $SUBMODULES_PATH | sed 's|,odoo,|,odoo/addons,|g')"
# Append env var
ADDONS_PATH="${ADDONS_PATH},${ODOO_ADDONS_PATH}"
}
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 -m 1 version "$1/__manifest__.py" | sed "s;';\";g" | 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
COUNT_DOTS=$(echo "$VERSION" | grep -o "\." | wc -l)
# check if oca version or enterprise version
if [[ $COUNT_DOTS == 2 ]]; then
VERSION="$GIT_BRANCH.$VERSION"
fi
if [[ $COUNT_DOTS == 1 ]]; then
VERSION="$GIT_BRANCH.$VERSION"
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 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 . -type f -name '__manifest__.py' -exec sed -i'' $'s/\'auto_install\': True,/\'auto_install\': False,/g' {} +
}
function build() {
echo "Run Docker build with tag ${DOCKER_REGISTRY}${DOCKER_TAG}"
docker build . --build-arg TARGETARCH="$TARGETARCH" --build-arg ODOO_IMAGE="odoo:$GIT_BRANCH" -t "${DOCKER_REGISTRY}${DOCKER_TAG}"
}
function install-odoo-scripts() {
curl -L https://raw.githubusercontent.com/mint-system/ansible-build/master/roles/odoo_scripts/files/install | bash
}
function install-native() {
init-venv
activate-venv
if [[ "Ubuntu|Debian" =~ $OS_RELEASE ]]; then
# Source: https://gist.github.com/faniska/37f896d5e9de5fee925925d7caf3cb9e
echo "Install wkhtmltopdf"
sudo apt remove wkhtmltopdf
cd ~ || exit
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
else
echo "The operating system $OS_RELEASE is not supported."
fi
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 development tools"
pip install pre-commit pyyaml rst2html5 odoorpc coverage
echo "Install OCA openupgrade tools"
pip install git+https://github.com/OCA/openupgradelib.git@master#egg=openupgradelib
echo "Install module dependencies: prometheus_exporter"
pip install prometheus_client
echo "Install module dependencies: base_view_inheritance_extension"
pip install astor
}
function open-url-with-delay(){
if test -z "$1"; then echo "\$1 is empty."; exit; fi
sleep 2
xdg-open "$1"
}
function start() {
set-addons-path
# Exports for Docker Compose
export POSTGRES_USER=odoo
export POSTGRES_PASSWORD=odoo
export DOCKER_TAG
export DOCKER_ADDONS_PATH
# Use default database if second param is not given
DATABASE="$2"
if test -z "$2"; then
DATABASE="$GIT_BRANCH"
fi
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
echo "Open http://localhost:8000 url in your browser."
fi
if [[ "$1" =~ "admin" ]]; then
docker-compose up -d 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
activate-venv
echo "Open http://localhost:8069 url in your browser."
open-url-with-delay "http://localhost:8069/web?db=$DATABASE" &
odoo-bin --config "config/odoo.conf" --addons-path="$ADDONS_PATH" --dev=all --log-handler odoo.tools.convert:DEBUG
fi
if [[ "$1" =~ "mail" ]]; then
echo "Open http://localhost:8025 url in your browser."
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"}
activate-venv
odoo-bin shell -d "$DATABASE" --config 'config/odoo.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"}
activate-venv
set-addons-path
echo "Make sure only one odoo process is running when initalizing the database."
odoo-bin -d "$DATABASE" -i base --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --stop-after-init --no-http --load-language "$ODOO_LANGUAGE"
}
function odoo-cloc() {
DATABASE="$1"
DATABASE=${DATABASE:="$GIT_BRANCH"}
activate-venv
odoo-bin cloc -d "$DATABASE" --config 'config/odoo.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 "Update index.html"
cd "$1" || exit
rst2html5 README.rst static/description/index.html
echo "Stage changes"
git add .
cd .. || exit
echo "Run pre-commit in $PWD"
pre-commit run --all-files
}
function update-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
activate-venv
set-addons-path
echo "Updating module $MODULE_NAME on $DATABASE ..."
odoo-bin -d "$DATABASE" -u "$MODULE_NAME" --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --stop-after-init --no-http
}
function generate-module-translation() {
if test -z "$1"; then echo "\$1 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
activate-venv
set-addons-path
echo "Generate $LANGUAGE tranlsation file for $MODULE_NAME on $DATABASE ..."
mkdir -p "$MODULE_PATH/i18n/"
odoo-bin -d "$DATABASE" --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --modules "$MODULE_NAME" -l "$LANGUAGE" --i18n-export "$MODULE_PATH/i18n/$LANGUAGE.po"
}
function list-addons() {
activate-venv
set-addons-path
echo "$ADDONS_PATH"
}
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
activate-venv
set-addons-path
echo "Installing module $MODULE_NAME on $DATABASE ..."
odoo-bin -d "$DATABASE" -i "$MODULE_NAME" --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --stop-after-init --no-http
}
function test-module() {
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
activate-venv
set-addons-path
echo "Testing module $MODULE_NAME on $DATABASE ..."
odoo-bin -d "$DATABASE" -i "$MODULE_NAME" --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --stop-after-init --test-tags /"$MODULE_NAME"
}
function test-coverage-module() {
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
activate-venv
set-addons-path
echo "Testing module $MODULE_NAME on $DATABASE ..."
coverage run odoo-bin -d "$DATABASE" -i "$MODULE_NAME" --config 'config/odoo.conf' --addons-path="$ADDONS_PATH" --stop-after-init --test-tags /"$MODULE_NAME"
}
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
activate-venv
set-addons-path
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.conf' --addons-path="$ADDONS_PATH" --no-http
}
function create-module() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
MODULE_NAME=$(basename "$1")
PARENT_DIR=$(dirname "$1")
activate-venv
echo "Scaffolding module $MODULE_NAME in $PARENT_DIR ..."
odoo-bin scaffold "$MODULE_NAME" "$PARENT_DIR" -t template/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 for $DATABASE:"
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_%';"
}
function reset-views() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
DATABASE="$1"
KEY=$(basename "$2")
# Use default database if second param is not given
if test -z "$2"; then
DATABASE="$GIT_BRANCH"
KEY=$(basename "$1")
fi
activate-venv
echo "Reset views for key $KEY"
echo "self.env['ir.ui.view'].search([('key', 'ilike', '$KEY')]).reset_arch(mode='hard')" |
odoo-bin shell -d "$DATABASE" --config 'config/odoo.conf' --no-http
}
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" || exit ; zip -r "../${1}2.zip" . ; cd ../.. || exit
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 git-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
echo "Switch branch to $1 in $SUBMODULE."
CWD=$(pwd)
cd "$SUBMODULE" || exit
git stash
git switch "$1"
cd "$CWD" || exit
done
}
function checkout-config-files() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
echo "Checkout config files $1 branch."
git checkout "$1" 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 from $1 branch."
git checkout "$1" $(tr '\n' ' ' < ./config/checkout_files)
}
function checkout() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
if [[ -n "$2" ]]; then
GIT_BRANCH="$2"
fi
echo "Switch branch."
git switch "$1"
git-update-submodules
git-switch-branch "$1"
checkout-config-files "$GIT_BRANCH"
}
function checkout-revision() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
cd odoo || exit
git checkout "$1"
cd .. || exit
cd enterprise || exit
git checkout "$1"
cd .. || exit
cd themes || exit
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" || exit
if [ -z "$UPDATE" ]; then
git pull
fi;
cd "$CWD" || exit
done
}
function release-module() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
VERSION=$(get-module-version "$1")
cd "$1" || exit
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 || exit
rm -f "$MODULE_NAME".zip
zip -q -r "$MODULE_NAME".zip "$MODULE_NAME"
cd .. || exit
}
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
activate-venv
echo "env['ir.module.module'].update_list()" | odoo-bin shell -d "$1" --config 'config/odoo.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-nextcloud-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/__manifest__.py" ]; 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
activate-venv
odoo-bin -s -d "$1" --config 'config/odoo.conf' --stop-after-init --no-http
}
function remove-submodule() {
if test -z "$1"; then echo "\$1 is empty."; exit; fi
echo "Deinit submodule"
git submodule deinit -f "$1"
echo "Move submodule to tmp folder"
mkdir -p tmp/"$1"
mv "$1" tmp/"$1"
echo "Remove submodule from work tree"
git rm -f "$1"
echo "Remove submodule from .git folder"
rm -rf .git/modules/"$1"
}
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" || exit
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" || exit
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-Build/tree/16.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 "# $TITLE" > "$DOCFILE"
echo "## [$TITLE](snippets/$MODULE.md)" >> snippets.md
SIDEBAR_ENTRIES+="'/snippets/$MODULE.md',\n"
# 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 -e "export default [$SIDEBAR_ENTRIES]" > .vuepress/sidebar.js
}
case "$1" in
activate-venv)
activate-venv
;;
disable-auto-install)
disable-auto-install
;;
save-config)
save-config "$2"
;;
checkout)
checkout "$2" "$3"
;;
checkout-config-files)
checkout-config-files "$2"
;;
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" "$3"
;;