From 38c01e014b263a58136266c6436dc90d85eab2c9 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 5 May 2022 00:48:44 +0200 Subject: [PATCH] wip --- .gitlab-ci.yml | 4 + odoo_openupgrade_wizard/cli.py | 2 + .../cli_install_from_csv.py | 84 +++++++++++++++++++ odoo_openupgrade_wizard/templates.py | 2 + 4 files changed, 92 insertions(+) create mode 100644 odoo_openupgrade_wizard/cli_install_from_csv.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3b532cc..0063383 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,9 @@ image: docker:18.09 +variables: + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + services: - docker:18.09-dind diff --git a/odoo_openupgrade_wizard/cli.py b/odoo_openupgrade_wizard/cli.py index 826b5ec..5a9e9d1 100644 --- a/odoo_openupgrade_wizard/cli.py +++ b/odoo_openupgrade_wizard/cli.py @@ -13,6 +13,7 @@ from odoo_openupgrade_wizard.cli_docker_build import docker_build from odoo_openupgrade_wizard.cli_execute_script import execute_script from odoo_openupgrade_wizard.cli_get_code import get_code from odoo_openupgrade_wizard.cli_init import init +from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv from odoo_openupgrade_wizard.cli_run import run from odoo_openupgrade_wizard.cli_test_dev import test_dev from odoo_openupgrade_wizard.cli_upgrade import upgrade @@ -106,6 +107,7 @@ main.add_command(init) main.add_command(get_code) main.add_command(docker_build) main.add_command(run) +main.add_command(install_from_csv) main.add_command(upgrade) main.add_command(execute_script) main.add_command(test_dev) diff --git a/odoo_openupgrade_wizard/cli_install_from_csv.py b/odoo_openupgrade_wizard/cli_install_from_csv.py new file mode 100644 index 0000000..5b62bd8 --- /dev/null +++ b/odoo_openupgrade_wizard/cli_install_from_csv.py @@ -0,0 +1,84 @@ +import csv + +import click +from loguru import logger + +from odoo_openupgrade_wizard.cli_options import ( + database_option, + get_migration_step_from_options, +) +from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo +from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance +from odoo_openupgrade_wizard.tools_postgres import ensure_database_exists + + +@click.command() +@database_option +@click.pass_context +def install_from_csv(ctx, database): + migration_step = get_migration_step_from_options(ctx, 1) + ensure_database_exists(database) + + # Get modules list from the CSV file + csv_path = ctx.obj["module_file_path"] + logger.info("Reading '%s' file ..." % csv_path) + module_names = [] + csvfile = open(csv_path, "r") + spamreader = csv.reader(csvfile, delimiter=",", quotechar='"') + for row in spamreader: + # Try to guess that a line is not correct + if not row[0]: + continue + if " " in row[0]: + continue + if any([x.isupper() for x in row[0]]): + continue + module_names.append(row[0]) + + module_names.sort() + logger.info("Found %d modules." % (len(module_names))) + logger.debug(module_names) + + try: + logger.info("Install 'base' module on %s database ..." % (database)) + run_odoo( + ctx, + migration_step, + database=database, + detached_container=True, + init="base", + ) + odoo_instance = OdooInstance(ctx, database) + + if "account" in module_names: + # Then, set correct country to the company of the current user + # Otherwise, due to poor design of Odoo, when installing account + # the US localization will be installed. + # (l10n_us + l10n_generic_coa) + country_code = ctx.obj["config"].get("default_country_code", "US") + countries = odoo_instance.browse_by_search( + "res.country", + [("code", "=", country_code)], + ) + if len(countries) != 1: + raise Exception( + "Unable to find a country, based on the code %s." + " countries found : %s " + % ( + country_code, + ", ".join([x.name for x in countries]), + ) + ) + logger.info( + "Configuring country of the main company with %s" + % (countries[0].name) + ) + odoo_instance.env.user.company_id.country_id = countries[0].id + + # Install modules + odoo_instance.install_modules(module_names) + + except (KeyboardInterrupt, SystemExit): + logger.info("Received Keyboard Interrupt or System Exiting...") + finally: + kill_odoo(ctx, migration_step) diff --git a/odoo_openupgrade_wizard/templates.py b/odoo_openupgrade_wizard/templates.py index 26905fc..d7cc5db 100644 --- a/odoo_openupgrade_wizard/templates.py +++ b/odoo_openupgrade_wizard/templates.py @@ -2,6 +2,7 @@ CONFIG_YML_TEMPLATE = """project_name: {{ project_name }} host_odoo_xmlrpc_port: 9069 host_postgres_port: 9432 +default_country_code: FR odoo_versions: {% for odoo_version in odoo_versions %} @@ -116,6 +117,7 @@ GIT_IGNORE_CONTENT = """ """ MODULES_CSV_TEMPLATE = """base,Base +account,Account Module product,Product web_responsive,Web Responsive Module """