[FIX] mail: this.env.services.bus_service is undefined

Before this commit, a page reload or a redirect could raise following
error:

```
Uncaught (in promise) TypeError: this.env.services.bus_service is undefined
```

This happens due to `Messaging` model relying on `bus_service` in its
teardown method `_willDelete`. This is sometimes unsafe because the
bus service may not have been deployed yet.

Task-2468469

closes odoo/odoo#66857

X-original-commit: a444f9c89bb8d5790b8a068a8f120f6ea9d1b17f
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2021-02-25 14:28:20 +00:00
parent f241fc6504
commit 14eed232cf
2 changed files with 7 additions and 3 deletions
@@ -12,7 +12,9 @@ function factory(dependencies) {
* @override
*/
_willDelete() {
this.env.services['bus_service'].off('window_focus', null, this._handleGlobalWindowFocus);
if (this.env.services['bus_service']) {
this.env.services['bus_service'].off('window_focus', null, this._handleGlobalWindowFocus);
}
return super._willDelete(...arguments);
}
@@ -16,8 +16,10 @@ function factory(dependencies) {
* @override
*/
_willDelete() {
this.env.services['bus_service'].off('notification');
this.env.services['bus_service'].stopPolling();
if (this.env.services['bus_service']) {
this.env.services['bus_service'].off('notification');
this.env.services['bus_service'].stopPolling();
}
return super._willDelete(...arguments);
}