diff options
| author | Raphael Collet <rco@odoo.com> | 2020-09-03 09:17:26 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-09-03 09:17:26 +0000 |
| commit | e9e37091a65d5ae2caa9eb6728abaffb7c9555a8 (patch) | |
| tree | a9045da0be927e8608afee70b58118f2ebcdd97b /addons | |
| parent | d4b2e9224839aed8fc160ebe5a89e0f7d4c6a5bb (diff) | |
[IMP] core: deprecate method cr.after()
Use the more convenient `cr.postcommit.add()` instead.
closes odoo/odoo#56990
Related: odoo/enterprise#12914
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/bus/models/bus.py | 2 | ||||
| -rw-r--r-- | addons/google_calendar/models/google_sync.py | 4 | ||||
| -rw-r--r-- | addons/mail/models/mail_thread.py | 3 | ||||
| -rw-r--r-- | addons/microsoft_calendar/models/microsoft_sync.py | 4 | ||||
| -rw-r--r-- | addons/website/__init__.py | 3 |
5 files changed, 11 insertions, 5 deletions
diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py index 1e62ad6eb48..b88a833601b 100644 --- a/addons/bus/models/bus.py +++ b/addons/bus/models/bus.py @@ -59,10 +59,10 @@ class ImBus(models.Model): # awakened and will fetch the notification in the bus table. If the # transaction is not commited yet, there will be nothing to fetch, # and the longpolling will return no notification. + @self.env.cr.postcommit.add def notify(): with odoo.sql_db.db_connect('postgres').cursor() as cr: cr.execute("notify imbus, %s", (json_dump(list(channels)),)) - self._cr.after('commit', notify) @api.model def sendone(self, channel, message): diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py index 9957bdad6cc..f29302ce1f7 100644 --- a/addons/google_calendar/models/google_sync.py +++ b/addons/google_calendar/models/google_sync.py @@ -30,6 +30,8 @@ def after_commit(func): dbname = self.env.cr.dbname context = self.env.context uid = self.env.uid + + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: @@ -39,7 +41,7 @@ def after_commit(func): except Exception as e: _logger.warning("Could not sync record now: %s" % self) _logger.exception(e) - self.env.cr.after('commit', called_after) + return wrapped @contextmanager diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 802fef140ae..caff059b408 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2307,12 +2307,13 @@ class MailThread(models.AbstractModel): email_ids = emails.ids dbname = self.env.cr.dbname _context = self._context + + @self.env.cr.postcommit.add def send_notifications(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: env = api.Environment(cr, SUPERUSER_ID, _context) env['mail.mail'].browse(email_ids).send() - self._cr.after('commit', send_notifications) else: emails.send() diff --git a/addons/microsoft_calendar/models/microsoft_sync.py b/addons/microsoft_calendar/models/microsoft_sync.py index 312904779ec..888fe09eff0 100644 --- a/addons/microsoft_calendar/models/microsoft_sync.py +++ b/addons/microsoft_calendar/models/microsoft_sync.py @@ -32,6 +32,8 @@ def after_commit(func): dbname = self.env.cr.dbname context = self.env.context uid = self.env.uid + + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: @@ -41,7 +43,7 @@ def after_commit(func): except Exception as e: _logger.warning("Could not sync record now: %s" % self) _logger.exception(e) - self.env.cr.after('commit', called_after) + return wrapped @contextmanager diff --git a/addons/website/__init__.py b/addons/website/__init__.py index 748058ff042..c4161c8635e 100644 --- a/addons/website/__init__.py +++ b/addons/website/__init__.py @@ -19,7 +19,8 @@ def uninstall_hook(cr, registry): ('name', '=', 'website_id'), ('model', '=', 'res.config.settings'), ]).unlink() - cr.after('commit', partial(rem_website_id_null, cr.dbname)) + + cr.postcommit.add(partial(rem_website_id_null, cr.dbname)) def post_init_hook(cr, registry): |
