From 2eb1f1bc1770e7e9fd3925d1203a036227fe575b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=C3=ADaz?= Date: Wed, 31 Jul 2019 13:18:44 +0200 Subject: [PATCH] [FIX] web_action_conditionable: Adapt to new api --- web_action_conditionable/README.rst | 100 ++-- .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 2 + web_action_conditionable/readme/USAGE.rst | 13 + .../static/description/index.html | 435 ++++++++++++++++++ .../static/src/js/field_one2many.js | 38 ++ .../static/src/js/views.js | 24 - web_action_conditionable/views/view.xml | 2 +- 8 files changed, 546 insertions(+), 71 deletions(-) create mode 100644 web_action_conditionable/readme/CONTRIBUTORS.rst create mode 100644 web_action_conditionable/readme/DESCRIPTION.rst create mode 100644 web_action_conditionable/readme/USAGE.rst create mode 100644 web_action_conditionable/static/description/index.html create mode 100644 web_action_conditionable/static/src/js/field_one2many.js delete mode 100644 web_action_conditionable/static/src/js/views.js diff --git a/web_action_conditionable/README.rst b/web_action_conditionable/README.rst index 9cee0d8df..506cb2759 100644 --- a/web_action_conditionable/README.rst +++ b/web_action_conditionable/README.rst @@ -1,12 +1,41 @@ -.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - ======================== -Web Action Conditionable +web_action_conditionable ======================== -This module was written to extend the functionality of actions in tree views. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/11.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-11-0/web-11-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/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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: :: @@ -16,70 +45,49 @@ Odoo by default support: with this module you can: :: - - + + 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 -===== - -This module has no direct interface, it only adds functionality for custom views. - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/11.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 - 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 smash it by providing detailed and welcomed feedback. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Cristian Salamea Contributors ------------- +~~~~~~~~~~~~ * Cristian Salamea * André Paramés (https://www.acsone.eu/) +* Alexandre Díaz -Do not contact contributors directly about support or help with technical issues. +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +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 https://odoo-community.org. +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_action_conditionable/readme/CONTRIBUTORS.rst b/web_action_conditionable/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9d55bf157 --- /dev/null +++ b/web_action_conditionable/readme/CONTRIBUTORS.rst @@ -0,0 +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 new file mode 100644 index 000000000..04e080de8 --- /dev/null +++ b/web_action_conditionable/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +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 new file mode 100644 index 000000000..8c56b1651 --- /dev/null +++ b/web_action_conditionable/readme/USAGE.rst @@ -0,0 +1,13 @@ +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 new file mode 100644 index 000000000..1ea87874d --- /dev/null +++ b/web_action_conditionable/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +web_action_conditionable + + + +
+

web_action_conditionable

+ + +

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 view (One2Many fields).

+

Table of contents

+ +
+

Usage

+

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

+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Cristian Salamea
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + 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 494c2fe66..ab53d02af 100644 --- a/web_action_conditionable/views/view.xml +++ b/web_action_conditionable/views/view.xml @@ -2,7 +2,7 @@