From 724df8a5708729629e2f38ac68b22a6d94f058b9 Mon Sep 17 00:00:00 2001 From: Michele Date: Tue, 16 May 2023 15:39:41 +0000 Subject: [PATCH] [IMP] core: new neutralize flag on database restore and database duplicate dialog Before this PR: The only way to neutralize the database is running cli command neutralize After this PR: There is a new checkbox "neutralize database" in Duplicate database and Restore database dialog that neutralize the database after duplication/restore. I also moved the neutralization code to the external module so it can be called also outside the cli . closes odoo/odoo#122185 X-original-commit: 616740e9d09b3d0376be43ed1489e390f6f5823e Signed-off-by: Julien Castiaux (juc) --- addons/web/controllers/database.py | 8 ++++---- .../web/static/src/public/database_manager.qweb.html | 12 ++++++++++++ odoo/cli/db.py | 12 ++++++++++-- odoo/cli/neutralize.py | 9 ++++----- odoo/modules/neutralize.py | 9 +++++++++ odoo/service/db.py | 9 +++++++-- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/addons/web/controllers/database.py b/addons/web/controllers/database.py index f797a4663f1..7168a5d2eeb 100644 --- a/addons/web/controllers/database.py +++ b/addons/web/controllers/database.py @@ -88,14 +88,14 @@ class Database(http.Controller): return self._render_template(error=error) @http.route('/web/database/duplicate', type='http', auth="none", methods=['POST'], csrf=False) - def duplicate(self, master_pwd, name, new_name): + def duplicate(self, master_pwd, name, new_name, neutralize_database=False): insecure = odoo.tools.config.verify_admin_password('admin') if insecure and master_pwd: dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd]) try: if not re.match(DBNAME_PATTERN, new_name): raise Exception(_('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot are allowed.')) - dispatch_rpc('db', 'duplicate_database', [master_pwd, name, new_name]) + dispatch_rpc('db', 'duplicate_database', [master_pwd, name, new_name, neutralize_database]) if request.db == name: request.env.cr.close() # duplicating a database leads to an unusable cursor return request.redirect('/web/database/manager') @@ -141,7 +141,7 @@ class Database(http.Controller): return self._render_template(error=error) @http.route('/web/database/restore', type='http', auth="none", methods=['POST'], csrf=False) - def restore(self, master_pwd, backup_file, name, copy=False): + def restore(self, master_pwd, backup_file, name, copy=False, neutralize_database=False): insecure = odoo.tools.config.verify_admin_password('admin') if insecure and master_pwd: dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd]) @@ -150,7 +150,7 @@ class Database(http.Controller): db.check_super(master_pwd) with tempfile.NamedTemporaryFile(delete=False) as data_file: backup_file.save(data_file) - db.restore_db(name, data_file.name, str2bool(copy)) + db.restore_db(name, data_file.name, str2bool(copy), neutralize_database) return request.redirect('/web/database/manager') except Exception as e: error = "Database restore error: %s" % (str(e) or repr(e)) diff --git a/addons/web/static/src/public/database_manager.qweb.html b/addons/web/static/src/public/database_manager.qweb.html index 8c4b6df6698..a194e8354d8 100644 --- a/addons/web/static/src/public/database_manager.qweb.html +++ b/addons/web/static/src/public/database_manager.qweb.html @@ -134,6 +134,12 @@ +
+ +
+ +
+

In order to avoid conflicts between databases, Odoo needs to know if this database was moved or copied.
@@ -211,6 +217,12 @@ +

+ +
+ +
+