Skip to content

Commit 456529e

Browse files
committed
Implement registry change signaling
1 parent fed90ea commit 456529e

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

click_odoo/env.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,30 @@
1212
@contextmanager
1313
def OdooEnvironment(database, rollback=False, **kwargs):
1414
with environment_manage():
15-
registry = odoo.modules.registry.Registry(database)
16-
try:
17-
with registry.cursor() as cr:
18-
uid = odoo.SUPERUSER_ID
19-
try:
20-
ctx = Environment(cr, uid, {})["res.users"].context_get()
21-
except Exception as e:
22-
ctx = {"lang": "en_US"}
23-
# this happens, for instance, when there are new
24-
# fields declared on res_partner which are not yet
25-
# in the database (before -u)
26-
_logger.warning(
27-
"Could not obtain a user context, continuing "
28-
"anyway with a default context. Error was: %s",
29-
e,
30-
)
31-
env = Environment(cr, uid, ctx)
32-
cr.rollback()
33-
yield env
34-
if rollback:
15+
registry = odoo.modules.registry(database).check_signaling()
16+
with registry.manage_changes():
17+
try:
18+
with registry.cursor() as cr:
19+
uid = odoo.SUPERUSER_ID
20+
try:
21+
ctx = Environment(cr, uid, {})["res.users"].context_get()
22+
except Exception as e:
23+
ctx = {"lang": "en_US"}
24+
# this happens, for instance, when there are new
25+
# fields declared on res_partner which are not yet
26+
# in the database (before -u)
27+
_logger.warning(
28+
"Could not obtain a user context, continuing "
29+
"anyway with a default context. Error was: %s",
30+
e,
31+
)
32+
env = Environment(cr, uid, ctx)
3533
cr.rollback()
36-
else:
37-
cr.commit()
38-
finally:
39-
odoo.modules.registry.Registry.delete(database)
40-
odoo.sql_db.close_db(database)
34+
yield env
35+
if rollback:
36+
cr.rollback()
37+
else:
38+
cr.commit()
39+
finally:
40+
odoo.modules.registry.Registry.delete(database)
41+
odoo.sql_db.close_db(database)

0 commit comments

Comments
 (0)