Merge lp:~sylvain-legal/web-addons/7.0-web_easy_switch_company into lp:~webaddons-core-editors/web-addons/7.0

Proposed by Sylvain LE GAL (GRAP)
Status: Merged
Merged at revision: 27
Proposed branch: lp:~sylvain-legal/web-addons/7.0-web_easy_switch_company
Merge into: lp:~webaddons-core-editors/web-addons/7.0
Diff against target: 522 lines (+458/-0)
10 files modified
web_easy_switch_company/__init__.py (+24/-0)
web_easy_switch_company/__openerp__.py (+71/-0)
web_easy_switch_company/controllers/__init__.py (+23/-0)
web_easy_switch_company/controllers/main.py (+31/-0)
web_easy_switch_company/model/__init__.py (+24/-0)
web_easy_switch_company/model/res_company.py (+57/-0)
web_easy_switch_company/model/res_users.py (+31/-0)
web_easy_switch_company/static/src/js/switch_company.js (+137/-0)
web_easy_switch_company/static/src/xml/switch_company.xml (+45/-0)
web_easy_switch_company/view/res_users_view.xml (+15/-0)
To merge this branch: bzr merge lp:~sylvain-legal/web-addons/7.0-web_easy_switch_company
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
Pedro Manuel Baeza code review and test Approve
arthru (community) tested, no-review Approve
Review via email: mp+210289@code.launchpad.net

Description of the change

Add a new module 'web_easy_switch_company'.

This module allow a user to switch from a company to another more easily. (with just 2 mouse click & without warning message).

To post a comment you must log in.
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi all,

I propose for merging this little module I did, that allow users to switch from a company to another more easily.

2 questions :

1/ l242, I wrote "window.location.reload()" to reload the page after the change of the value 'company_id' of the current user. It works fine but I wonder if there is a solution more elegant ? A function in the openERP framework ?

2/ By default, the name of the current company is displayed with parenthesis, after the name of the current user, if company_id >1 ... (pretty weird)
http://bazaar.launchpad.net/~openerp/openerp-web/7.0/view/head:/addons/web/static/src/js/chrome.js#L1117
I would like to remove the name of the company (because my module display it in all case) but the operation is realized asynchroneously after a ".then" (L1113).
So I found 3 solutions that I do not like :
A/ overload 'do_update' function and change the text after a 'setTimeout' of x seconde ... ; (-> not predictive / ugly)
B/ rewrite the 'do_update' function entirely ; (-> not modular)
C/ Do nothing ; (-> not a solution ;-) )

Do you have some ideas about that 2 questions ?

thanks for your review.

Revision history for this message
arthru (arthru) wrote :

Tested and approved.

About the first question, I don't think you can do better : even OpenERP reloads the full page after changing it in your own preferences.

Can't help for the second question... sorry...

Just a littel improvement : don't display your widget if the current user is in only one company.

review: Approve (tested, no-review)
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi Arthru,

I did the improvement you asked, hidding the widget if the user has right only in one company.

Thanks for your review.

Regards.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Sylvain,

I have tested your module and it works very well! Thanks for the contribution.

I agree with Arthru about question 1.

And on question 2, it would be preferible to hide company name, but due to this combo has a maximum width, I would let as iss.

Regards.

review: Approve (code review and test)
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi Pedro,

Thank you for your review !
I'm not sure to understand what you said about question 2. It's preferible to hide company name displayed by the 'web' module or the company name displayed by 'web_easy_swich_company' ?

In few word, should I change something ?

Regards.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Sylvain, sorry if I haven't expressed clearly. You don't need to change anything, because any of the solutions is ideal. I said that having company name on the other combo is not problem, because it has a limited width.

Regards.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

s/any of the solutions is ideal/none of the solutions is ideal

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

there is a client action for reloading the application (called after the installation of a module for instance).

