diff --git a/addons/web/static/src/js/widgets/switch_company_menu.js b/addons/web/static/src/js/widgets/switch_company_menu.js index a51f16eb2f2..ca056c4c644 100644 --- a/addons/web/static/src/js/widgets/switch_company_menu.js +++ b/addons/web/static/src/js/widgets/switch_company_menu.js @@ -1,6 +1,12 @@ odoo.define('web.SwitchCompanyMenu', function(require) { "use strict"; +/** + * When Odoo is configured in multi-company mode, users should obviously be able + * to switch their interface from one company to the other. This is the purpose + * of this widget, by displaying a dropdown menu in the systray. + */ + var config = require('web.config'); var core = require('web.core'); var session = require('web.session'); @@ -11,34 +17,34 @@ var _t = core._t; var SwitchCompanyMenu = Widget.extend({ template: 'SwitchCompanyMenu', - willStart: function() { - this.isMobile = config.device.isMobile; - if (!session.user_companies) { - return $.Deferred().reject(); - } - return this._super(); + events: { + 'click .dropdown-menu li a[data-menu]': '_onClick', }, - start: function() { - var self = this; - this.$el.on('click', '.dropdown-menu li a[data-menu]', _.debounce(function(ev) { - ev.preventDefault(); - var company_id = $(ev.currentTarget).data('company-id'); - self._rpc({ - model: 'res.users', - method: 'write', - args: [[session.uid], {'company_id': company_id}], - }) - .then(function() { - location.reload(); - }); - }, 1500, true)); - - var companies_list = ''; + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + this.isMobile = config.device.isMobile; + this._onClick = _.debounce(this._onClick, 1500, true); + }, + /** + * @override + */ + willStart: function () { + return session.user_companies ? this._super() : $.Deferred().reject(); + }, + /** + * @override + */ + start: function () { + var companiesList = ''; if (this.isMobile) { - companies_list = '