3
0
Fork 0

[ADD] web_action_conditionable: Expression based on group xml ids

[ADD] Tests

Enable usage of context

Revert "Enable usage of context"

[REM] Commented code
8.0
tarteo 2018-12-04 09:36:06 +01:00 committed by Dennis Sluijk
parent c55ceba978
commit db090d78ba
11 changed files with 161 additions and 65 deletions

View File

@ -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. This module was written to extend the functionality of actions in tree views.
Odoo by default support: Odoo by default support:
@ -11,73 +32,70 @@ Odoo by default support:
<tree delete="false" create="false"> <tree delete="false" create="false">
with this module you can: with this module you can do:
:: ::
<tree delete="state=='draft'"> <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. It works in any tree view, so you can use it in One2many.
**Table of contents**
Installation .. contents::
============ :local:
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 ...
.. 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:
* https://www.odoo.com/forum/help-1
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`here <https://github.com/OCA/web/issues/new?body=module:web_action_conditionableversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/web/issues/new?body=module:%20web_action_conditionable%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits Credits
======= =======
Authors
~~~~~~~
* Cristian Salamea
* Onestein
Contributors Contributors
------------ ~~~~~~~~~~~~
* Cristian Salamea <cristian.salamea@gmail.com> * Cristian Salamea <cristian.salamea@gail.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
Maintainer Other credits
---------- ~~~~~~~~~~~~~
The development of this module has been financially supported by:
* Canna <https://www.canna.nl>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png .. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association :alt: Odoo Community Association
:target: https://odoo-community.org :target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
To contribute to this module, please visit http://odoo-community.org. This module is part of the `OCA/web <https://github.com/OCA/web/tree/8.0/web_action_conditionable>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import controllers

View File

@ -2,13 +2,19 @@
{ {
"name": 'web_action_conditionable', "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": [ "depends": [
'base', 'base',
'web', 'web',
], ],
"license": "AGPL-3", "license": "AGPL-3",
'data': ['views/view.xml'], 'data': [
"author": "Cristian Salamea,Odoo Community Association (OCA)", 'views/view.xml'
],
"author": "Cristian Salamea,Onestein,"
"Odoo Community Association (OCA)",
"installable": True, "installable": True,
} }

View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import main

View File

@ -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

View File

@ -0,0 +1,2 @@
* Cristian Salamea <cristian.salamea@gail.com>
* Dennis Sluijk <d.sluijk@onestein.nl>

View File

@ -0,0 +1,3 @@
The development of this module has been financially supported by:
* Canna <https://www.canna.nl>

View File

@ -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.

View File

@ -1,22 +1,27 @@
/*global openerp, _, $ */ /*global openerp, _, $ */
openerp.web_action_conditionable = function (instance) { openerp.web_action_conditionable = function (instance) {
instance.web.View.include({ instance.web.View.include({
is_action_enabled: function(action) { /**
var attrs = this.fields_view.arch.attrs; * @override
if (action in attrs) { */
try { is_action_enabled: function(action) {
return this._super(action); var attrs = this.fields_view.arch.attrs;
} catch(error) { if (action in attrs) {
var expr = attrs[action]; try {
var expression = py.parse(py.tokenize(expr)); return this._super(action);
var cxt = this.dataset.get_context().__eval_context.__contexts[1]; } catch(error) {
var result = py.evaluate(expression, cxt).toJSON(); var expr = attrs[action];
return result var expression = py.parse(py.tokenize(expr));
} var cxt = this.dataset.get_context().__eval_context;
} else { cxt = cxt ? cxt.__contexts[1] : {};
return true; cxt['_group_refs'] = instance.session.group_refs;
}
} return py.evaluate(expression, cxt).toJSON();
}); }
} else {
return true;
}
}
});
} }

View File

@ -0,0 +1 @@
from . import test_action_conditionable

View File

@ -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)