diff --git a/web_action_conditionable/README.rst b/web_action_conditionable/README.rst index 56b9c46a2..5428e3497 100644 --- a/web_action_conditionable/README.rst +++ b/web_action_conditionable/README.rst @@ -25,7 +25,17 @@ web_action_conditionable |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 view (One2Many fields). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + Odoo by default support: :: @@ -36,20 +46,10 @@ with this module you can: :: - + It works in any tree view, so you can use it in One2many. -**Table of contents** - -.. contents:: - :local: - -Usage -===== - -This module has no direct interface, it only adds functionality for custom views. - Bug Tracker =========== @@ -73,6 +73,7 @@ Contributors * Cristian Salamea * André Paramés (https://www.acsone.eu/) +* Alexandre Díaz Maintainers ~~~~~~~~~~~ diff --git a/web_action_conditionable/readme/CONTRIBUTORS.rst b/web_action_conditionable/readme/CONTRIBUTORS.rst index 3a1f62984..9d55bf157 100644 --- a/web_action_conditionable/readme/CONTRIBUTORS.rst +++ b/web_action_conditionable/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Cristian Salamea * André Paramés (https://www.acsone.eu/) +* Alexandre Díaz diff --git a/web_action_conditionable/readme/DESCRIPTION.rst b/web_action_conditionable/readme/DESCRIPTION.rst index a1a3d40ea..04e080de8 100644 --- a/web_action_conditionable/readme/DESCRIPTION.rst +++ b/web_action_conditionable/readme/DESCRIPTION.rst @@ -1,14 +1,2 @@ -This module was written to extend the functionality of actions in tree views. -Odoo by default support: - -:: - - - -with this module you can: - -:: - - - -It works in any tree view, so you can use it in One2many. +This module was written to extend the functionality of actions in +tree view (One2Many fields). diff --git a/web_action_conditionable/readme/USAGE.rst b/web_action_conditionable/readme/USAGE.rst index a51878174..8c56b1651 100644 --- a/web_action_conditionable/readme/USAGE.rst +++ b/web_action_conditionable/readme/USAGE.rst @@ -1 +1,13 @@ -This module has no direct interface, it only adds functionality for custom views. +Odoo by default support: + +:: + + + +with this module you can: + +:: + + + +It works in any tree view, so you can use it in One2many. diff --git a/web_action_conditionable/static/description/index.html b/web_action_conditionable/static/description/index.html index eaf0d7d67..be6dbc57e 100644 --- a/web_action_conditionable/static/description/index.html +++ b/web_action_conditionable/static/description/index.html @@ -368,16 +368,8 @@ ul.auto-toc { !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

-

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:

-
-<tree delete="state=='draft'">
-
-

It works in any tree view, so you can use it in One2many.

+

This module was written to extend the functionality of actions in +tree view (One2Many fields).

Table of contents

    @@ -393,7 +385,15 @@ Odoo by default support:

Usage

-

This module has no direct interface, it only adds functionality for custom views.

+

Odoo by default support:

+
+<tree delete="false" create="false">
+
+

with this module you can:

+
+<tree delete="state=='draft'" create="state!='sent'">
+
+

It works in any tree view, so you can use it in One2many.

Bug Tracker

@@ -416,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
diff --git a/web_action_conditionable/static/src/js/field_one2many.js b/web_action_conditionable/static/src/js/field_one2many.js new file mode 100644 index 000000000..72b033a74 --- /dev/null +++ b/web_action_conditionable/static/src/js/field_one2many.js @@ -0,0 +1,38 @@ +/* global py */ +/* Copyright 2019 Alexandre Díaz + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ +odoo.define('web.web_action_conditionable', function (require) { + "use strict"; + + var FieldOne2Many = require('web.relational_fields').FieldOne2Many; + + FieldOne2Many.include({ + init: function () { + var self = this; + try { + return this._super.apply(this, arguments); + } catch (error) { + var arch = this.view && this.view.arch; + if (arch) { + ['create', 'delete'].forEach(function (item) { + if (!_.has(arch.attrs, item)) { + return; + } + var expr = arch.attrs[item]; + try { + self.activeActions[item] = py.evaluate( + py.parse(py.tokenize(expr)), + self.recordData).toJSON(); + } catch (ignored) { + // Do nothing + } + }); + this.editable = arch.attrs.editable; + } + if (this.attrs.columnInvisibleFields) { + this._processColumnInvisibleFields(); + } + } + }, + }); +}); diff --git a/web_action_conditionable/static/src/js/views.js b/web_action_conditionable/static/src/js/views.js deleted file mode 100644 index af0a3494a..000000000 --- a/web_action_conditionable/static/src/js/views.js +++ /dev/null @@ -1,24 +0,0 @@ -odoo.define('web.web_action_conditionable', function (require) { - "use strict"; - - var View = require('web.View'); - - 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; - } - } - }); -}); diff --git a/web_action_conditionable/views/view.xml b/web_action_conditionable/views/view.xml index 2cfb0e2ee..ab53d02af 100644 --- a/web_action_conditionable/views/view.xml +++ b/web_action_conditionable/views/view.xml @@ -2,7 +2,7 @@