Merge branch 'new_project_with_model'
- new_project script can create models from configuration - improve makefile format
This commit is contained in:
commit
ac869f5691
5 changed files with 114 additions and 34 deletions
26
Makefile
26
Makefile
|
|
@ -624,6 +624,15 @@ test_full_fast:
|
|||
# TODO This test is broken in parallel
|
||||
#./script/make.sh test_code_generator_hello_world
|
||||
|
||||
.PHONY: test_full_fast_debug
|
||||
test_full_fast_debug:
|
||||
./script/make.sh clean
|
||||
# Need to create a BD to create cache _cache_erplibre_base
|
||||
./script/database/db_restore.py --database test
|
||||
./script/test/run_parallel_test.py --keep_cache
|
||||
# TODO This test is broken in parallel
|
||||
#./script/make.sh test_code_generator_hello_world
|
||||
|
||||
.PHONY: test_full_fast_coverage
|
||||
test_full_fast_coverage:
|
||||
./script/make.sh clean
|
||||
|
|
@ -861,11 +870,7 @@ open_terminal:
|
|||
############
|
||||
.PHONY: format
|
||||
format:
|
||||
./script/make.sh format_code_generator
|
||||
./script/make.sh format_code_generator_template
|
||||
./script/make.sh format_script
|
||||
./script/make.sh format_erplibre_addons
|
||||
./script/make.sh format_supported_addons
|
||||
parallel ::: "./script/make.sh format_code_generator" "./script/make.sh format_code_generator_template" "./script/make.sh format_script" "./script/make.sh format_erplibre_addons" "./script/make.sh format_supported_addons"
|
||||
|
||||
.PHONY: format_code_generator
|
||||
format_code_generator:
|
||||
|
|
@ -1106,11 +1111,12 @@ stat_module_evolution_per_year_OCA:
|
|||
# documentation all
|
||||
.PHONY: doc
|
||||
doc:
|
||||
./script/make.sh doc_dev
|
||||
./script/make.sh doc_migration
|
||||
./script/make.sh doc_test
|
||||
./script/make.sh doc_user
|
||||
./script/make.sh doc_markdown
|
||||
# ./script/make.sh doc_dev
|
||||
# ./script/make.sh doc_migration
|
||||
# ./script/make.sh doc_test
|
||||
# ./script/make.sh doc_user
|
||||
# ./script/make.sh doc_markdown
|
||||
parallel ::: "./script/make.sh doc_dev" "./script/make.sh doc_migration" "./script/make.sh doc_test" "./script/make.sh doc_user" "./script/make.sh doc_markdown"
|
||||
|
||||
# documentation clean all
|
||||
.PHONY: doc_clean
|
||||
|
|
|
|||
3
run.sh
3
run.sh
|
|
@ -12,6 +12,9 @@ if [ ! -f "${CONFIG_PATH}" ]; then
|
|||
fi
|
||||
|
||||
python3 ./odoo/odoo-bin -c ${CONFIG_PATH} --limit-time-real 99999 --limit-time-cpu 99999 --limit-memory-hard=0 "$@"
|
||||
# When need more memory RAM for instance by force
|
||||
#python3 ./odoo/odoo-bin -c ${CONFIG_PATH} --limit-time-real 99999 --limit-time-cpu 99999 --limit-memory-soft=8589934592 --limit-memory-hard=10737418240 $@
|
||||
|
||||
retVal=$?
|
||||
if [[ $retVal -ne 0 ]]; then
|
||||
echo "Error run.sh"
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@ import os
|
|||
import sys
|
||||
import tempfile
|
||||
import uuid
|
||||
import json
|
||||
|
||||
from git import Repo
|
||||
from git.exc import InvalidGitRepositoryError, NoSuchPathError
|
||||
|
||||
|
||||
CODE_GENERATOR_DIRECTORY = "./addons/TechnoLibre_odoo-code-generator-template/"
|
||||
CODE_GENERATOR_DEMO_NAME = "code_generator_demo"
|
||||
KEY_REPLACE_CODE_GENERATOR_DEMO = 'MODULE_NAME = "%s"'
|
||||
|
|
@ -24,10 +26,12 @@ logging.basicConfig(
|
|||
)
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
# TODO Check if exist DONE
|
||||
# TODO change name into code_generator_demo DONE
|
||||
# TODO Create code generator empty module with demo DONE
|
||||
# TODO revert code_generator_demo DONE
|
||||
|
||||
class Struct:
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
|
||||
|
||||
# TODO execute create_code_generator_from_existing_module.sh with force option
|
||||
# TODO open web interface on right database already selected locally with make run
|
||||
|
||||
|
|
@ -53,6 +57,11 @@ def get_config():
|
|||
required=True,
|
||||
help="Module name to create",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
help="""Configuration to create models with fields and type. JSON style.
|
||||
Example : "{\"model\":[{\"name\":\"a\",\"fields\":[{\"name\":\"a\",\"type\":\"char\"}]}]}" """,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--directory_code_generator",
|
||||
help="The directory of the code_generator to use.",
|
||||
|
|
@ -106,6 +115,7 @@ class ProjectManagement:
|
|||
force=False,
|
||||
keep_bd_alive=False,
|
||||
coverage=False,
|
||||
config="",
|
||||
):
|
||||
self.force = force
|
||||
self._coverage = coverage
|
||||
|
|
@ -156,6 +166,16 @@ class ProjectManagement:
|
|||
default=template_name
|
||||
)
|
||||
|
||||
self._parse_config(config)
|
||||
|
||||
def _parse_config(self, config):
|
||||
if not config:
|
||||
self.config = {}
|
||||
self.config_lst_model = []
|
||||
else:
|
||||
self.config = json.loads(config)
|
||||
self.config_lst_model = self.config.get("model")
|
||||
|
||||
def _generate_cg_name(self, default=""):
|
||||
if default:
|
||||
return default
|
||||
|
|
@ -243,6 +263,7 @@ class ProjectManagement:
|
|||
return False
|
||||
|
||||
cg_path = os.path.join(self.cg_directory, self.cg_name)
|
||||
cg_hooks_py = os.path.join(cg_path, "hooks.py")
|
||||
if not self.force and not self.validate_path_ready_to_be_override(
|
||||
self.cg_name, self.cg_directory, path=cg_path
|
||||
):
|
||||
|
|
@ -357,15 +378,26 @@ class ProjectManagement:
|
|||
else:
|
||||
_logger.info(f"Module template exists '{template_path}'")
|
||||
|
||||
self.search_and_replace_file(
|
||||
template_hooks_py,
|
||||
[
|
||||
(
|
||||
'value["enable_template_wizard_view"] = False',
|
||||
'value["enable_template_wizard_view"] = True',
|
||||
),
|
||||
],
|
||||
)
|
||||
lst_template_hooks_py_replace = [
|
||||
(
|
||||
'value["enable_template_wizard_view"] = False',
|
||||
'value["enable_template_wizard_view"] = True',
|
||||
),
|
||||
]
|
||||
|
||||
# Add model from config
|
||||
if self.config:
|
||||
str_lst_model = "; ".join(
|
||||
[a.get("name") for a in self.config_lst_model]
|
||||
)
|
||||
old_str = 'value["template_model_name"] = ""'
|
||||
new_str = f'value["template_model_name"] = "{str_lst_model}"'
|
||||
lst_template_hooks_py_replace.append((old_str, new_str))
|
||||
|
||||
self.search_and_replace_file(
|
||||
template_hooks_py,
|
||||
lst_template_hooks_py_replace,
|
||||
)
|
||||
|
||||
# Execute all
|
||||
bd_name_template = (
|
||||
|
|
@ -431,6 +463,43 @@ class ProjectManagement:
|
|||
os.system(cmd)
|
||||
_logger.info(f"========= GENERATE {self.cg_name} =========")
|
||||
|
||||
# Add field from config
|
||||
if self.config:
|
||||
lst_update_cg = []
|
||||
for model in self.config_lst_model:
|
||||
model_name = model.get("name")
|
||||
dct_field = {}
|
||||
for a in model.get("fields"):
|
||||
dct_value = {"ttype": a.get("type")}
|
||||
if "relation" in a.keys():
|
||||
dct_value["relation"] = a["relation"]
|
||||
if "relation_field" in a.keys():
|
||||
dct_value["relation_field"] = a["relation_field"]
|
||||
if "description" in a.keys():
|
||||
dct_value["field_description"] = a["description"]
|
||||
dct_field[a.get("name")] = dct_value
|
||||
if "name" not in dct_field.keys():
|
||||
dct_field["name"] = {"ttype": "char"}
|
||||
old_str = (
|
||||
f'model_model = "{model_name}"\n '
|
||||
" code_generator_id.add_update_model(model_model)"
|
||||
)
|
||||
new_str = (
|
||||
f'model_model = "{model_name}"\n dct_field ='
|
||||
f" {dct_field}\n "
|
||||
" code_generator_id.add_update_model(model_model,"
|
||||
" dct_field=dct_field)"
|
||||
)
|
||||
lst_update_cg.append((old_str, new_str))
|
||||
|
||||
# Force add menu and access
|
||||
lst_update_cg.append(('"disable_generate_menu": True,', ""))
|
||||
lst_update_cg.append(('"disable_generate_access": True,', ""))
|
||||
self.search_and_replace_file(
|
||||
cg_hooks_py,
|
||||
lst_update_cg,
|
||||
)
|
||||
|
||||
if self._coverage:
|
||||
cmd = (
|
||||
"./script/addons/coverage_install_addons_dev.sh"
|
||||
|
|
@ -509,6 +578,7 @@ def main():
|
|||
force=config.force,
|
||||
keep_bd_alive=config.keep_bd_alive,
|
||||
coverage=config.coverage,
|
||||
config=config.config,
|
||||
)
|
||||
if project.msg_error:
|
||||
return -1
|
||||
|
|
|
|||
|
|
@ -116,17 +116,17 @@ def main():
|
|||
f'get_{"_".join(url.replace("-", "_").strip("/").split("/"))}'
|
||||
)
|
||||
|
||||
# template = f"""
|
||||
# @http.route(
|
||||
# ["{url}"],
|
||||
# type="http",
|
||||
# auth="user",
|
||||
# website=True,
|
||||
# )
|
||||
# def {method_name}(self, **kw):
|
||||
# return request.env["ir.ui.view"].render_template(
|
||||
# "{module_name}.{view_id}",
|
||||
# )
|
||||
# template = f"""
|
||||
# @http.route(
|
||||
# ["{url}"],
|
||||
# type="http",
|
||||
# auth="user",
|
||||
# website=True,
|
||||
# )
|
||||
# def {method_name}(self, **kw):
|
||||
# return request.env["ir.ui.view"].render_template(
|
||||
# "{module_name}.{view_id}",
|
||||
# )
|
||||
template = f"""
|
||||
@http.route(
|
||||
["{url}"],
|
||||
|
|
|
|||
|
|
@ -1126,6 +1126,7 @@ async def run_code_generator_template_demo_internal_test(
|
|||
|
||||
return test_result, test_status
|
||||
|
||||
|
||||
async def run_code_generator_template_demo_internal_inherit_test(
|
||||
config,
|
||||
) -> Tuple[str, int]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue