diff --git a/odoo/cli/__init__.py b/odoo/cli/__init__.py index 070cd7e96f2..277e25197e2 100644 --- a/odoo/cli/__init__.py +++ b/odoo/cli/__init__.py @@ -14,3 +14,4 @@ from . import shell from . import start from . import populate from . import tsconfig +from . import neutralize diff --git a/odoo/cli/neutralize.py b/odoo/cli/neutralize.py new file mode 100644 index 00000000000..bc7b9a40b79 --- /dev/null +++ b/odoo/cli/neutralize.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging +import optparse +import sys + +import odoo + +from pathlib import Path + +from . import Command + +_logger = logging.getLogger(__name__) + + +class Neutralize(Command): + """neutralize a database""" + + def run(self, args): + parser = odoo.tools.config.parser + group = optparse.OptionGroup(parser, "Neutralize", "Neutralize the database specified by the `-d` argument.") + parser.add_option_group(group) + odoo.tools.config.parse_config(args) + + dbname = odoo.tools.config['db_name'] + if not dbname: + _logger.error('Neutralize command needs a database name. Use "-d" argument') + sys.exit(1) + + registry = odoo.registry(dbname) + _logger.info('Starting database neutralization') + try: + with registry.cursor() as cr: + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + for model in env.values(): + model._neutralize() + with open(Path(__file__).parent / 'neutralize_watermarks.xml', 'rb') as f: + odoo.tools.convert_xml_import(cr, "__neutralize__", f) + except Exception: + _logger.error('An exception occured during neutralization.') + raise + _logger.info('Neutralization finished') diff --git a/odoo/cli/neutralize_watermarks.xml b/odoo/cli/neutralize_watermarks.xml new file mode 100644 index 00000000000..d3c87228c13 --- /dev/null +++ b/odoo/cli/neutralize_watermarks.xml @@ -0,0 +1,39 @@ + + + + + diff --git a/odoo/models.py b/odoo/models.py index 799e8e27abf..fa66eaab6b4 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6688,6 +6688,12 @@ Fields: records_batches.append(self.create(create_values)) return self.concat(*records_batches) + def _neutralize(self): + """ Neutralize this model's records. + This should prevent the database from connecting to external services. + """ + return + collections.Set.register(BaseModel) # not exactly true as BaseModel doesn't have index or count