Merge lp:~acsone-openerp/web-addons/bug-1303944-sbi into lp:~webaddons-core-editors/web-addons/7.0

Proposed by Stéphane Bidoul (Acsone)
Status: Merged
Merged at revision: 36
Proposed branch: lp:~acsone-openerp/web-addons/bug-1303944-sbi
Merge into: lp:~webaddons-core-editors/web-addons/7.0
Prerequisite: lp:~acsone-openerp/web-addons/web_easy_switch_company-userform-fix-sbi
Diff against target: 53 lines (+24/-8)
1 file modified
web_easy_switch_company/static/src/js/switch_company.js (+24/-8)
To merge this branch: bzr merge lp:~acsone-openerp/web-addons/bug-1303944-sbi
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza code review and test Approve
arthru (community) tested Approve
Review via email: mp+216422@code.launchpad.net

Description of the change

[FIX] web_easy_switch_company: propose the correct companies to non-admin users

Emulate the exact behaviour of the stock user preferences form.

To post a comment you must log in.
32. By Stéphane Bidoul (Acsone)

Added a comment about an issue with the logos

Revision history for this message
arthru (arthru) wrote :

Tested with admin and non admin users.

review: Approve (tested)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Note: logos do not display correctely, and, as far as I can tell, there is no way to make this work with the default record rule.

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

LGTM.

Sorry for the late.

+++

review: Approve (code review, test)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Hi Sylvain, thanks for the review.

What do you think about the logos. In practice they don't display properly with non admin users and I see no way out of that. Should we remove them?

-sbi

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

Hi Stéphane,

I don't have a precise idea about that.
I'm pretty in favor to keep that feature because :
- it works for admin user and doesn't bug with non-admin users;
- It works if admin user decide to change default ACL;

I'm agree : it's not very clean. (but OpenERP Core is not very clean in that case...)

Other point of you ?

Regards.

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

I'm fine with your view. It does not crash indeed and users don't complain. So let's keep it that way for now.

Thanks again for this neat module!

-sbi

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

I have tried and it works good for admin and non admin users. It's a pity the logos issue, but module is very good even with that!

Regards

review: Approve (code review and test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'web_easy_switch_company/static/src/js/switch_company.js'
2--- web_easy_switch_company/static/src/js/switch_company.js 2014-04-02 09:17:53 +0000
3+++ web_easy_switch_company/static/src/js/switch_company.js 2014-04-18 10:09:50 +0000
4@@ -92,25 +92,41 @@
5 _load_data: function(){
6 var self = this;
7 // Request for current users information
8- this._fetch('res.users',['company_id','company_ids'],[['id','=',this.session.uid]]).then(function(res_users){
9+ this._fetch('res.users',['company_id'],[['id','=',this.session.uid]]).then(function(res_users){
10 self.current_company_id = res_users[0].company_id[0];
11 self.current_company_name = res_users[0].company_id[1];
12 // Request for other companies
13- self._fetch('res.company',['name',],[['id','in', res_users[0].company_ids]]).then(function(res_company){
14+ // We have to go through fields_view_get to emulate the
15+ // exact (exotic) behavior of the user preferences form in
16+ // fetching the allowed companies wrt record rules.
17+ // Note: calling res.company.name_search with
18+ // user_preference=True in the context does
19+ // not work either.
20+ new instance.web.Model('res.users').call('fields_view_get',{context:{'form_view_ref':'base.view_users_form_simple_modif'}}).then(function(res){
21+ var res_company = res.fields.company_id.selection;
22 for ( var i=0 ; i < res_company.length; i++) {
23- res_company[i]['logo_topbar'] = self.session.url(
24+ var logo_topbar, logo_state;
25+ // TODO: fetching the logo of other companies fails with the
26+ // default res.company record rule, so we should
27+ // probably remove the logos from the menu :(
28+ logo_topbar = self.session.url(
29 '/web/binary/image', {
30 model:'res.company',
31 field: 'logo_topbar',
32- id: res_company[i].id
33+ id: res_company[i][0]
34 });
35- if (res_company[i].id == self.current_company_id){
36- res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-on.png';
37+ if (res_company[i][0] == self.current_company_id){
38+ logo_state = '/web_easy_switch_company/static/src/img/selection-on.png';
39 }
40 else{
41- res_company[i]['logo_state'] = '/web_easy_switch_company/static/src/img/selection-off.png';
42+ logo_state = '/web_easy_switch_company/static/src/img/selection-off.png';
43 }
44- self.companies.push(res_company[i]);
45+ self.companies.push({
46+ id: res_company[i][0],
47+ name: res_company[i][1],
48+ logo_topbar: logo_topbar,
49+ logo_state: logo_state
50+ });
51 }
52 // Update rendering
53 self.renderElement();

Subscribers

People subscribed via source and target branches