Asking a reload from the server can be done by returning:

          return {
            'type': 'ir.actions.client',
            'tag': 'reload',
            'params': {
                'menu_id': menu_id
            },
          }

I'm not sure, but I think you can call it from javascript with

    self.do_action('reload');

You can inspect the client action in web/static/src/js/chrome.js +784 (instance.web.Reload).
I don't know how the reload will behave though, ie if it will stay on the current page.

In the __init__.py modules, could you replace the absolute imports with relative ones, so instead of:
    import model
write:
    from . import model
This is a good habit because if an egg or an openerp module is named model, it could import it instead of your module.

Thanks!

review: Needs Fixing (code review)
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi Guewen,

I changed import call.

About the reload, the self.do_action('reload') doesn't work. I think because I'm in a instance.web.Widget class.
Can you say me how to call this function ? I 'rgreped' 'do_action' in web-addons without results.

As Arthru said, openerp call window.location.reload().
rgrep "window.*reload" ./ gives 3 references in openerp-web project.

Regards.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

On 03/23/2014 11:42 PM, Sylvain LE GAL (GRAP) wrote:
> Hi Guewen,
>
> I changed import call.
>
> About the reload, the self.do_action('reload') doesn't work. I think because I'm in a instance.web.Widget class.
> Can you say me how to call this function ? I 'rgreped' 'do_action' in web-addons without results.

You will find many occurrences if you grep for rgrep "do_action(.*)" ./
You won't find it if you grep for rgrep "do_action('reload')" ./ because it is never passed directly as a constant, but always called using client actions from the server.

>
> As Arthru said, openerp call window.location.reload().
> rgrep "window.*reload" ./ gives 3 references in openerp-web project.
It does that when the user logs out or when closing the view editor. I don't know what is the correct way to reload the page, maybe the client action is only for reloading from the server, when a window.location.reload() is sufficient.
>
> Regards.

review: Approve
Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Thanks for your review.

About the call of do_action, yes it's possible via client actions. But in full web it doesn't seem to work. But I'm not openerp-web-expert.
If somebody find a solution more elegant we can update the code in a second time.

Regards.

Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Following reviews on another merge proposal i did, I changed this MP. (non functional changes : just pep8, copyright & typos changes).

regards.

Revision history for this message
Ray Carnes (rcarnes) wrote :

FYI: The module doesn't work for regular users and Sylvain is looking into it.

Everyone - can you remember when testing modules (that you write, and that you test for suitability for merge proposals) that you test with non ADMIN users? This didn't happen for this module. My boss isn't happy I wasted 4 hours trying to get this to work. I am VERY HAPPY that this module was written, just wish it was tested before I got to it!!

Revision history for this message
arthru (arthru) wrote :

Ray, your boss should be glad you helped the community pointing out a bug. This is really not nice complaining about other people free (as in beer, _and_, as in speech) work.

