mirror of https://github.com/OCA/web.git
fix: migrate to 9.0
- Use new UserMenu include method - Works with Community and enterprisepull/260/head
parent
c7917a56bc
commit
e678e3e080
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Multicompany - Easy Switch Company',
|
'name': 'Multicompany - Easy Switch Company',
|
||||||
'version': '8.0.1.0.0',
|
'version': '9.0.1.0.0',
|
||||||
'category': 'web',
|
'category': 'web',
|
||||||
'description': """
|
'description': """
|
||||||
Add menu to allow user to switch to another company more easily
|
Add menu to allow user to switch to another company more easily
|
||||||
|
@ -50,6 +50,7 @@ Copyright, Author and Licence:
|
||||||
------------------------------
|
------------------------------
|
||||||
* Copyright: 2014, Groupement Régional Alimentaire de Proximité;
|
* Copyright: 2014, Groupement Régional Alimentaire de Proximité;
|
||||||
* Author: Sylvain LE GAL (https://twitter.com/legalsylvain);
|
* Author: Sylvain LE GAL (https://twitter.com/legalsylvain);
|
||||||
|
* Contributor: Nicolas JEUDY (https://github.com/njeudy);
|
||||||
* Licence: AGPL-3 (http://www.gnu.org/licenses/)""",
|
* Licence: AGPL-3 (http://www.gnu.org/licenses/)""",
|
||||||
'author': "GRAP,Odoo Community Association (OCA)",
|
'author': "GRAP,Odoo Community Association (OCA)",
|
||||||
'website': 'http://www.grap.coop',
|
'website': 'http://www.grap.coop',
|
||||||
|
@ -63,6 +64,6 @@ Copyright, Author and Licence:
|
||||||
'qweb': [
|
'qweb': [
|
||||||
'static/src/xml/switch_company.xml',
|
'static/src/xml/switch_company.xml',
|
||||||
],
|
],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
Web Easy Switch Company module for OpenERP
|
Web Easy Switch Company module for OpenERP
|
||||||
Copyright (C) 2014 GRAP (http://www.grap.coop)
|
Copyright (C) 2014-2015 GRAP (http://www.grap.coop)
|
||||||
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
|
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
|
||||||
|
@contributor Nicolas JEUDY (https://github.com/njeudy)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Affero General Public License as
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -17,18 +18,27 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
openerp.web_easy_switch_company = function (instance) {
|
odoo.define('web.web_easy_switch_company',function (require) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var core = require('web.core');
|
||||||
|
var Widget = require('web.Widget');
|
||||||
|
var UserMenu = require('web.UserMenu');
|
||||||
|
var SystrayMenu = require('web.SystrayMenu');
|
||||||
|
var web_client = require('web.web_client');
|
||||||
|
var Model = require('web.Model');
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Create an new 'SwitchCompanyWidget' widget that allow users to switch
|
Create an new 'SwitchCompanyWidget' widget that allow users to switch
|
||||||
from a company to another more easily.
|
from a company to another more easily.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
instance.web.SwitchCompanyWidget = instance.web.Widget.extend({
|
var SwitchCompanyWidget = Widget.extend({
|
||||||
|
|
||||||
template:'web_easy_switch_company.SwitchCompanyWidget',
|
template:'web_easy_switch_company.SwitchCompanyWidget',
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
Overload section
|
Overload section
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,14 +87,14 @@ openerp.web_easy_switch_company = function (instance) {
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
Custom section
|
Custom section
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* helper function to load data from the server
|
* helper function to load data from the server
|
||||||
*/
|
*/
|
||||||
_fetch: function(model, fields, domain, ctx){
|
_fetch: function(model, fields, domain, ctx){
|
||||||
return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all();
|
return new Model(model).query(fields).filter(domain).context(ctx).all();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,17 +104,18 @@ openerp.web_easy_switch_company = function (instance) {
|
||||||
_load_data: function(){
|
_load_data: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
// Request for current users information
|
// Request for current users information
|
||||||
|
|
||||||
this._fetch('res.users',['company_id'],[['id','=',this.session.uid]]).then(function(res_users){
|
this._fetch('res.users',['company_id'],[['id','=',this.session.uid]]).then(function(res_users){
|
||||||
self.current_company_id = res_users[0].company_id[0];
|
self.current_company_id = res_users[0].company_id[0];
|
||||||
self.current_company_name = res_users[0].company_id[1];
|
self.current_company_name = res_users[0].company_id[1];
|
||||||
// Request for other companies
|
// Request for other companies
|
||||||
// We have to go through fields_view_get to emulate the
|
// We have to go through fields_view_get to emulate the
|
||||||
// exact (exotic) behavior of the user preferences form in
|
// exact (exotic) behavior of the user preferences form in
|
||||||
// fetching the allowed companies wrt record rules.
|
// fetching the allowed companies wrt record rules.
|
||||||
// Note: calling res.company.name_search with
|
// Note: calling res.company.name_search with
|
||||||
// user_preference=True in the context does
|
// user_preference=True in the context does
|
||||||
// not work either.
|
// not work either.
|
||||||
new instance.web.Model('res.company').call('name_search',{context:{'user_preference':'True'}}).then(function(res){
|
new Model('res.company').call('name_search',{context:{'user_preference':'True'}}).then(function(res){
|
||||||
var res_company = res;
|
var res_company = res;
|
||||||
for ( var i=0 ; i < res_company.length; i++) {
|
for ( var i=0 ; i < res_company.length; i++) {
|
||||||
var logo_topbar, logo_state;
|
var logo_topbar, logo_state;
|
||||||
|
@ -113,8 +124,8 @@ openerp.web_easy_switch_company = function (instance) {
|
||||||
// probably remove the logos from the menu :(
|
// probably remove the logos from the menu :(
|
||||||
logo_topbar = self.session.url(
|
logo_topbar = self.session.url(
|
||||||
'/web/binary/image', {
|
'/web/binary/image', {
|
||||||
model:'res.company',
|
model:'res.company',
|
||||||
field: 'logo_topbar',
|
field: 'logo_topbar',
|
||||||
id: res_company[i][0]
|
id: res_company[i][0]
|
||||||
});
|
});
|
||||||
if (res_company[i][0] == self.current_company_id){
|
if (res_company[i][0] == self.current_company_id){
|
||||||
|
@ -138,18 +149,6 @@ openerp.web_easy_switch_company = function (instance) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/***************************************************************************
|
SystrayMenu.Items.push(SwitchCompanyWidget);
|
||||||
Extend 'UserMenu' Widget to insert a 'SwitchCompanyWidget' widget.
|
|
||||||
***************************************************************************/
|
|
||||||
instance.web.UserMenu = instance.web.UserMenu.extend({
|
|
||||||
|
|
||||||
init: function(parent) {
|
|
||||||
this._super(parent);
|
|
||||||
var switch_button = new instance.web.SwitchCompanyWidget();
|
|
||||||
switch_button.appendTo(instance.webclient.$el.find('.oe_systray'));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -47,4 +47,3 @@
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue