Skip to content

Commit

Permalink
Implement registry change signaling
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed May 9, 2021
1 parent b65f976 commit b4ca949
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions click_odoo/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b4ca949

Please sign in to comment.