And don't forget : http://bazaar.launchpad.net/~sylvain-legal/web-addons/7.0-web_easy_switch_company/view/head:/web_easy_switch_company/__openerp__.py#L13

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'web_easy_switch_company'
=== added file 'web_easy_switch_company/__init__.py'
--- web_easy_switch_company/__init__.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/__init__.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,24 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import model
24from . import controllers
025
=== added file 'web_easy_switch_company/__openerp__.py'
--- web_easy_switch_company/__openerp__.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/__openerp__.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,71 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': 'Multicompany - Easy Switch Company',
25 'version': '1.0',
26 'category': 'web',
27 'description': """
28Add menu to allow user to switch to another company more easily
29===============================================================
30
31Functionality:
32--------------
33 * Add a new menu in the top bar to switch to another company more easily;
34 * Remove the old behaviour to switch company;
35
36Documentations:
37---------------
38 * Video : http://www.youtube.com/watch?v=Cpm6dg-IEQQ
39
40Technical information:
41----------------------
42 * Create a field function 'logo_topbar' in res_company to have a good"""
43 """resized logo;
44
45Limits:
46-------
47 * It would be interesting to show the structure of the companies;
48
49Copyright, Author and Licence:
50------------------------------
51 * Copyright: 2014, Groupement Régional Alimentaire de Proximité;
52 * Author: Sylvain LE GAL (https://twitter.com/legalsylvain);
53 * Licence: AGPL-3 (http://www.gnu.org/licenses/)""",
54 'author': 'GRAP',
55 'website': 'http://www.grap.coop',
56 'license': 'AGPL-3',
57 'depends': [
58 'web',
59 ],
60 'data': [
61 'view/res_users_view.xml',
62 ],
63 'js': [
64 'static/src/js/switch_company.js',
65 ],
66 'qweb': [
67 'static/src/xml/switch_company.xml',
68 ],
69 'installable': True,
70 'auto_install': False,
71}
072
=== added directory 'web_easy_switch_company/controllers'
=== added file 'web_easy_switch_company/controllers/__init__.py'
--- web_easy_switch_company/controllers/__init__.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/controllers/__init__.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,23 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import main
024
=== added file 'web_easy_switch_company/controllers/main.py'
--- web_easy_switch_company/controllers/main.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/controllers/main.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,31 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23import openerp
24
25
26class WebEasySwitchCompanyController(openerp.addons.web.http.Controller):
27 _cp_path = '/web_easy_switch_company/switch'
28
29 @openerp.addons.web.http.jsonrequest
30 def change_current_company(self, req, company_id):
31 req.session.model('res.users').change_current_company(company_id)
032
=== added directory 'web_easy_switch_company/model'
=== added file 'web_easy_switch_company/model/__init__.py'
--- web_easy_switch_company/model/__init__.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/model/__init__.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,24 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import res_users
24from . import res_company
025
=== added file 'web_easy_switch_company/model/res_company.py'
--- web_easy_switch_company/model/res_company.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/model/res_company.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,57 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import fields
24from openerp.osv.orm import Model
25from openerp.tools import image_resize_image
26
27
28class res_company(Model):
29 _inherit = 'res.company'
30
31 # Custom Section
32 def _switch_company_get_companies_from_partner(
33 self, cr, uid, ids, context=None):
34 return self.pool['res.company'].search(
35 cr, uid, [('partner_id', 'in', ids)], context=context)
36
37 # Fields function Section
38 def _get_logo_topbar(self, cr, uid, ids, _field_name, _args, context=None):
39 result = dict.fromkeys(ids, False)
40 for record in self.browse(cr, uid, ids, context=context):
41 size = (48, 48)
42 result[record.id] = image_resize_image(
43 record.partner_id.image, size)
44 return result
45
46 # Columns Section
47 _columns = {
48 'logo_topbar': fields.function(
49 _get_logo_topbar,
50 string="Logo displayed in the switch company menu",
51 type="binary", store={
52 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10),
53 'res.partner': (_switch_company_get_companies_from_partner,
54 ['image'], 10),
55 }
56 ),
57 }
058
=== added file 'web_easy_switch_company/model/res_users.py'
--- web_easy_switch_company/model/res_users.py 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/model/res_users.py 2014-04-02 09:20:18 +0000
@@ -0,0 +1,31 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# Web Easy Switch Company module for OpenERP
5# Copyright (C) 2014 GRAP (http://www.grap.coop)
6# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv.orm import Model
24
25
26class res_users(Model):
27 _inherit = 'res.users'
28
29 # Custom Function Section
30 def change_current_company(self, cr, uid, company_id, context=None):
31 return self.write(cr, uid, uid, {'company_id': company_id})
032
=== added directory 'web_easy_switch_company/static'
=== added directory 'web_easy_switch_company/static/src'
=== added directory 'web_easy_switch_company/static/src/img'
=== added file 'web_easy_switch_company/static/src/img/icon.png'
1Binary files web_easy_switch_company/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/icon.png 2014-04-02 09:20:18 +0000 differ33Binary files web_easy_switch_company/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/icon.png 2014-04-02 09:20:18 +0000 differ
=== added file 'web_easy_switch_company/static/src/img/selection-off.png'
2Binary files web_easy_switch_company/static/src/img/selection-off.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/selection-off.png 2014-04-02 09:20:18 +0000 differ34Binary files web_easy_switch_company/static/src/img/selection-off.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/selection-off.png 2014-04-02 09:20:18 +0000 differ
=== added file 'web_easy_switch_company/static/src/img/selection-on.png'
3Binary files web_easy_switch_company/static/src/img/selection-on.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/selection-on.png 2014-04-02 09:20:18 +0000 differ35Binary files web_easy_switch_company/static/src/img/selection-on.png 1970-01-01 00:00:00 +0000 and web_easy_switch_company/static/src/img/selection-on.png 2014-04-02 09:20:18 +0000 differ
=== added directory 'web_easy_switch_company/static/src/js'
=== added file 'web_easy_switch_company/static/src/js/switch_company.js'
--- web_easy_switch_company/static/src/js/switch_company.js 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/static/src/js/switch_company.js 2014-04-02 09:20:18 +0000
@@ -0,0 +1,137 @@
1/******************************************************************************
2 Web Easy Switch Company module for OpenERP
3 Copyright (C) 2014 GRAP (http://www.grap.coop)
4 @author Sylvain LE GAL (https://twitter.com/legalsylvain)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License as
8 published by the Free Software Foundation, either version 3 of the
9 License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18******************************************************************************/
19
20openerp.web_easy_switch_company = function (instance) {
21
22 /***************************************************************************
23 Create an new 'SwitchCompanyWidget' widget that allow users to switch
24 from a company to another more easily.
25 ***************************************************************************/
26 instance.web.SwitchCompanyWidget = instance.web.Widget.extend({
27
28 template:'web_easy_switch_company.SwitchCompanyWidget',
29
30 /***********************************************************************
31 Overload section
32 ***********************************************************************/
33
34 /**
35 * Overload 'init' function to initialize the values of the widget.
36 */
37 init: function(parent){
38 this._super(parent);
39 this.companies = [];
40 this.current_company_id = 0;
41 this.current_company_name = '';
42 },
43
44 /**
45 * Overload 'start' function to load datas from DB.
46 */
47 start: function () {
48 this._super();
49 this._load_data();
50 },
51
52 /**
53 * Overload 'renderElement' function to set events on company items.
54 */
55 renderElement: function() {
56 var self = this;
57 this._super();
58 if (this.companies.length === 1) {
59 this.$el.hide();
60 }
61 else{
62 this.$el.show();
63 this.$el.find('.easy_switch_company_company_item').on('click', function(ev) {
64 var company_id = $(ev.target).data("company-id");
65 if (company_id != self.current_company_id){
66 var func = '/web_easy_switch_company/switch/change_current_company';
67 var param = {'company_id': company_id}
68 self.rpc(func, param).done(function(res) {
69 window.location.reload()
70 });
71 }
72 });
73 }
74 },
75
76
77 /***********************************************************************
78 Custom section
79 ***********************************************************************/
80
81 /**
82 * helper function to load data from the server
83 */
84 _fetch: function(model, fields, domain, ctx){
85 return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all();
86 },
87
88 /**
89 * - Load data of the companies allowed to the current users;
90 * - Launch the rendering of the current widget;
91 */
92 _load_data: function(){
93 var self = this;
94 // Request for current users information
95 this._fetch('res.users',['company_id','company_ids'],[['id','=',this.session.uid]]).then(function(res_users){
96 self.current_company_id = res_users[0].company_id[0];
97 self.current_company_name = res_users[0].company_id[1];
98 // Request for other companies
99 self._fetch('res.company',['name',],[['id','in', res_users[0].company_ids]]).then(function(res_company){
100 for ( var i=0 ; i < res_company.length; i++) {
101 res_company[i]['logo_topbar'] = self.session.url(
102 '/web/binary/image', {
103 model:'res.company',
104 field: 'logo_topbar',
105 id: res_company[i].id
106 });
107 if (res_company[i].id == self.current_company_id){
108 res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-on.png';
109 }
110 else{
111 res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-off.png';
112 }
113 self.companies.push(res_company[i]);
114 }
115 // Update rendering
116 self.renderElement();
117 });
118 });
119 },
120
121 });
122
123 /***************************************************************************
124 Extend 'UserMenu' Widget to insert a 'SwitchCompanyWidget' widget.
125 ***************************************************************************/
126 instance.web.UserMenu = instance.web.UserMenu.extend({
127
128 init: function(parent) {
129 this._super(parent);
130 var switch_button = new instance.web.SwitchCompanyWidget();
131 switch_button.appendTo(instance.webclient.$el.find('.oe_systray'));
132 },
133
134 });
135
136};
137
0138
=== added directory 'web_easy_switch_company/static/src/xml'
=== added file 'web_easy_switch_company/static/src/xml/switch_company.xml'
--- web_easy_switch_company/static/src/xml/switch_company.xml 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/static/src/xml/switch_company.xml 2014-04-02 09:20:18 +0000
@@ -0,0 +1,45 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- ********************************************************************** -->
3<!-- -->
4<!--Web Easy Switch Company module for OpenERP -->
5<!--Copyright (C) 2014 GRAP (http://www.grap.coop) -->
6<!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) -->
7
8<!--This program is free software: you can redistribute it and/or modify -->
9<!--it under the terms of the GNU Affero General Public License as -->
10<!--published by the Free Software Foundation, either version 3 of the -->
11<!--License, or (at your option) any later version. -->
12<!-- -->
13<!--This program is distributed in the hope that it will be useful, -->
14<!--but WITHOUT ANY WARRANTY; without even the implied warranty of -->
15<!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
16<!--GNU Affero General Public License for more details. -->
17<!-- -->
18<!--You should have received a copy of the GNU Affero General Public License-->
19<!--along with this program. If not, see <http://www.gnu.org/licenses/>. -->
20<!-- ********************************************************************** -->
21<template>
22
23 <t t-name="web_easy_switch_company.SwitchCompanyWidget">
24 <span class="oe_user_menu oe_topbar_item oe_dropdown_toggle oe_dropdown_arrow">
25 <span>
26 <t t-esc="widget.current_company_name"/>
27 </span>
28 <ul class="oe_dropdown_menu">
29 <t t-foreach="widget.companies" t-as="company">
30 <li>
31 <a class="easy_switch_company_company_item"
32 href="#"
33 t-att-data-company-id="company.id">
34 <img class="oe_topbar_avatar" t-att-src="company.logo_topbar"/>
35 <img class="oe_topbar_avatar" t-att-src="company.logo_state"/>
36 <t t-esc="company.name"/>
37 </a>
38 </li>
39 </t>
40 </ul>
41 </span>
42 </t>
43
44</template>
45
046
=== added directory 'web_easy_switch_company/view'
=== added file 'web_easy_switch_company/view/res_users_view.xml'
--- web_easy_switch_company/view/res_users_view.xml 1970-01-01 00:00:00 +0000
+++ web_easy_switch_company/view/res_users_view.xml 2014-04-02 09:20:18 +0000
@@ -0,0 +1,15 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4
5 <record id="view_res_users_simple_modif_form" model="ir.ui.view">
6 <field name="name">res.users.form</field>
7 <field name="model">res.users</field>
8 <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
9 <field name="arch" type="xml">
10 <!-- hide old behaviour to change company -->
11 <field name="company_id" position="replace" />
12 </field>
13 </record>
14 </data>
15</openerp>

Subscribers

People subscribed via source and target branches