Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
25 changes: 18 additions & 7 deletions click_odoo_contrib/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -404,6 +414,7 @@ def trim_age(self, max_age):
)
@click.option(
"--phone",
required=False,
help="Phone of the admin user",
)
def main(
Expand Down Expand Up @@ -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."
Expand All @@ -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)
Expand Down