Merge lp:~sylvain-legal/web-addons/7.0-web_easy_switch_company into lp:~webaddons-core-editors/web-addons/7.0
- 7.0-web_easy_switch_company
- Merge into 7.0
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 |
Related bugs: |
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 |
Commit message
Description of the change
Add a new module 'web_easy_
This module allow a user to switch from a company to another more easily. (with just 2 mouse click & without warning message).
Sylvain LE GAL (GRAP) (sylvain-legal) wrote : | # |
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.
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.
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.
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_
In few word, should I change something ?
Regards.
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.
Pedro Manuel Baeza (pedro.baeza) wrote : | # |
s/any of the solutions is ideal/none of the solutions is ideal
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.
'tag': 'reload',
},
}
I'm not sure, but I think you can call it from javascript with
self.
You can inspect the client action in web/static/
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!
Sylvain LE GAL (GRAP) (sylvain-legal) wrote : | # |
Hi Guewen,
I changed import call.
About the reload, the self.do_
Can you say me how to call this function ? I 'rgreped' 'do_action' in web-addons without results.
As Arthru said, openerp call window.
rgrep "window.*reload" ./ gives 3 references in openerp-web project.
Regards.
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_
> 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(
>
> As Arthru said, openerp call window.
> 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.
>
> Regards.
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.
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.
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!!
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://
Preview Diff
1 | === added directory 'web_easy_switch_company' | |||
2 | === added file 'web_easy_switch_company/__init__.py' | |||
3 | --- web_easy_switch_company/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ web_easy_switch_company/__init__.py 2014-04-02 09:20:18 +0000 | |||
5 | @@ -0,0 +1,24 @@ | |||
6 | 1 | # -*- encoding: utf-8 -*- | ||
7 | 2 | ############################################################################## | ||
8 | 3 | # | ||
9 | 4 | # Web Easy Switch Company module for OpenERP | ||
10 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
11 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
12 | 7 | # | ||
13 | 8 | # This program is free software: you can redistribute it and/or modify | ||
14 | 9 | # it under the terms of the GNU Affero General Public License as | ||
15 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
16 | 11 | # License, or (at your option) any later version. | ||
17 | 12 | # | ||
18 | 13 | # This program is distributed in the hope that it will be useful, | ||
19 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | 16 | # GNU Affero General Public License for more details. | ||
22 | 17 | # | ||
23 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
24 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
25 | 20 | # | ||
26 | 21 | ############################################################################## | ||
27 | 22 | |||
28 | 23 | from . import model | ||
29 | 24 | from . import controllers | ||
30 | 0 | 25 | ||
31 | === added file 'web_easy_switch_company/__openerp__.py' | |||
32 | --- web_easy_switch_company/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
33 | +++ web_easy_switch_company/__openerp__.py 2014-04-02 09:20:18 +0000 | |||
34 | @@ -0,0 +1,71 @@ | |||
35 | 1 | # -*- encoding: utf-8 -*- | ||
36 | 2 | ############################################################################## | ||
37 | 3 | # | ||
38 | 4 | # Web Easy Switch Company module for OpenERP | ||
39 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
40 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
41 | 7 | # | ||
42 | 8 | # This program is free software: you can redistribute it and/or modify | ||
43 | 9 | # it under the terms of the GNU Affero General Public License as | ||
44 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
45 | 11 | # License, or (at your option) any later version. | ||
46 | 12 | # | ||
47 | 13 | # This program is distributed in the hope that it will be useful, | ||
48 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
49 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
50 | 16 | # GNU Affero General Public License for more details. | ||
51 | 17 | # | ||
52 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
53 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
54 | 20 | # | ||
55 | 21 | ############################################################################## | ||
56 | 22 | |||
57 | 23 | { | ||
58 | 24 | 'name': 'Multicompany - Easy Switch Company', | ||
59 | 25 | 'version': '1.0', | ||
60 | 26 | 'category': 'web', | ||
61 | 27 | 'description': """ | ||
62 | 28 | Add menu to allow user to switch to another company more easily | ||
63 | 29 | =============================================================== | ||
64 | 30 | |||
65 | 31 | Functionality: | ||
66 | 32 | -------------- | ||
67 | 33 | * Add a new menu in the top bar to switch to another company more easily; | ||
68 | 34 | * Remove the old behaviour to switch company; | ||
69 | 35 | |||
70 | 36 | Documentations: | ||
71 | 37 | --------------- | ||
72 | 38 | * Video : http://www.youtube.com/watch?v=Cpm6dg-IEQQ | ||
73 | 39 | |||
74 | 40 | Technical information: | ||
75 | 41 | ---------------------- | ||
76 | 42 | * Create a field function 'logo_topbar' in res_company to have a good""" | ||
77 | 43 | """resized logo; | ||
78 | 44 | |||
79 | 45 | Limits: | ||
80 | 46 | ------- | ||
81 | 47 | * It would be interesting to show the structure of the companies; | ||
82 | 48 | |||
83 | 49 | Copyright, Author and Licence: | ||
84 | 50 | ------------------------------ | ||
85 | 51 | * Copyright: 2014, Groupement Régional Alimentaire de Proximité; | ||
86 | 52 | * Author: Sylvain LE GAL (https://twitter.com/legalsylvain); | ||
87 | 53 | * Licence: AGPL-3 (http://www.gnu.org/licenses/)""", | ||
88 | 54 | 'author': 'GRAP', | ||
89 | 55 | 'website': 'http://www.grap.coop', | ||
90 | 56 | 'license': 'AGPL-3', | ||
91 | 57 | 'depends': [ | ||
92 | 58 | 'web', | ||
93 | 59 | ], | ||
94 | 60 | 'data': [ | ||
95 | 61 | 'view/res_users_view.xml', | ||
96 | 62 | ], | ||
97 | 63 | 'js': [ | ||
98 | 64 | 'static/src/js/switch_company.js', | ||
99 | 65 | ], | ||
100 | 66 | 'qweb': [ | ||
101 | 67 | 'static/src/xml/switch_company.xml', | ||
102 | 68 | ], | ||
103 | 69 | 'installable': True, | ||
104 | 70 | 'auto_install': False, | ||
105 | 71 | } | ||
106 | 0 | 72 | ||
107 | === added directory 'web_easy_switch_company/controllers' | |||
108 | === added file 'web_easy_switch_company/controllers/__init__.py' | |||
109 | --- web_easy_switch_company/controllers/__init__.py 1970-01-01 00:00:00 +0000 | |||
110 | +++ web_easy_switch_company/controllers/__init__.py 2014-04-02 09:20:18 +0000 | |||
111 | @@ -0,0 +1,23 @@ | |||
112 | 1 | # -*- encoding: utf-8 -*- | ||
113 | 2 | ############################################################################## | ||
114 | 3 | # | ||
115 | 4 | # Web Easy Switch Company module for OpenERP | ||
116 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
117 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
118 | 7 | # | ||
119 | 8 | # This program is free software: you can redistribute it and/or modify | ||
120 | 9 | # it under the terms of the GNU Affero General Public License as | ||
121 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
122 | 11 | # License, or (at your option) any later version. | ||
123 | 12 | # | ||
124 | 13 | # This program is distributed in the hope that it will be useful, | ||
125 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
126 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
127 | 16 | # GNU Affero General Public License for more details. | ||
128 | 17 | # | ||
129 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
130 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
131 | 20 | # | ||
132 | 21 | ############################################################################## | ||
133 | 22 | |||
134 | 23 | from . import main | ||
135 | 0 | 24 | ||
136 | === added file 'web_easy_switch_company/controllers/main.py' | |||
137 | --- web_easy_switch_company/controllers/main.py 1970-01-01 00:00:00 +0000 | |||
138 | +++ web_easy_switch_company/controllers/main.py 2014-04-02 09:20:18 +0000 | |||
139 | @@ -0,0 +1,31 @@ | |||
140 | 1 | # -*- encoding: utf-8 -*- | ||
141 | 2 | ############################################################################## | ||
142 | 3 | # | ||
143 | 4 | # Web Easy Switch Company module for OpenERP | ||
144 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
145 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
146 | 7 | # | ||
147 | 8 | # This program is free software: you can redistribute it and/or modify | ||
148 | 9 | # it under the terms of the GNU Affero General Public License as | ||
149 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
150 | 11 | # License, or (at your option) any later version. | ||
151 | 12 | # | ||
152 | 13 | # This program is distributed in the hope that it will be useful, | ||
153 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
154 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
155 | 16 | # GNU Affero General Public License for more details. | ||
156 | 17 | # | ||
157 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
158 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
159 | 20 | # | ||
160 | 21 | ############################################################################## | ||
161 | 22 | |||
162 | 23 | import openerp | ||
163 | 24 | |||
164 | 25 | |||
165 | 26 | class WebEasySwitchCompanyController(openerp.addons.web.http.Controller): | ||
166 | 27 | _cp_path = '/web_easy_switch_company/switch' | ||
167 | 28 | |||
168 | 29 | @openerp.addons.web.http.jsonrequest | ||
169 | 30 | def change_current_company(self, req, company_id): | ||
170 | 31 | req.session.model('res.users').change_current_company(company_id) | ||
171 | 0 | 32 | ||
172 | === added directory 'web_easy_switch_company/model' | |||
173 | === added file 'web_easy_switch_company/model/__init__.py' | |||
174 | --- web_easy_switch_company/model/__init__.py 1970-01-01 00:00:00 +0000 | |||
175 | +++ web_easy_switch_company/model/__init__.py 2014-04-02 09:20:18 +0000 | |||
176 | @@ -0,0 +1,24 @@ | |||
177 | 1 | # -*- encoding: utf-8 -*- | ||
178 | 2 | ############################################################################## | ||
179 | 3 | # | ||
180 | 4 | # Web Easy Switch Company module for OpenERP | ||
181 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
182 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
183 | 7 | # | ||
184 | 8 | # This program is free software: you can redistribute it and/or modify | ||
185 | 9 | # it under the terms of the GNU Affero General Public License as | ||
186 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
187 | 11 | # License, or (at your option) any later version. | ||
188 | 12 | # | ||
189 | 13 | # This program is distributed in the hope that it will be useful, | ||
190 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
191 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
192 | 16 | # GNU Affero General Public License for more details. | ||
193 | 17 | # | ||
194 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
195 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
196 | 20 | # | ||
197 | 21 | ############################################################################## | ||
198 | 22 | |||
199 | 23 | from . import res_users | ||
200 | 24 | from . import res_company | ||
201 | 0 | 25 | ||
202 | === added file 'web_easy_switch_company/model/res_company.py' | |||
203 | --- web_easy_switch_company/model/res_company.py 1970-01-01 00:00:00 +0000 | |||
204 | +++ web_easy_switch_company/model/res_company.py 2014-04-02 09:20:18 +0000 | |||
205 | @@ -0,0 +1,57 @@ | |||
206 | 1 | # -*- encoding: utf-8 -*- | ||
207 | 2 | ############################################################################## | ||
208 | 3 | # | ||
209 | 4 | # Web Easy Switch Company module for OpenERP | ||
210 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
211 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
212 | 7 | # | ||
213 | 8 | # This program is free software: you can redistribute it and/or modify | ||
214 | 9 | # it under the terms of the GNU Affero General Public License as | ||
215 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
216 | 11 | # License, or (at your option) any later version. | ||
217 | 12 | # | ||
218 | 13 | # This program is distributed in the hope that it will be useful, | ||
219 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
220 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
221 | 16 | # GNU Affero General Public License for more details. | ||
222 | 17 | # | ||
223 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
224 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
225 | 20 | # | ||
226 | 21 | ############################################################################## | ||
227 | 22 | |||
228 | 23 | from openerp.osv import fields | ||
229 | 24 | from openerp.osv.orm import Model | ||
230 | 25 | from openerp.tools import image_resize_image | ||
231 | 26 | |||
232 | 27 | |||
233 | 28 | class res_company(Model): | ||
234 | 29 | _inherit = 'res.company' | ||
235 | 30 | |||
236 | 31 | # Custom Section | ||
237 | 32 | def _switch_company_get_companies_from_partner( | ||
238 | 33 | self, cr, uid, ids, context=None): | ||
239 | 34 | return self.pool['res.company'].search( | ||
240 | 35 | cr, uid, [('partner_id', 'in', ids)], context=context) | ||
241 | 36 | |||
242 | 37 | # Fields function Section | ||
243 | 38 | def _get_logo_topbar(self, cr, uid, ids, _field_name, _args, context=None): | ||
244 | 39 | result = dict.fromkeys(ids, False) | ||
245 | 40 | for record in self.browse(cr, uid, ids, context=context): | ||
246 | 41 | size = (48, 48) | ||
247 | 42 | result[record.id] = image_resize_image( | ||
248 | 43 | record.partner_id.image, size) | ||
249 | 44 | return result | ||
250 | 45 | |||
251 | 46 | # Columns Section | ||
252 | 47 | _columns = { | ||
253 | 48 | 'logo_topbar': fields.function( | ||
254 | 49 | _get_logo_topbar, | ||
255 | 50 | string="Logo displayed in the switch company menu", | ||
256 | 51 | type="binary", store={ | ||
257 | 52 | 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10), | ||
258 | 53 | 'res.partner': (_switch_company_get_companies_from_partner, | ||
259 | 54 | ['image'], 10), | ||
260 | 55 | } | ||
261 | 56 | ), | ||
262 | 57 | } | ||
263 | 0 | 58 | ||
264 | === added file 'web_easy_switch_company/model/res_users.py' | |||
265 | --- web_easy_switch_company/model/res_users.py 1970-01-01 00:00:00 +0000 | |||
266 | +++ web_easy_switch_company/model/res_users.py 2014-04-02 09:20:18 +0000 | |||
267 | @@ -0,0 +1,31 @@ | |||
268 | 1 | # -*- encoding: utf-8 -*- | ||
269 | 2 | ############################################################################## | ||
270 | 3 | # | ||
271 | 4 | # Web Easy Switch Company module for OpenERP | ||
272 | 5 | # Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
273 | 6 | # @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
274 | 7 | # | ||
275 | 8 | # This program is free software: you can redistribute it and/or modify | ||
276 | 9 | # it under the terms of the GNU Affero General Public License as | ||
277 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
278 | 11 | # License, or (at your option) any later version. | ||
279 | 12 | # | ||
280 | 13 | # This program is distributed in the hope that it will be useful, | ||
281 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
282 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
283 | 16 | # GNU Affero General Public License for more details. | ||
284 | 17 | # | ||
285 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
286 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
287 | 20 | # | ||
288 | 21 | ############################################################################## | ||
289 | 22 | |||
290 | 23 | from openerp.osv.orm import Model | ||
291 | 24 | |||
292 | 25 | |||
293 | 26 | class res_users(Model): | ||
294 | 27 | _inherit = 'res.users' | ||
295 | 28 | |||
296 | 29 | # Custom Function Section | ||
297 | 30 | def change_current_company(self, cr, uid, company_id, context=None): | ||
298 | 31 | return self.write(cr, uid, uid, {'company_id': company_id}) | ||
299 | 0 | 32 | ||
300 | === added directory 'web_easy_switch_company/static' | |||
301 | === added directory 'web_easy_switch_company/static/src' | |||
302 | === added directory 'web_easy_switch_company/static/src/img' | |||
303 | === added file 'web_easy_switch_company/static/src/img/icon.png' | |||
304 | 1 | Binary 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 | 33 | Binary 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 |
305 | === added file 'web_easy_switch_company/static/src/img/selection-off.png' | |||
306 | 2 | Binary 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 | 34 | Binary 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 |
307 | === added file 'web_easy_switch_company/static/src/img/selection-on.png' | |||
308 | 3 | Binary 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 | 35 | Binary 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 |
309 | === added directory 'web_easy_switch_company/static/src/js' | |||
310 | === added file 'web_easy_switch_company/static/src/js/switch_company.js' | |||
311 | --- web_easy_switch_company/static/src/js/switch_company.js 1970-01-01 00:00:00 +0000 | |||
312 | +++ web_easy_switch_company/static/src/js/switch_company.js 2014-04-02 09:20:18 +0000 | |||
313 | @@ -0,0 +1,137 @@ | |||
314 | 1 | /****************************************************************************** | ||
315 | 2 | Web Easy Switch Company module for OpenERP | ||
316 | 3 | Copyright (C) 2014 GRAP (http://www.grap.coop) | ||
317 | 4 | @author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
318 | 5 | |||
319 | 6 | This program is free software: you can redistribute it and/or modify | ||
320 | 7 | it under the terms of the GNU Affero General Public License as | ||
321 | 8 | published by the Free Software Foundation, either version 3 of the | ||
322 | 9 | License, or (at your option) any later version. | ||
323 | 10 | |||
324 | 11 | This program is distributed in the hope that it will be useful, | ||
325 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
326 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
327 | 14 | GNU Affero General Public License for more details. | ||
328 | 15 | |||
329 | 16 | You should have received a copy of the GNU Affero General Public License | ||
330 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
331 | 18 | ******************************************************************************/ | ||
332 | 19 | |||
333 | 20 | openerp.web_easy_switch_company = function (instance) { | ||
334 | 21 | |||
335 | 22 | /*************************************************************************** | ||
336 | 23 | Create an new 'SwitchCompanyWidget' widget that allow users to switch | ||
337 | 24 | from a company to another more easily. | ||
338 | 25 | ***************************************************************************/ | ||
339 | 26 | instance.web.SwitchCompanyWidget = instance.web.Widget.extend({ | ||
340 | 27 | |||
341 | 28 | template:'web_easy_switch_company.SwitchCompanyWidget', | ||
342 | 29 | |||
343 | 30 | /*********************************************************************** | ||
344 | 31 | Overload section | ||
345 | 32 | ***********************************************************************/ | ||
346 | 33 | |||
347 | 34 | /** | ||
348 | 35 | * Overload 'init' function to initialize the values of the widget. | ||
349 | 36 | */ | ||
350 | 37 | init: function(parent){ | ||
351 | 38 | this._super(parent); | ||
352 | 39 | this.companies = []; | ||
353 | 40 | this.current_company_id = 0; | ||
354 | 41 | this.current_company_name = ''; | ||
355 | 42 | }, | ||
356 | 43 | |||
357 | 44 | /** | ||
358 | 45 | * Overload 'start' function to load datas from DB. | ||
359 | 46 | */ | ||
360 | 47 | start: function () { | ||
361 | 48 | this._super(); | ||
362 | 49 | this._load_data(); | ||
363 | 50 | }, | ||
364 | 51 | |||
365 | 52 | /** | ||
366 | 53 | * Overload 'renderElement' function to set events on company items. | ||
367 | 54 | */ | ||
368 | 55 | renderElement: function() { | ||
369 | 56 | var self = this; | ||
370 | 57 | this._super(); | ||
371 | 58 | if (this.companies.length === 1) { | ||
372 | 59 | this.$el.hide(); | ||
373 | 60 | } | ||
374 | 61 | else{ | ||
375 | 62 | this.$el.show(); | ||
376 | 63 | this.$el.find('.easy_switch_company_company_item').on('click', function(ev) { | ||
377 | 64 | var company_id = $(ev.target).data("company-id"); | ||
378 | 65 | if (company_id != self.current_company_id){ | ||
379 | 66 | var func = '/web_easy_switch_company/switch/change_current_company'; | ||
380 | 67 | var param = {'company_id': company_id} | ||
381 | 68 | self.rpc(func, param).done(function(res) { | ||
382 | 69 | window.location.reload() | ||
383 | 70 | }); | ||
384 | 71 | } | ||
385 | 72 | }); | ||
386 | 73 | } | ||
387 | 74 | }, | ||
388 | 75 | |||
389 | 76 | |||
390 | 77 | /*********************************************************************** | ||
391 | 78 | Custom section | ||
392 | 79 | ***********************************************************************/ | ||
393 | 80 | |||
394 | 81 | /** | ||
395 | 82 | * helper function to load data from the server | ||
396 | 83 | */ | ||
397 | 84 | _fetch: function(model, fields, domain, ctx){ | ||
398 | 85 | return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all(); | ||
399 | 86 | }, | ||
400 | 87 | |||
401 | 88 | /** | ||
402 | 89 | * - Load data of the companies allowed to the current users; | ||
403 | 90 | * - Launch the rendering of the current widget; | ||
404 | 91 | */ | ||
405 | 92 | _load_data: function(){ | ||
406 | 93 | var self = this; | ||
407 | 94 | // Request for current users information | ||
408 | 95 | this._fetch('res.users',['company_id','company_ids'],[['id','=',this.session.uid]]).then(function(res_users){ | ||
409 | 96 | self.current_company_id = res_users[0].company_id[0]; | ||
410 | 97 | self.current_company_name = res_users[0].company_id[1]; | ||
411 | 98 | // Request for other companies | ||
412 | 99 | self._fetch('res.company',['name',],[['id','in', res_users[0].company_ids]]).then(function(res_company){ | ||
413 | 100 | for ( var i=0 ; i < res_company.length; i++) { | ||
414 | 101 | res_company[i]['logo_topbar'] = self.session.url( | ||
415 | 102 | '/web/binary/image', { | ||
416 | 103 | model:'res.company', | ||
417 | 104 | field: 'logo_topbar', | ||
418 | 105 | id: res_company[i].id | ||
419 | 106 | }); | ||
420 | 107 | if (res_company[i].id == self.current_company_id){ | ||
421 | 108 | res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-on.png'; | ||
422 | 109 | } | ||
423 | 110 | else{ | ||
424 | 111 | res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-off.png'; | ||
425 | 112 | } | ||
426 | 113 | self.companies.push(res_company[i]); | ||
427 | 114 | } | ||
428 | 115 | // Update rendering | ||
429 | 116 | self.renderElement(); | ||
430 | 117 | }); | ||
431 | 118 | }); | ||
432 | 119 | }, | ||
433 | 120 | |||
434 | 121 | }); | ||
435 | 122 | |||
436 | 123 | /*************************************************************************** | ||
437 | 124 | Extend 'UserMenu' Widget to insert a 'SwitchCompanyWidget' widget. | ||
438 | 125 | ***************************************************************************/ | ||
439 | 126 | instance.web.UserMenu = instance.web.UserMenu.extend({ | ||
440 | 127 | |||
441 | 128 | init: function(parent) { | ||
442 | 129 | this._super(parent); | ||
443 | 130 | var switch_button = new instance.web.SwitchCompanyWidget(); | ||
444 | 131 | switch_button.appendTo(instance.webclient.$el.find('.oe_systray')); | ||
445 | 132 | }, | ||
446 | 133 | |||
447 | 134 | }); | ||
448 | 135 | |||
449 | 136 | }; | ||
450 | 137 | |||
451 | 0 | 138 | ||
452 | === added directory 'web_easy_switch_company/static/src/xml' | |||
453 | === added file 'web_easy_switch_company/static/src/xml/switch_company.xml' | |||
454 | --- web_easy_switch_company/static/src/xml/switch_company.xml 1970-01-01 00:00:00 +0000 | |||
455 | +++ web_easy_switch_company/static/src/xml/switch_company.xml 2014-04-02 09:20:18 +0000 | |||
456 | @@ -0,0 +1,45 @@ | |||
457 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
458 | 2 | <!-- ********************************************************************** --> | ||
459 | 3 | <!-- --> | ||
460 | 4 | <!--Web Easy Switch Company module for OpenERP --> | ||
461 | 5 | <!--Copyright (C) 2014 GRAP (http://www.grap.coop) --> | ||
462 | 6 | <!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) --> | ||
463 | 7 | |||
464 | 8 | <!--This program is free software: you can redistribute it and/or modify --> | ||
465 | 9 | <!--it under the terms of the GNU Affero General Public License as --> | ||
466 | 10 | <!--published by the Free Software Foundation, either version 3 of the --> | ||
467 | 11 | <!--License, or (at your option) any later version. --> | ||
468 | 12 | <!-- --> | ||
469 | 13 | <!--This program is distributed in the hope that it will be useful, --> | ||
470 | 14 | <!--but WITHOUT ANY WARRANTY; without even the implied warranty of --> | ||
471 | 15 | <!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --> | ||
472 | 16 | <!--GNU Affero General Public License for more details. --> | ||
473 | 17 | <!-- --> | ||
474 | 18 | <!--You should have received a copy of the GNU Affero General Public License--> | ||
475 | 19 | <!--along with this program. If not, see <http://www.gnu.org/licenses/>. --> | ||
476 | 20 | <!-- ********************************************************************** --> | ||
477 | 21 | <template> | ||
478 | 22 | |||
479 | 23 | <t t-name="web_easy_switch_company.SwitchCompanyWidget"> | ||
480 | 24 | <span class="oe_user_menu oe_topbar_item oe_dropdown_toggle oe_dropdown_arrow"> | ||
481 | 25 | <span> | ||
482 | 26 | <t t-esc="widget.current_company_name"/> | ||
483 | 27 | </span> | ||
484 | 28 | <ul class="oe_dropdown_menu"> | ||
485 | 29 | <t t-foreach="widget.companies" t-as="company"> | ||
486 | 30 | <li> | ||
487 | 31 | <a class="easy_switch_company_company_item" | ||
488 | 32 | href="#" | ||
489 | 33 | t-att-data-company-id="company.id"> | ||
490 | 34 | <img class="oe_topbar_avatar" t-att-src="company.logo_topbar"/> | ||
491 | 35 | <img class="oe_topbar_avatar" t-att-src="company.logo_state"/> | ||
492 | 36 | <t t-esc="company.name"/> | ||
493 | 37 | </a> | ||
494 | 38 | </li> | ||
495 | 39 | </t> | ||
496 | 40 | </ul> | ||
497 | 41 | </span> | ||
498 | 42 | </t> | ||
499 | 43 | |||
500 | 44 | </template> | ||
501 | 45 | |||
502 | 0 | 46 | ||
503 | === added directory 'web_easy_switch_company/view' | |||
504 | === added file 'web_easy_switch_company/view/res_users_view.xml' | |||
505 | --- web_easy_switch_company/view/res_users_view.xml 1970-01-01 00:00:00 +0000 | |||
506 | +++ web_easy_switch_company/view/res_users_view.xml 2014-04-02 09:20:18 +0000 | |||
507 | @@ -0,0 +1,15 @@ | |||
508 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
509 | 2 | <openerp> | ||
510 | 3 | <data> | ||
511 | 4 | |||
512 | 5 | <record id="view_res_users_simple_modif_form" model="ir.ui.view"> | ||
513 | 6 | <field name="name">res.users.form</field> | ||
514 | 7 | <field name="model">res.users</field> | ||
515 | 8 | <field name="inherit_id" ref="base.view_users_form_simple_modif"/> | ||
516 | 9 | <field name="arch" type="xml"> | ||
517 | 10 | <!-- hide old behaviour to change company --> | ||
518 | 11 | <field name="company_id" position="replace" /> | ||
519 | 12 | </field> | ||
520 | 13 | </record> | ||
521 | 14 | </data> | ||
522 | 15 | </openerp> |
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) bazaar. launchpad. net/~openerp/ openerp- web/7.0/ view/head: /addons/ web/static/ src/js/ chrome. js#L1117
http://
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.