Browse Source
[ADD] web_action_conditionable: Expression based on group xml ids
[ADD] web_action_conditionable: Expression based on group xml ids
[ADD] Tests Enable usage of context Revert "Enable usage of context" [REM] Commented codepull/235/merge
tarteo
6 years ago
committed by
Dennis Sluijk
11 changed files with 159 additions and 63 deletions
-
100web_action_conditionable/README.rst
-
2web_action_conditionable/__init__.py
-
12web_action_conditionable/__openerp__.py
-
3web_action_conditionable/controllers/__init__.py
-
16web_action_conditionable/controllers/main.py
-
2web_action_conditionable/readme/CONTRIBUTORS.rst
-
3web_action_conditionable/readme/CREDITS.rst
-
20web_action_conditionable/readme/DESCRIPTION.rst
-
41web_action_conditionable/static/src/js/views.js
-
1web_action_conditionable/tests/__init__.py
-
20web_action_conditionable/tests/test_action_conditionable.py
@ -1 +1,3 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import controllers |
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import main |
@ -0,0 +1,16 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from openerp.http import request |
||||
|
from openerp.addons.web.controllers.main import Session |
||||
|
|
||||
|
|
||||
|
class MainController(Session): |
||||
|
|
||||
|
def session_info(self): |
||||
|
res = super(MainController, self).session_info() |
||||
|
groups = request.env['ir.model.data'].sudo().search([ |
||||
|
('model', '=', 'res.groups'), |
||||
|
('res_id', 'in', request.env.user.groups_id.ids) |
||||
|
]) |
||||
|
res['group_refs'] = groups.mapped(lambda g: g.complete_name) |
||||
|
return res |
@ -0,0 +1,2 @@ |
|||||
|
* Cristian Salamea <cristian.salamea@gail.com> |
||||
|
* Dennis Sluijk <d.sluijk@onestein.nl> |
@ -0,0 +1,3 @@ |
|||||
|
The development of this module has been financially supported by: |
||||
|
|
||||
|
* Canna <https://www.canna.nl> |
@ -0,0 +1,20 @@ |
|||||
|
This module was written to extend the functionality of actions in tree views. |
||||
|
Odoo by default support: |
||||
|
|
||||
|
:: |
||||
|
|
||||
|
<tree delete="false" create="false"> |
||||
|
|
||||
|
with this module you can do: |
||||
|
|
||||
|
:: |
||||
|
|
||||
|
<tree delete="state=='draft'"> |
||||
|
|
||||
|
you can use `_group_refs` to make a condition based on the user's groups: |
||||
|
|
||||
|
:: |
||||
|
|
||||
|
<tree delete="'base.group_user' in _group_refs"> |
||||
|
|
||||
|
It works in any tree view, so you can use it in One2many. |
@ -1,22 +1,27 @@ |
|||||
/*global openerp, _, $ */ |
/*global openerp, _, $ */ |
||||
|
|
||||
openerp.web_action_conditionable = function (instance) { |
openerp.web_action_conditionable = function (instance) { |
||||
instance.web.View.include({ |
|
||||
is_action_enabled: function(action) { |
|
||||
var attrs = this.fields_view.arch.attrs; |
|
||||
if (action in attrs) { |
|
||||
try { |
|
||||
return this._super(action); |
|
||||
} catch(error) { |
|
||||
var expr = attrs[action]; |
|
||||
var expression = py.parse(py.tokenize(expr)); |
|
||||
var cxt = this.dataset.get_context().__eval_context.__contexts[1]; |
|
||||
var result = py.evaluate(expression, cxt).toJSON(); |
|
||||
return result |
|
||||
} |
|
||||
} else { |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
|
instance.web.View.include({ |
||||
|
/** |
||||
|
* @override |
||||
|
*/ |
||||
|
is_action_enabled: function(action) { |
||||
|
var attrs = this.fields_view.arch.attrs; |
||||
|
if (action in attrs) { |
||||
|
try { |
||||
|
return this._super(action); |
||||
|
} catch(error) { |
||||
|
var expr = attrs[action]; |
||||
|
var expression = py.parse(py.tokenize(expr)); |
||||
|
var cxt = this.dataset.get_context().__eval_context; |
||||
|
cxt = cxt ? cxt.__contexts[1] : {}; |
||||
|
cxt['_group_refs'] = instance.session.group_refs; |
||||
|
|
||||
|
return py.evaluate(expression, cxt).toJSON(); |
||||
|
} |
||||
|
} else { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
} |
} |
@ -0,0 +1 @@ |
|||||
|
from . import test_action_conditionable |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from mock import patch |
||||
|
from openerp.tests.common import TransactionCase |
||||
|
from openerp.addons.web_action_conditionable.controllers.main \ |
||||
|
import MainController |
||||
|
|
||||
|
|
||||
|
class TestActionConditionable(TransactionCase): |
||||
|
@patch('openerp.addons.web_action_conditionable.' |
||||
|
'controllers.main.request') |
||||
|
@patch('openerp.addons.web.controllers.main.request') |
||||
|
def test_session_info(self, request, request2): |
||||
|
# Mock |
||||
|
request.env = self.env |
||||
|
request2.env = self.env |
||||
|
|
||||
|
ctrl = MainController() |
||||
|
res = ctrl.session_info() |
||||
|
self.assertTrue('group_refs' in res) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue