Skip to content
Open
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
15 changes: 12 additions & 3 deletions odoorpc/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ def drop(self, password, db):
)
return data['result']

def duplicate(self, password, db, new_db):
"""Duplicate `db' as `new_db`.
def duplicate(self, password, db, new_db, neutralize_database=False):
"""Duplicate `db` as `new_db`. If `neutralize_database` is set to `True`,
the duplicated database will be neutralized (available from Odoo 16+).

>>> odoo.db.duplicate('super_admin_passwd', 'prod', 'test') # doctest: +SKIP

To neutralize the duplicated database (Odoo 16+):

>>> odoo.db.duplicate('super_admin_passwd', 'prod', 'test', neutralize_database=True) # doctest: +SKIP

The super administrator password is required to perform this method.

*Python 2:*
Expand All @@ -241,12 +246,16 @@ def duplicate(self, password, db, new_db):
:raise: :class:`odoorpc.error.RPCError` (access denied / wrong database)
:raise: `urllib.error.URLError` (connection error)
"""
args = [password, db, new_db]
# neutralize_database parameter is only available from Odoo 16+
if neutralize_database and v(self._odoo.version)[0] >= 16:
args.append(neutralize_database)
self._odoo.json(
'/jsonrpc',
{
'service': 'db',
'method': 'duplicate_database',
'args': [password, db, new_db],
'args': args,
},
)

Expand Down
11 changes: 11 additions & 0 deletions odoorpc/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ def test_db_duplicate(self):
self.env['super_pwd'], self.env['db'], new_database
)

def test_db_duplicate_with_neutralization(self):
date = datetime.strftime(datetime.today(), '%Y%m%d_%Hh%Mm%S')
new_database = "{}_{}_neutralized".format(self.env['db'], date)
self.databases.append(new_database)
self.odoo.db.duplicate(
self.env['super_pwd'], self.env['db'], new_database,
neutralize_database=True
)
# Check that database was created
self.assertIn(new_database, self.odoo.db.list())

def test_db_duplicate_wrong_database(self):
date = datetime.strftime(datetime.today(), '%Y%m%d_%Hh%Mm%S')
new_database = "{}_{}".format(self.env['db'], date)
Expand Down