diff --git a/web_action_conditionable/README.rst b/web_action_conditionable/README.rst index 054a8d27..ff627e29 100644 --- a/web_action_conditionable/README.rst +++ b/web_action_conditionable/README.rst @@ -1,8 +1,29 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 - -Web Action Conditionable ======================== +web_action_conditionable +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/8.0/web_action_conditionable + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-8-0/web-8-0-web_action_conditionable + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/8.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| This module was written to extend the functionality of actions in tree views. Odoo by default support: @@ -11,73 +32,70 @@ Odoo by default support: -with this module you can: +with this module you can do: :: - - - -It works in any tree view, so you can use it in One2many. - - -Installation -============ - -To install this module, just follow basic steps to install an odoo module. - - -Configuration -============= - -Not needed. -Usage -===== - -To use this module, you need to: + -* go to ... +you can use `_group_refs` to make a condition based on the user's groups: -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/web/8.0 +:: -.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt -.. branch is "8.0" for example + -For further information, please visit: +It works in any tree view, so you can use it in One2many. -* https://www.odoo.com/forum/help-1 +**Table of contents** +.. contents:: + :local: Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Cristian Salamea +* Onestein + Contributors ------------- +~~~~~~~~~~~~ + +* Cristian Salamea +* Dennis Sluijk -* Cristian Salamea +Other credits +~~~~~~~~~~~~~ -Maintainer ----------- +The development of this module has been financially supported by: + +* Canna + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_action_conditionable/__init__.py b/web_action_conditionable/__init__.py index 40a96afc..b0f26a9a 100644 --- a/web_action_conditionable/__init__.py +++ b/web_action_conditionable/__init__.py @@ -1 +1,3 @@ # -*- coding: utf-8 -*- + +from . import controllers diff --git a/web_action_conditionable/__openerp__.py b/web_action_conditionable/__openerp__.py index d17cad2d..8ab32d34 100644 --- a/web_action_conditionable/__openerp__.py +++ b/web_action_conditionable/__openerp__.py @@ -2,13 +2,19 @@ { "name": 'web_action_conditionable', - "version": "8.0.0.1.0", + "version": "8.0.1.1.0", + "category": "Web", + "website": "https://github.com/OCA/web", + "development_status": "Beta", "depends": [ 'base', 'web', ], "license": "AGPL-3", - 'data': ['views/view.xml'], - "author": "Cristian Salamea,Odoo Community Association (OCA)", + 'data': [ + 'views/view.xml' + ], + "author": "Cristian Salamea,Onestein," + "Odoo Community Association (OCA)", "installable": True, } diff --git a/web_action_conditionable/controllers/__init__.py b/web_action_conditionable/controllers/__init__.py new file mode 100644 index 00000000..65a8c120 --- /dev/null +++ b/web_action_conditionable/controllers/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import main diff --git a/web_action_conditionable/controllers/main.py b/web_action_conditionable/controllers/main.py new file mode 100644 index 00000000..252f6e28 --- /dev/null +++ b/web_action_conditionable/controllers/main.py @@ -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 diff --git a/web_action_conditionable/readme/CONTRIBUTORS.rst b/web_action_conditionable/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..85c28af1 --- /dev/null +++ b/web_action_conditionable/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Cristian Salamea +* Dennis Sluijk diff --git a/web_action_conditionable/readme/CREDITS.rst b/web_action_conditionable/readme/CREDITS.rst new file mode 100644 index 00000000..72fe4b4d --- /dev/null +++ b/web_action_conditionable/readme/CREDITS.rst @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +* Canna diff --git a/web_action_conditionable/readme/DESCRIPTION.rst b/web_action_conditionable/readme/DESCRIPTION.rst new file mode 100644 index 00000000..8c4852a4 --- /dev/null +++ b/web_action_conditionable/readme/DESCRIPTION.rst @@ -0,0 +1,20 @@ +This module was written to extend the functionality of actions in tree views. +Odoo by default support: + +:: + + + +with this module you can do: + +:: + + + +you can use `_group_refs` to make a condition based on the user's groups: + +:: + + + +It works in any tree view, so you can use it in One2many. diff --git a/web_action_conditionable/static/src/js/views.js b/web_action_conditionable/static/src/js/views.js index 5eeb6c4a..650e1d3f 100644 --- a/web_action_conditionable/static/src/js/views.js +++ b/web_action_conditionable/static/src/js/views.js @@ -1,22 +1,27 @@ /*global openerp, _, $ */ 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; + } + } + }); } diff --git a/web_action_conditionable/tests/__init__.py b/web_action_conditionable/tests/__init__.py new file mode 100644 index 00000000..09b8ca42 --- /dev/null +++ b/web_action_conditionable/tests/__init__.py @@ -0,0 +1 @@ +from . import test_action_conditionable diff --git a/web_action_conditionable/tests/test_action_conditionable.py b/web_action_conditionable/tests/test_action_conditionable.py new file mode 100644 index 00000000..eec2b6ca --- /dev/null +++ b/web_action_conditionable/tests/test_action_conditionable.py @@ -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)