Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[initdb] add user and lang options #101

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ 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_US]
--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.
--unless-exists Don't report error if database already exists.
--help Show this message and exit.

Expand Down
43 changes: 41 additions & 2 deletions click_odoo_contrib/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def _db_storage(self):
finally:
IrAttachment._storage = orig

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"
)
)

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):
with _patch_ir_attachment_store(force_db_storage):
Expand All @@ -85,6 +99,7 @@ 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):
Expand Down Expand Up @@ -379,6 +394,26 @@ def trim_age(self, max_age):
is_flag=True,
help="Don't report error if database already exists.",
)
@click.option(
"--lang",
default='en_US',
show_default=True,
help="Language to use for the new database",
)
@click.option(
"--password",
required=False,
help="Password for the admin user",
)
@click.option(
"--login",
required=False,
help="Login for the admin user",
)
@click.option(
"--country",
help="Country for the new database",
)
def main(
env,
new_database,
Expand All @@ -389,6 +424,10 @@ def main(
cache_max_age,
cache_max_size,
unless_exists,
lang,
password,
login,
country,
):
"""Create an Odoo database with pre-installed modules.

Expand All @@ -408,9 +447,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)
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."
Expand Down