From 1e18b5d07e7fcac38bdc1a723984fabf9a2e9fca Mon Sep 17 00:00:00 2001 From: Florian Chevalier Date: Fri, 10 Sep 2021 16:23:59 +0200 Subject: [PATCH 1/7] add user and lang options --- click_odoo_contrib/initdb.py | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index bb30c98..0db7941 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -65,9 +65,12 @@ def _db_storage(self): IrAttachment._storage = orig -def odoo_createdb(dbname, demo, module_names, force_db_storage): +def odoo_createdb(dbname, demo, module_names, force_db_storage, lang, password, login, country, phone): with _patch_ir_attachment_store(force_db_storage): - odoo.service.db._create_empty_database(dbname) +# odoo.service.db._create_empty_database(dbname) + + odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country, phone) + odoo.tools.config["init"] = dict.fromkeys(module_names, 1) odoo.tools.config["without_demo"] = not demo if _odoo_version < odoo.tools.parse_version("10"): @@ -379,6 +382,30 @@ def trim_age(self, max_age): is_flag=True, help="Don't report error if database already exists.", ) +@click.option( + "--lang", + default='en_EN', + show_default=True, + help="Language to use for the new database", +) +@click.option( + "--password", + help="Password for the admin user", +) +@click.option( + "--login", + help="Login for the admin user", +) +@click.option( + "--country", + default='GB', + show_default=True, + help="Country for the new database", +) +@click.option( + "--phone", + help="Phone of the admin user", +) def main( env, new_database, @@ -389,6 +416,11 @@ def main( cache_max_age, cache_max_size, unless_exists, + lang, + password, + login, + country, + phone, ): """Create an Odoo database with pre-installed modules. @@ -410,7 +442,7 @@ def main( module_names = [m.strip() for m in modules.split(",")] if not cache: if new_database: - odoo_createdb(new_database, demo, module_names, False) + odoo_createdb(new_database, demo, module_names, False, lang, password, login, country, phone) else: _logger.info( "Cache disabled and no new database name provided. " "Nothing to do." @@ -429,7 +461,7 @@ def main( ) refresh_module_list(new_database) else: - odoo_createdb(new_database, demo, module_names, True) + odoo_createdb(new_database, demo, module_names, True, lang, password, login, country, phone) dbcache.add(new_database, hashsum) if cache_max_size >= 0: dbcache.trim_size(cache_max_size) From 3f8750bfd2b29d32b5bf7be429ab49f4449a7253 Mon Sep 17 00:00:00 2001 From: "gael.torrecillas" Date: Fri, 15 Oct 2021 14:16:44 +0200 Subject: [PATCH 2/7] add new params for initdb. add login password lang and country (#1) * add new params for initdb. add login password lang and country * fix no cache with specific modules * fix no cache with specific modules --- README.rst | 10 ++++++++++ click_odoo_contrib/initdb.py | 25 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 7194455..4e1fa50 100644 --- a/README.rst +++ b/README.rst @@ -108,6 +108,16 @@ click-odoo-initdb (stable) 30] --cache-max-size INTEGER Keep N most recently used cache templates. Use -1 to disable. Use 0 to empty cache. [default: 5] + --lang TEXT Install default language on your company. + Imcompatibility with --cache. [default: en_EN] + --password TEXT Set admin password. + Imcompatibility with --cache. [default: admin] + --login TEXT Set admin login. + Imcompatibility with --cache. [default: admin] + --country TEXT Set default country. + Imcompatibility with --cache. [default: GB] + --phone TEXT Set default phone. + Imcompatibility with --cache. --unless-exists Don't report error if database already exists. --help Show this message and exit. diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index 0db7941..5e105f6 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -64,13 +64,20 @@ def _db_storage(self): finally: IrAttachment._storage = orig +def odoo_createdb_without_cache(dbname, demo, module_names, lang, password, login, country, phone): + odoo.tools.config["init"] = dict.fromkeys(module_names, 1) + odoo.service.db._exp_create_database(dbname, demo, lang, password, login, country, phone) -def odoo_createdb(dbname, demo, module_names, force_db_storage, lang, password, login, country, phone): - with _patch_ir_attachment_store(force_db_storage): -# odoo.service.db._create_empty_database(dbname) + _logger.info( + click.style( + "Created new Odoo database {dbname}.".format(**locals()), fg="green" + ) + ) - odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country, phone) +def odoo_createdb(dbname, demo, module_names, force_db_storage): + with _patch_ir_attachment_store(force_db_storage): + odoo.service.db._create_empty_database(dbname) odoo.tools.config["init"] = dict.fromkeys(module_names, 1) odoo.tools.config["without_demo"] = not demo if _odoo_version < odoo.tools.parse_version("10"): @@ -88,6 +95,7 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage, lang, password, odoo.sql_db.close_db(dbname) + def _fnmatch(filename, patterns): for pattern in patterns: if fnmatch(filename, pattern): @@ -390,10 +398,12 @@ def trim_age(self, max_age): ) @click.option( "--password", + required=False, help="Password for the admin user", ) @click.option( "--login", + required=False, help="Login for the admin user", ) @click.option( @@ -404,6 +414,7 @@ def trim_age(self, max_age): ) @click.option( "--phone", + required=False, help="Phone of the admin user", ) def main( @@ -440,9 +451,9 @@ def main( click.echo(click.style(msg, fg="yellow")) return module_names = [m.strip() for m in modules.split(",")] - if not cache: + if not cache : if new_database: - odoo_createdb(new_database, demo, module_names, False, lang, password, login, country, phone) + odoo_createdb_without_cache(new_database, demo,module_names, lang, password, login, country, phone) else: _logger.info( "Cache disabled and no new database name provided. " "Nothing to do." @@ -461,7 +472,7 @@ def main( ) refresh_module_list(new_database) else: - odoo_createdb(new_database, demo, module_names, True, lang, password, login, country, phone) + odoo_createdb(new_database, demo, module_names, True) dbcache.add(new_database, hashsum) if cache_max_size >= 0: dbcache.trim_size(cache_max_size) From 29f1468e8005ece5511a8885655152df6cc957ce Mon Sep 17 00:00:00 2001 From: Florian Chevalier Date: Fri, 22 Oct 2021 15:47:02 +0200 Subject: [PATCH 3/7] fix odoo_createdb_without_cache and default country --- README.rst | 2 +- click_odoo_contrib/initdb.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 4e1fa50..6c4d45d 100644 --- a/README.rst +++ b/README.rst @@ -115,7 +115,7 @@ click-odoo-initdb (stable) --login TEXT Set admin login. Imcompatibility with --cache. [default: admin] --country TEXT Set default country. - Imcompatibility with --cache. [default: GB] + Imcompatibility with --cache. --phone TEXT Set default phone. Imcompatibility with --cache. --unless-exists Don't report error if database already exists. diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index 5e105f6..a06296b 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -66,13 +66,17 @@ def _db_storage(self): def odoo_createdb_without_cache(dbname, demo, module_names, lang, password, login, country, phone): odoo.tools.config["init"] = dict.fromkeys(module_names, 1) - odoo.service.db._exp_create_database(dbname, demo, lang, password, login, country, phone) + odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country, phone) _logger.info( click.style( "Created new Odoo database {dbname}.".format(**locals()), fg="green" ) ) + + with odoo.sql_db.db_connect(dbname).cursor() as cr: + _save_installed_checksums(cr) + odoo.sql_db.close_db(dbname) def odoo_createdb(dbname, demo, module_names, force_db_storage): @@ -408,8 +412,6 @@ def trim_age(self, max_age): ) @click.option( "--country", - default='GB', - show_default=True, help="Country for the new database", ) @click.option( From e58526f093473dc0aab8bd092167ef18cc3c9fcf Mon Sep 17 00:00:00 2001 From: "gael.torrecillas" Date: Fri, 22 Oct 2021 16:12:22 +0200 Subject: [PATCH 4/7] remove phone (odoo 10 does not support phone in arguments) (#2) --- README.rst | 2 -- click_odoo_contrib/initdb.py | 12 +++--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 6c4d45d..b324764 100644 --- a/README.rst +++ b/README.rst @@ -116,8 +116,6 @@ click-odoo-initdb (stable) Imcompatibility with --cache. [default: admin] --country TEXT Set default country. Imcompatibility with --cache. - --phone TEXT Set default phone. - Imcompatibility with --cache. --unless-exists Don't report error if database already exists. --help Show this message and exit. diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index a06296b..0ac2076 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -64,9 +64,9 @@ def _db_storage(self): finally: IrAttachment._storage = orig -def odoo_createdb_without_cache(dbname, demo, module_names, lang, password, login, country, phone): +def odoo_createdb_without_cache(dbname, demo, module_names, lang, password, login, country): odoo.tools.config["init"] = dict.fromkeys(module_names, 1) - odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country, phone) + odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country) _logger.info( click.style( @@ -414,11 +414,6 @@ def trim_age(self, max_age): "--country", help="Country for the new database", ) -@click.option( - "--phone", - required=False, - help="Phone of the admin user", -) def main( env, new_database, @@ -433,7 +428,6 @@ def main( password, login, country, - phone, ): """Create an Odoo database with pre-installed modules. @@ -455,7 +449,7 @@ def main( module_names = [m.strip() for m in modules.split(",")] if not cache : if new_database: - odoo_createdb_without_cache(new_database, demo,module_names, lang, password, login, country, phone) + odoo_createdb_without_cache(new_database, demo,module_names, lang, password, login, country) else: _logger.info( "Cache disabled and no new database name provided. " "Nothing to do." From 97f26778501ea334e05100346390f7233aec9dad Mon Sep 17 00:00:00 2001 From: MAG-Florian-Chevalier <73696844+MAG-Florian-Chevalier@users.noreply.github.com> Date: Fri, 14 Jan 2022 15:14:37 +0100 Subject: [PATCH 5/7] update default lang --- click_odoo_contrib/initdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index 0ac2076..50cf9b2 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -396,7 +396,7 @@ def trim_age(self, max_age): ) @click.option( "--lang", - default='en_EN', + default='en_US', show_default=True, help="Language to use for the new database", ) From 46af7d8354ecfe71de18cf001d2c4220d8746531 Mon Sep 17 00:00:00 2001 From: MAG-Florian-Chevalier <73696844+MAG-Florian-Chevalier@users.noreply.github.com> Date: Fri, 14 Jan 2022 15:15:22 +0100 Subject: [PATCH 6/7] update default lang --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b324764..c57d636 100644 --- a/README.rst +++ b/README.rst @@ -109,7 +109,7 @@ click-odoo-initdb (stable) --cache-max-size INTEGER Keep N most recently used cache templates. Use -1 to disable. Use 0 to empty cache. [default: 5] --lang TEXT Install default language on your company. - Imcompatibility with --cache. [default: en_EN] + Imcompatibility with --cache. [default: en_US] --password TEXT Set admin password. Imcompatibility with --cache. [default: admin] --login TEXT Set admin login. From 5410eb03c99491cc8a7500d45e128c561da3141d Mon Sep 17 00:00:00 2001 From: Florian Chevalier Date: Fri, 14 Jan 2022 15:24:37 +0100 Subject: [PATCH 7/7] run precommit --- README.rst | 2 +- click_odoo_contrib/initdb.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index c57d636..249e1e4 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ click-odoo-initdb (stable) 30] --cache-max-size INTEGER Keep N most recently used cache templates. Use -1 to disable. Use 0 to empty cache. [default: 5] - --lang TEXT Install default language on your company. + --lang TEXT Install default language on your company. Imcompatibility with --cache. [default: en_US] --password TEXT Set admin password. Imcompatibility with --cache. [default: admin] diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index 50cf9b2..348ccfa 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -64,16 +64,19 @@ def _db_storage(self): finally: IrAttachment._storage = orig -def odoo_createdb_without_cache(dbname, demo, module_names, lang, password, login, country): + +def odoo_createdb_without_cache( + dbname, demo, module_names, lang, password, login, country +): odoo.tools.config["init"] = dict.fromkeys(module_names, 1) odoo.service.db.exp_create_database(dbname, demo, lang, password, login, country) _logger.info( click.style( - "Created new Odoo database {dbname}.".format(**locals()), fg="green" + "Created new Odoo database {dbname}.".format(**locals()), fg="green" ) ) - + with odoo.sql_db.db_connect(dbname).cursor() as cr: _save_installed_checksums(cr) odoo.sql_db.close_db(dbname) @@ -99,7 +102,6 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage): odoo.sql_db.close_db(dbname) - def _fnmatch(filename, patterns): for pattern in patterns: if fnmatch(filename, pattern): @@ -396,7 +398,7 @@ def trim_age(self, max_age): ) @click.option( "--lang", - default='en_US', + default="en_US", show_default=True, help="Language to use for the new database", ) @@ -447,9 +449,11 @@ def main( click.echo(click.style(msg, fg="yellow")) return module_names = [m.strip() for m in modules.split(",")] - if not cache : + if not cache: if new_database: - odoo_createdb_without_cache(new_database, demo,module_names, lang, password, login, country) + odoo_createdb_without_cache( + new_database, demo, module_names, lang, password, login, country + ) else: _logger.info( "Cache disabled and no new database name provided. " "Nothing to do."