From 0f3dbe67442d433a1dcfe4b4e00bbe1d6eac2ce7 Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Mon, 10 Aug 2015 19:22:41 -0500 Subject: [PATCH 1/6] 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 @@ + + + + + + From d416afbf62bf21019f11a2d15eb4d1ead6b48dbe Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Tue, 11 Aug 2015 07:45:02 -0500 Subject: [PATCH 2/6] Add Readme removed active key. --- web_action_conditionable/README.rst | 77 +++++++++++++++++++++++++ web_action_conditionable/__openerp__.py | 1 - 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 web_action_conditionable/README.rst diff --git a/web_action_conditionable/README.rst b/web_action_conditionable/README.rst new file mode 100644 index 00000000..d198a800 --- /dev/null +++ b/web_action_conditionable/README.rst @@ -0,0 +1,77 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Web Action Conditionable +======================== + +This module was written to extend the functionality of actions in tree views. +Odoo by default support delete="false" create="false", with this module you can: +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 +============= + +No 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 + +Known issues / Roadmap +====================== + +* ... + +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 `_. + + +Credits +======= + +Contributors +------------ + +* Cristian Salamea + +Maintainer +---------- + +.. 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. diff --git a/web_action_conditionable/__openerp__.py b/web_action_conditionable/__openerp__.py index 420d5c6e..5f4793c5 100644 --- a/web_action_conditionable/__openerp__.py +++ b/web_action_conditionable/__openerp__.py @@ -10,5 +10,4 @@ 'data': ['views/view.xml'], "author": "Cristian Salamea,Odoo Community Association (OCA)", "installable": True, - "active": False, } From 476ea597f287c6784a5cb3b0c8d3dc424df19102 Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Tue, 11 Aug 2015 09:02:00 -0500 Subject: [PATCH 3/6] Better description --- web_action_conditionable/README.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web_action_conditionable/README.rst b/web_action_conditionable/README.rst index d198a800..4ed2152b 100644 --- a/web_action_conditionable/README.rst +++ b/web_action_conditionable/README.rst @@ -5,11 +5,21 @@ Web Action Conditionable ======================== This module was written to extend the functionality of actions in tree views. -Odoo by default support delete="false" create="false", with this module you can: -delete="state=='draft'". +Odoo by default support: + +:: + + + +with this module you can: + +:: + + It works in any tree view, so you can use it in One2many. + Installation ============ @@ -19,7 +29,7 @@ To install this module, just follow basic steps to install an odoo module. Configuration ============= -No needed. +Not needed. Usage ===== From c8887fd2f92d10ba5c202668f37cbefd89c88c1c Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Tue, 11 Aug 2015 10:42:13 -0500 Subject: [PATCH 4/6] FIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testing in all cases is better catch errno in JSON.parse. attrs[action] is always “string” type. --- web_action_conditionable/static/src/js/views.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web_action_conditionable/static/src/js/views.js b/web_action_conditionable/static/src/js/views.js index 9daf279c..c9713913 100644 --- a/web_action_conditionable/static/src/js/views.js +++ b/web_action_conditionable/static/src/js/views.js @@ -5,9 +5,10 @@ openerp.web_action_conditionable = function (instance) { 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 { + try { + data = JSON.parse(attrs[action]); + return data; + } catch(error) { var expr = attrs[action]; var expression = py.parse(py.tokenize(expr)); var cxt = this.dataset.get_context().__eval_context.__contexts[1]; From 76822f22ee47927b6641efd35ec2c99b8c289ab6 Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Tue, 11 Aug 2015 10:45:50 -0500 Subject: [PATCH 5/6] Fix flake fail --- web_action_conditionable/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/web_action_conditionable/__init__.py b/web_action_conditionable/__init__.py index 633f8661..40a96afc 100644 --- a/web_action_conditionable/__init__.py +++ b/web_action_conditionable/__init__.py @@ -1,2 +1 @@ # -*- coding: utf-8 -*- - From 64551293c5728f6dbf1ebe18b0d9101b2f7e148c Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Mon, 17 Aug 2015 18:25:24 -0500 Subject: [PATCH 6/6] Use super to allow better future hacking --- web_action_conditionable/static/src/js/views.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web_action_conditionable/static/src/js/views.js b/web_action_conditionable/static/src/js/views.js index c9713913..5eeb6c4a 100644 --- a/web_action_conditionable/static/src/js/views.js +++ b/web_action_conditionable/static/src/js/views.js @@ -6,8 +6,7 @@ openerp.web_action_conditionable = function (instance) { var attrs = this.fields_view.arch.attrs; if (action in attrs) { try { - data = JSON.parse(attrs[action]); - return data; + return this._super(action); } catch(error) { var expr = attrs[action]; var expression = py.parse(py.tokenize(expr));