diff --git a/pms/models/inherited_ir_http.py b/pms/models/inherited_ir_http.py
index 77caa06aa..3f4e89d0d 100644
--- a/pms/models/inherited_ir_http.py
+++ b/pms/models/inherited_ir_http.py
@@ -13,22 +13,18 @@ class IrHttp(models.AbstractModel):
def session_info(self):
res = super().session_info()
user = request.env.user
- display_switch_pms_menu = len(user.pms_property_ids) > 1
- # TODO: limit properties to the current company?
- # or switch company automatically
- res['pms_property_id'] = request.env.user.pms_property_id.id if \
- request.session.uid else None
- res['user_properties'] = {
- 'current_property': (user.pms_property_id.id, user.pms_property_id.name),
- 'allowed_properties': [
- (property.id, property.name) for property in user.pms_property_ids
- ]
- } if display_switch_pms_menu else False
+ res.update({
+ # current_pms_property should be default_property
+ "user_pms_properties": {'current_pms_property': (user.pms_property_id.id, user.pms_property_id.name), 'allowed_pms_properties': [(property.id, property.name) for property in user.pms_property_ids]},
+ "display_switch_pms_property_menu": user.has_group('base.group_multi_company') and len(user.pms_property_ids) > 1,
+ })
+ # TODO: This user context update should be placed in other function ¿?
+ res['user_context'].update({'allowed_pms_property_ids': [(property.id) for property in user.pms_property_ids]})
+ # update current_company based on current_pms_property
if user.pms_property_id.company_id in user.company_ids:
user.company_id = user.pms_property_id.company_id
res['company_id'] = user.pms_property_id.company_id.id
else:
- return res #TODO Review method
raise MissingError(
_("Wrong property and company access settings for this user. "
"Please review property and company for user %s") % user.name)
diff --git a/pms/static/src/js/widgets/switch_hotel_menu.js b/pms/static/src/js/widgets/switch_hotel_menu.js
deleted file mode 100644
index bb985f3c7..000000000
--- a/pms/static/src/js/widgets/switch_hotel_menu.js
+++ /dev/null
@@ -1,61 +0,0 @@
-odoo.define('pms.SwitchPmsMenu', function(require) {
-"use strict";
-
-var config = require('web.config');
-var core = require('web.core');
-var session = require('web.session');
-var SystrayMenu = require('web.SystrayMenu');
-var Widget = require('web.Widget');
-
-var _t = core._t;
-
-var SwitchPmsMenu = Widget.extend({
- template: 'pms.SwitchPmsMenu',
- willStart: function() {
- this.isMobile = config.device.isMobile;
- if (!session.user_pms) {
- return $.Deferred().reject();
- }
- return this._super();
- },
- start: function() {
- var self = this;
- this.$el.on('click', '.dropdown-menu li a[data-menu]', _.debounce(function(ev) {
- ev.preventDefault();
- var pms_property_id = $(ev.currentTarget).data('property-id');
- self._rpc({
- model: 'res.users',
- method: 'write',
- args: [[session.uid], {'pms_property_id': pms_property_id}],
- })
- .then(function() {
- location.reload();
- });
- }, 1500, true));
-
- var properties_list = '';
- if (this.isMobile) {
- propertiess_list = '
' + _t('Tap on the list to change property') + '';
- }
- else {
- self.$('.oe_topbar_name').text(session.user_properties.current_property[1]);
- }
- _.each(session.user_properties.allowed_propierties, function(property) {
- var a = '';
- if (property[0] === session.user_properties.current_property[0]) {
- a = '';
- } else {
- a = '';
- }
- properties_list += '' + a + property[1] + '';
- });
- self.$('.dropdown-menu').html(properties_list);
- return this._super();
- },
-});
-
-SystrayMenu.Items.push(SwitchPmsMenu);
-
-return SwitchPmsMenu;
-
-});
diff --git a/pms/static/src/js/widgets/switch_property_menu.js b/pms/static/src/js/widgets/switch_property_menu.js
new file mode 100644
index 000000000..568e38c80
--- /dev/null
+++ b/pms/static/src/js/widgets/switch_property_menu.js
@@ -0,0 +1,126 @@
+odoo.define('web.SwitchPmsMenu', function(require) {
+ "use strict";
+
+ /**
+ * When Odoo is configured in multi-property mode, users should obviously be able
+ * to switch their interface from one property 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');
+ var SystrayMenu = require('web.SystrayMenu');
+ var Widget = require('web.Widget');
+
+ var _t = core._t;
+
+ var SwitchPmsMenu = Widget.extend({
+ template: 'SwitchPmsMenu',
+ events: {
+ 'click .dropdown-item[data-menu] div.log_into': '_onSwitchPmsPropertyClick',
+ 'keydown .dropdown-item[data-menu] div.log_into': '_onSwitchPmsPropertyClick',
+ 'click .dropdown-item[data-menu] div.toggle_pms_property': '_onTogglePmsPropertyClick',
+ 'keydown .dropdown-item[data-menu] div.toggle_pms_property': '_onTogglePmsPropertyClick',
+ },
+ /**
+ * @override
+ */
+ init: function () {
+ this._super.apply(this, arguments);
+ this.isMobile = config.device.isMobile;
+ this._onSwitchPmsPropertyClick = _.debounce(this._onSwitchPmsPropertyClick, 1500, true);
+ },
+
+ /**
+ * @override
+ */
+ willStart: function () {
+ var self = this;
+ this.allowed_pms_property_ids = String(session.user_context.allowed_pms_property_ids)
+ .split(',')
+ .map(function (id) {return parseInt(id);});
+ this.user_pms_properties = session.user_pms_properties.allowed_pms_properties;
+ this.current_pms_property = this.allowed_pms_property_ids[0];
+ this.current_pms_property_name = _.find(session.user_pms_properties.allowed_pms_properties, function (pms_property) {
+ return pms_property[0] === self.current_pms_property;
+ })[1];
+ return this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {MouseEvent|KeyEvent} ev
+ */
+ _onSwitchPmsPropertyClick: function (ev) {
+ if (ev.type == 'keydown' && ev.which != $.ui.keyCode.ENTER && ev.which != $.ui.keyCode.SPACE) {
+ return;
+ }
+ ev.preventDefault();
+ ev.stopPropagation();
+ var dropdownItem = $(ev.currentTarget).parent();
+ var dropdownMenu = dropdownItem.parent();
+ var pms_propertyID = dropdownItem.data('pms_property-id');
+ var allowed_pms_property_ids = this.allowed_pms_property_ids;
+ if (dropdownItem.find('.fa-square-o').length) {
+ // 1 enabled pms_property: Stay in single pms proeprty mode
+ if (this.allowed_pms_property_ids.length === 1) {
+ if (this.isMobile) {
+ dropdownMenu = dropdownMenu.parent();
+ }
+ dropdownMenu.find('.fa-check-square').removeClass('fa-check-square').addClass('fa-square-o');
+ dropdownItem.find('.fa-square-o').removeClass('fa-square-o').addClass('fa-check-square');
+ allowed_pms_property_ids = [pms_propertyID];
+ } else { // Multi pms proeprty mode
+ allowed_pms_property_ids.push(pms_propertyID);
+ dropdownItem.find('.fa-square-o').removeClass('fa-square-o').addClass('fa-check-square');
+ }
+ }
+ $(ev.currentTarget).attr('aria-pressed', 'true');
+ session.setPmsProperties(pms_propertyID, allowed_pms_property_ids);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {MouseEvent|KeyEvent} ev
+ */
+ _onTogglePmsPropertyClick: function (ev) {
+ if (ev.type == 'keydown' && ev.which != $.ui.keyCode.ENTER && ev.which != $.ui.keyCode.SPACE) {
+ return;
+ }
+ ev.preventDefault();
+ ev.stopPropagation();
+ var dropdownItem = $(ev.currentTarget).parent();
+ var pms_propertyID = dropdownItem.data('pms_property-id');
+ var allowed_pms_property_ids = this.allowed_pms_property_ids;
+ var current_pms_property_id = allowed_pms_property_ids[0];
+ if (dropdownItem.find('.fa-square-o').length) {
+ allowed_pms_property_ids.push(pms_propertyID);
+ dropdownItem.find('.fa-square-o').removeClass('fa-square-o').addClass('fa-check-square');
+ $(ev.currentTarget).attr('aria-checked', 'true');
+ } else {
+ allowed_pms_property_ids.splice(allowed_pms_property_ids.indexOf(pms_propertyID), 1);
+ dropdownItem.find('.fa-check-square').addClass('fa-square-o').removeClass('fa-check-square');
+ $(ev.currentTarget).attr('aria-checked', 'false');
+ }
+ session.setPmsProperties(current_pms_property_id, allowed_pms_property_ids);
+ },
+
+ });
+
+ if (session.display_switch_pms_property_menu) {
+ SystrayMenu.Items.push(SwitchPmsMenu);
+ }
+
+ return SwitchPmsMenu;
+
+ });
+
\ No newline at end of file
diff --git a/pms/static/src/xml/pms_base_templates.xml b/pms/static/src/xml/pms_base_templates.xml
index 60a185ef3..bf89acd69 100644
--- a/pms/static/src/xml/pms_base_templates.xml
+++ b/pms/static/src/xml/pms_base_templates.xml
@@ -1,11 +1,42 @@
-
-