Skip to content

Commit

Permalink
Fix javascript code of smile_web_impex
Browse files Browse the repository at this point in the history
Using a callback to evaluate whether the button should be hidden
does not always work. The callback is not guaranteed to be called instantaneously.

For example, when refreshing the screen, the export button disapears.

Instead, use the session to store flags to indicate whether the user is member of
the import/export groups.
  • Loading branch information
isabellerichard committed Feb 25, 2020
1 parent 048c1a9 commit 17c9e6d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
2 changes: 2 additions & 0 deletions smile_web_impex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.fr>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import models
6 changes: 6 additions & 0 deletions smile_web_impex/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# (C) 2019 Smile (<http://www.smile.fr>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import (
ir_http,
)
15 changes: 15 additions & 0 deletions smile_web_impex/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# (C) 2019 Smile (<http://www.smile.fr>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import models


class IrHttp(models.AbstractModel):

_inherit = 'ir.http'

def session_info(self):
result = super().session_info()
result['has_group_smile_import'] = self.env.user.has_group('smile_web_impex.group_import')
result['has_group_smile_export'] = self.env.user.has_group('smile_web_impex.group_export')
return result
36 changes: 6 additions & 30 deletions smile_web_impex/static/src/js/web_impex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ odoo.define('web_impex', function (require) {
var KanbanController = require('web.KanbanController');
var ListController = require("web.ListController");
var _t = core._t;
var session = require("web.session");

KanbanController.include({
/**
Expand All @@ -14,16 +15,8 @@ odoo.define('web_impex', function (require) {
renderButtons: function () {
this._super.apply(this, arguments); // Sets this.$buttons

var has_import_group = false;
this.getSession().user_has_group('smile_web_impex.group_import').then(function(has_group) {
if(has_group) {
has_import_group = true;
} else {
has_import_group = false;
}
});

if (!has_import_group && this.$buttons != undefined) {
var has_import_group = session.has_group_smile_import;
if (!has_import_group && this.$buttons !== undefined) {
this.$buttons.find('.o_button_import').hide();
}
},
Expand All @@ -37,16 +30,8 @@ odoo.define('web_impex', function (require) {
renderButtons: function () {
this._super.apply(this, arguments); // Sets this.$buttons

var has_import_group = false;
this.getSession().user_has_group('smile_web_impex.group_import').then(function(has_group) {
if(has_group) {
has_import_group = true;
} else {
has_import_group = false;
}
});

if (!has_import_group && this.$buttons != undefined) {
var has_import_group = session.has_group_smile_import;
if (!has_import_group && this.$buttons !== undefined) {
this.$buttons.find('.o_button_import').hide();
}
},
Expand All @@ -56,18 +41,9 @@ odoo.define('web_impex', function (require) {
*/
renderSidebar: function ($node) {
if (this.hasSidebar && !this.sidebar) {

var has_export_group = false;
this.getSession().user_has_group('smile_web_impex.group_export').then(function(has_group) {
if(has_group) {
has_export_group = true;
} else {
has_export_group = false;
}
});

var other = [];

var has_export_group = session.has_group_smile_export;
if (has_export_group) {
other.push({
label: _t("Export"),
Expand Down

0 comments on commit 17c9e6d

Please sign in to comment.