From b4ca9493cf9de22f4b8cef7edf5c3163b0aad3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 6 May 2021 10:28:44 +0200 Subject: [PATCH] Implement registry change signaling --- click_odoo/env.py | 59 ++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/click_odoo/env.py b/click_odoo/env.py index ec3ecef..5a2a841 100644 --- a/click_odoo/env.py +++ b/click_odoo/env.py @@ -29,34 +29,35 @@ @contextmanager def OdooEnvironment(database, rollback=False, **kwargs): with Environment.manage(): - registry = odoo.registry(database) - try: - with registry.cursor() as cr: - uid = odoo.SUPERUSER_ID - try: - ctx = Environment(cr, uid, {})["res.users"].context_get() - except Exception as e: - ctx = {"lang": "en_US"} - # this happens, for instance, when there are new - # fields declared on res_partner which are not yet - # in the database (before -u) - _logger.warning( - "Could not obtain a user context, continuing " - "anyway with a default context. Error was: %s", - e, - ) - env = Environment(cr, uid, ctx) - cr.rollback() - yield env - if rollback: + registry = odoo.registry(database).check_signaling() + with registry.manage_changes(): + try: + with registry.cursor() as cr: + uid = odoo.SUPERUSER_ID + try: + ctx = Environment(cr, uid, {})["res.users"].context_get() + except Exception as e: + ctx = {"lang": "en_US"} + # this happens, for instance, when there are new + # fields declared on res_partner which are not yet + # in the database (before -u) + _logger.warning( + "Could not obtain a user context, continuing " + "anyway with a default context. Error was: %s", + e, + ) + env = Environment(cr, uid, ctx) cr.rollback() + yield env + if rollback: + cr.rollback() + else: + cr.commit() + finally: + if odoo.tools.parse_version( + odoo.release.version + ) < odoo.tools.parse_version("10.0"): + odoo.modules.registry.RegistryManager.delete(database) else: - cr.commit() - finally: - if odoo.tools.parse_version( - odoo.release.version - ) < odoo.tools.parse_version("10.0"): - odoo.modules.registry.RegistryManager.delete(database) - else: - odoo.modules.registry.Registry.delete(database) - odoo.sql_db.close_db(database) + odoo.modules.registry.Registry.delete(database) + odoo.sql_db.close_db(database)