|
29 | 29 | @contextmanager |
30 | 30 | def OdooEnvironment(database, rollback=False, **kwargs): |
31 | 31 | with Environment.manage(): |
32 | | - registry = odoo.registry(database) |
33 | | - try: |
34 | | - with registry.cursor() as cr: |
35 | | - uid = odoo.SUPERUSER_ID |
36 | | - try: |
37 | | - ctx = Environment(cr, uid, {})["res.users"].context_get() |
38 | | - except Exception as e: |
39 | | - ctx = {"lang": "en_US"} |
40 | | - # this happens, for instance, when there are new |
41 | | - # fields declared on res_partner which are not yet |
42 | | - # in the database (before -u) |
43 | | - _logger.warning( |
44 | | - "Could not obtain a user context, continuing " |
45 | | - "anyway with a default context. Error was: %s", |
46 | | - e, |
47 | | - ) |
48 | | - env = Environment(cr, uid, ctx) |
49 | | - cr.rollback() |
50 | | - yield env |
51 | | - if rollback: |
| 32 | + registry = odoo.registry(database).check_signaling() |
| 33 | + with registry.manage_changes(): |
| 34 | + try: |
| 35 | + with registry.cursor() as cr: |
| 36 | + uid = odoo.SUPERUSER_ID |
| 37 | + try: |
| 38 | + ctx = Environment(cr, uid, {})["res.users"].context_get() |
| 39 | + except Exception as e: |
| 40 | + ctx = {"lang": "en_US"} |
| 41 | + # this happens, for instance, when there are new |
| 42 | + # fields declared on res_partner which are not yet |
| 43 | + # in the database (before -u) |
| 44 | + _logger.warning( |
| 45 | + "Could not obtain a user context, continuing " |
| 46 | + "anyway with a default context. Error was: %s", |
| 47 | + e, |
| 48 | + ) |
| 49 | + env = Environment(cr, uid, ctx) |
52 | 50 | cr.rollback() |
| 51 | + yield env |
| 52 | + if rollback: |
| 53 | + cr.rollback() |
| 54 | + else: |
| 55 | + cr.commit() |
| 56 | + finally: |
| 57 | + if odoo.tools.parse_version( |
| 58 | + odoo.release.version |
| 59 | + ) < odoo.tools.parse_version("10.0"): |
| 60 | + odoo.modules.registry.RegistryManager.delete(database) |
53 | 61 | else: |
54 | | - cr.commit() |
55 | | - finally: |
56 | | - if odoo.tools.parse_version( |
57 | | - odoo.release.version |
58 | | - ) < odoo.tools.parse_version("10.0"): |
59 | | - odoo.modules.registry.RegistryManager.delete(database) |
60 | | - else: |
61 | | - odoo.modules.registry.Registry.delete(database) |
62 | | - odoo.sql_db.close_db(database) |
| 62 | + odoo.modules.registry.Registry.delete(database) |
| 63 | + odoo.sql_db.close_db(database) |
0 commit comments