Browse Source

[ADD] web_action_conditionable: Expression based on group xml ids

[ADD] Tests

Enable usage of context

Revert "Enable usage of context"

[REM] Commented code
pull/235/merge
tarteo 6 years ago
committed by Dennis Sluijk
parent
commit
db090d78ba
  1. 102
      web_action_conditionable/README.rst
  2. 2
      web_action_conditionable/__init__.py
  3. 12
      web_action_conditionable/__openerp__.py
  4. 3
      web_action_conditionable/controllers/__init__.py
  5. 16
      web_action_conditionable/controllers/main.py
  6. 2
      web_action_conditionable/readme/CONTRIBUTORS.rst
  7. 3
      web_action_conditionable/readme/CREDITS.rst
  8. 20
      web_action_conditionable/readme/DESCRIPTION.rst
  9. 41
      web_action_conditionable/static/src/js/views.js
  10. 1
      web_action_conditionable/tests/__init__.py
  11. 20
      web_action_conditionable/tests/test_action_conditionable.py

102
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:
<tree delete="false" create="false">
with this module you can:
with this module you can do:
::
<tree delete="state=='draft'">
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:
<tree delete="state=='draft'">
* 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
<tree delete="'base.group_user' in _group_refs">
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 <https://github.com/OCA/web/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 <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**>`_.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`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
=======
Authors
~~~~~~~
* Cristian Salamea
* Onestein
Contributors
------------
~~~~~~~~~~~~
* Cristian Salamea <cristian.salamea@gail.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
* Cristian Salamea <cristian.salamea@gmail.com>
Other credits
~~~~~~~~~~~~~
Maintainer
----------
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
: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 <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.

2
web_action_conditionable/__init__.py

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

12
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,
}

3
web_action_conditionable/controllers/__init__.py

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

16
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

2
web_action_conditionable/readme/CONTRIBUTORS.rst

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

3
web_action_conditionable/readme/CREDITS.rst

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

20
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:
::
<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.

41
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;
}
}
});
}

1
web_action_conditionable/tests/__init__.py

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

20
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)
Loading…
Cancel
Save