- Explication about general usage of code generator - How to generate i18n translation - How to synchronize code_generator with module
3.7 KiB
How to generate code
Never run this on production environment, this create circular dependencies and will cause frustration to clean damage.
Modules
############ ################## ##########
# Template # -> # Code_Generator # -> # Module #
############ ################## ##########
- [A Template generates a Template or a Code_Generator.](Create your first code generator)
- A Code_Generator generates a Module.
- A Template reads a Module to generate a Code_Generator.
Prepare a DB
This will destroy and create database named code_generator.
make db_restore_erplibre_base_db_code_generator
Create your first Code_Generator
Edit Code Generator Demo and update # TODO HUMAN:
Generate a Template
By default, code_generator_demo generate itself, code_generator_demo.
Name your module begin with MODULE_NAME = "code_generator_template_"
The value "enable_template_code_generator_demo" at False to create a new template module, else this will recreate code_generator_demo.
value["enable_template_code_generator_demo"] = True
Example, to generate the module code_generator_template_demo_website_snippet, change value
MODULE_NAME = "code_generator_template_demo_website_snippet"
[...]
value["enable_template_website_snippet_view"] = True
[...]
lst_depend = [
"code_generator",
"code_generator_website_snippet",
]
Generate new module, this will overwrite code_generator_template_demo_website_snippet:
make addons_install_code_generator_demo
Generate a Code_Generator
Name your module begin with MODULE_NAME = "code_generator_demo_"
Disable enable_template_code_generator_demo
value["enable_template_code_generator_demo"] = False
Continue the example, you generated the template code_generator_template_demo_website_snippet, this will overwrite code_generator_demo_website_snippet:
./install_addon.sh code_generator code_generator_template_demo_website_snippet
Create your first Module
Continue example of code_generator_demo_website_snippet to generate your first module. Update next value:
"application": True,
"category_id": env.ref("base.module_category_website").id,
[...]
# Add dependencies
lst_depend = [
"website",
]
Generate your module:
./install_addon.sh code_generator code_generator_demo_website_snippet
Now, you can test it! Note, you cannot install a generated module with is code_generator associated, because duplicated models! Generate your module:
# Optional, reset test database
make db_restore_erplibre_base_db_test
./install_addon.sh test demo_website_snippet
How to generate i18n translation
You need a template and a module. Be sure you have this line in template:
new_module_path = os.path.join(path_module_generate, new_module_name)
code_generator_writer.set_module_translator(new_module_name, new_module_path)
First, install the module, example demo_portal, and after the template, example code_generator_template_demo_portal
make db_restore_erplibre_base_db_code_generator
./install_addon.sh test demo_portal
./install_addon.sh test code_generator_template_demo_portal
Sync Code_Generator fields from Module
This reduce time of programming a Code_Generator with sync module field with Template.
You need a Template, a Code_Generator with his Module. Install the Module first in clean database and install Template, this will generate the Code_generator, use enable_sync_template at True.
Example
make db_restore_erplibre_base_db_code_generator
./install_addon.sh test demo_portal
./install_addon.sh test code_generator_template_demo_portal