diff --git a/web_action_conditionable/__init__.py b/web_action_conditionable/__init__.py new file mode 100644 index 00000000..633f8661 --- /dev/null +++ b/web_action_conditionable/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- + diff --git a/web_action_conditionable/__openerp__.py b/web_action_conditionable/__openerp__.py new file mode 100644 index 00000000..420d5c6e --- /dev/null +++ b/web_action_conditionable/__openerp__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +{ + "name": 'web_action_conditionable', + "version": "0.1", + "depends": [ + 'base', + 'web', + ], + 'data': ['views/view.xml'], + "author": "Cristian Salamea,Odoo Community Association (OCA)", + "installable": True, + "active": False, +} diff --git a/web_action_conditionable/static/src/js/views.js b/web_action_conditionable/static/src/js/views.js new file mode 100644 index 00000000..9daf279c --- /dev/null +++ b/web_action_conditionable/static/src/js/views.js @@ -0,0 +1,22 @@ +/*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) { + if ($.type(attrs[action]) == 'boolean') { + return JSON.parse(attrs[action]) + } else { + 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; + } + } + }); +} diff --git a/web_action_conditionable/views/view.xml b/web_action_conditionable/views/view.xml new file mode 100644 index 00000000..c1de0b32 --- /dev/null +++ b/web_action_conditionable/views/view.xml @@ -0,0 +1,10 @@ + + + + + +