KevinKhao
4 years ago
9 changed files with 8 additions and 170 deletions
-
4base_user_role_profile/README.rst
-
12base_user_role_profile/models/user.py
-
1base_user_role_profile/readme/CONFIGURE.rst
-
4base_user_role_profile/readme/DESCRIPTION.rst
-
85base_user_role_profile/static/src/js/switch_profile_menu.js
-
23base_user_role_profile/static/src/xml/templates.xml
-
31base_user_role_profile/tests/test_user_role.py
-
2base_user_role_profile/views/role.xml
-
16base_user_role_profile/views/user.xml
@ -1,2 +1 @@ |
|||||
Go to Configuration / Users / Profiles and create a profile. Go to Configuration / Users / Roles and define some role lines with profiles. |
Go to Configuration / Users / Profiles and create a profile. Go to Configuration / Users / Roles and define some role lines with profiles. |
||||
Be careful when defining role lines that company ids and profiles are correctly configured. |
|
@ -1,85 +0,0 @@ |
|||||
odoo.define("web.SwitchProfileMenu", 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 SwitchProfileMenu = Widget.extend({ |
|
||||
template: "SwitchProfileMenu", |
|
||||
events: { |
|
||||
"click .dropdown-item[data-menu]": "_onClick", |
|
||||
}, |
|
||||
|
|
||||
init: function () { |
|
||||
this._super.apply(this, arguments); |
|
||||
this.isMobile = config.device.isMobile; |
|
||||
this._onClick = _.debounce(this._onClick, 1500, true); |
|
||||
}, |
|
||||
|
|
||||
willStart: function () { |
|
||||
return session.user_profiles ? this._super() : $.Deferred().reject(); |
|
||||
}, |
|
||||
|
|
||||
start: function () { |
|
||||
var profilesList = ""; |
|
||||
if (this.isMobile) { |
|
||||
profilesList = |
|
||||
'<li class="bg-info">' + |
|
||||
_t("Tap on the list to change profile") + |
|
||||
"</li>"; |
|
||||
} else { |
|
||||
this.$(".oe_topbar_name").text( |
|
||||
session.user_profiles.current_profile[1] |
|
||||
); |
|
||||
} |
|
||||
_.each(session.user_profiles.allowed_profiles, function (profile) { |
|
||||
var a = ""; |
|
||||
if (profile[0] == session.user_profiles.current_profile[0]) { |
|
||||
a = '<i class="fa fa-check mr8"></i>'; |
|
||||
} else { |
|
||||
a = '<span style="margin-right: 24px;"/>'; |
|
||||
} |
|
||||
profilesList += |
|
||||
'<a role="menuitem" href="#" class="dropdown-item" data-menu="profile" data-profile-id="' + |
|
||||
profile[0] + |
|
||||
'">' + |
|
||||
a + |
|
||||
profile[1] + |
|
||||
"</a>"; |
|
||||
}); |
|
||||
this.$(".dropdown-menu").html(profilesList); |
|
||||
return this._super(); |
|
||||
}, |
|
||||
|
|
||||
_onClick: function (ev) { |
|
||||
var self = this; |
|
||||
ev.preventDefault(); |
|
||||
var profileID = $(ev.currentTarget).data("profile-id"); |
|
||||
// We use this instead of the location.reload() because permissions change
|
|
||||
// and we might land on a menu that we don't have permissions for. Thus it
|
|
||||
// is cleaner to reload any root menu
|
|
||||
this._rpc({ |
|
||||
model: "res.users", |
|
||||
method: "action_profile_change", |
|
||||
args: [ |
|
||||
[session.uid], |
|
||||
{ |
|
||||
profile_id: profileID, |
|
||||
}, |
|
||||
], |
|
||||
}).done(function (result) { |
|
||||
self.trigger_up("do_action", { |
|
||||
action: result, |
|
||||
}); |
|
||||
}); |
|
||||
}, |
|
||||
}); |
|
||||
|
|
||||
SystrayMenu.Items.push(SwitchProfileMenu); |
|
||||
|
|
||||
return SwitchProfileMenu; |
|
||||
}); |
|
@ -1,23 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8" ?> |
|
||||
<templates id="template" xml:space="preserve"> |
|
||||
|
|
||||
<t t-name="SwitchProfileMenu"> |
|
||||
<li class="o_switch_profile_menu"> |
|
||||
<a |
|
||||
role="button" |
|
||||
class="dropdown-toggle" |
|
||||
data-toggle="dropdown" |
|
||||
aria-expanded="false" |
|
||||
href="#" |
|
||||
aria-label="Dropdown menu" |
|
||||
title="Dropdown menu" |
|
||||
> |
|
||||
<span |
|
||||
t-attf-class="#{widget.isMobile ? 'fa fa-building-o' : 'oe_topbar_name'}" |
|
||||
/> |
|
||||
</a> |
|
||||
<div class="dropdown-menu dropdown-menu-right" role="menu" /> |
|
||||
</li> |
|
||||
</t> |
|
||||
|
|
||||
</templates> |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue