From 0f3dbe67442d433a1dcfe4b4e00bbe1d6eac2ce7 Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Mon, 10 Aug 2015 19:22:41 -0500 Subject: [PATCH] Web addon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This module implements condition for actions in tree view. do allows: edit=“false” create=“false” delete=“false” This module allows too: delete=“state==‘draft’”, simple expression. --- web_action_conditionable/__init__.py | 2 ++ web_action_conditionable/__openerp__.py | 14 ++++++++++++ .../static/src/js/views.js | 22 +++++++++++++++++++ web_action_conditionable/views/view.xml | 10 +++++++++ 4 files changed, 48 insertions(+) create mode 100644 web_action_conditionable/__init__.py create mode 100644 web_action_conditionable/__openerp__.py create mode 100644 web_action_conditionable/static/src/js/views.js create mode 100644 web_action_conditionable/views/view.xml 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 @@ + + + + + +