diff --git a/web_pivot_computed_measure/README.rst b/web_pivot_computed_measure/README.rst index f59d8fd1f..f124524fe 100644 --- a/web_pivot_computed_measure/README.rst +++ b/web_pivot_computed_measure/README.rst @@ -14,13 +14,13 @@ Web Pivot Computed Measure :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/12.0/web_pivot_computed_measure + :target: https://github.com/OCA/web/tree/13.0/web_pivot_computed_measure :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_pivot_computed_measure + :target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_pivot_computed_measure :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/12.0 + :target: https://runbot.odoo-community.org/runbot/162/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -72,7 +72,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -91,6 +91,7 @@ Contributors * Alexandre D. Díaz * Pedro M. Baeza + * Ernesto Tejeda Maintainers ~~~~~~~~~~~ @@ -105,6 +106,6 @@ 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. +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_pivot_computed_measure/__manifest__.py b/web_pivot_computed_measure/__manifest__.py index a387e2f58..b347deb0c 100644 --- a/web_pivot_computed_measure/__manifest__.py +++ b/web_pivot_computed_measure/__manifest__.py @@ -4,13 +4,13 @@ { "name": "Web Pivot Computed Measure", "category": "web", - "version": "12.0.1.0.2", - "author": "Tecnativa, " "Odoo Community Association (OCA)", + "version": "13.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/OCA/web", "depends": ["web"], "data": ["view/assets.xml"], - "qweb": ["static/src/xml/web_pivot_computed_measure.xml",], + "qweb": ["static/src/xml/web_pivot_computed_measure.xml"], "auto_install": False, "installable": True, } diff --git a/web_pivot_computed_measure/i18n/es.po b/web_pivot_computed_measure/i18n/es.po index 1eff05478..adb3cded6 100644 --- a/web_pivot_computed_measure/i18n/es.po +++ b/web_pivot_computed_measure/i18n/es.po @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_pivot_computed_measure +# * web_pivot_computed_measure # msgid "" msgstr "" @@ -18,135 +18,137 @@ msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:96 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Add" msgstr "Añadir" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:87 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Can be empty" msgstr "Puede estar vacío" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:47 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Computed Measure" msgstr "Medida computada" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:24 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Custom" msgstr "Customizado" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:18 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Div (m1 / m2)" msgstr "Div (m1 / m2)" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:33 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Float" msgstr "Flotador" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:90 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Format" msgstr "Formato" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:82 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Formula" msgstr "Fórmula" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:30 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Integer" msgstr "Entero" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:56 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Measure 1" msgstr "Medida 1" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:66 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Measure 2" msgstr "Medida 2" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:15 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Mult (m1 * m2)" msgstr "Mult (m1 * m2)" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:86 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Name" msgstr "Nombre" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:76 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Operation" msgstr "Operación" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:21 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Perc (m1 * 100 / m2)" msgstr "Perc (m1 * 100 / m2)" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:36 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Percentage" msgstr "Porcentaje" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:12 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Sub (m1 - m2)" msgstr "Sub (m1 - m2)" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:9 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Sum (m1 + m2)" msgstr "Sum (m1 + m2)" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:275 +#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:0 #, python-format -msgid "This measure is currently used by a 'computed measure'. Please, disable the computed measure first." +msgid "" +"This measure is currently used by a 'computed measure'. Please, disable the " +"computed measure first." msgstr "" "Esta medida está utilizada por una 'medida computada'. Por favor, desabilita " "la medida computada primero." diff --git a/web_pivot_computed_measure/i18n/web_pivot_computed_measure.pot b/web_pivot_computed_measure/i18n/web_pivot_computed_measure.pot index 9feda8589..6700b3276 100644 --- a/web_pivot_computed_measure/i18n/web_pivot_computed_measure.pot +++ b/web_pivot_computed_measure/i18n/web_pivot_computed_measure.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_pivot_computed_measure +# * web_pivot_computed_measure # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -15,134 +15,135 @@ msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:96 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Add" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:87 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Can be empty" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:47 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Computed Measure" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:24 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Custom" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:18 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Div (m1 / m2)" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:33 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Float" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:90 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Format" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:82 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Formula" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:30 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Integer" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:56 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Measure 1" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:66 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Measure 2" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:15 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Mult (m1 * m2)" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:86 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Name" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:76 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Operation" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:21 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Perc (m1 * 100 / m2)" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:36 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Percentage" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:12 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Sub (m1 - m2)" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:9 +#: code:addons/web_pivot_computed_measure/static/src/xml/web_pivot_computed_measure.xml:0 #, python-format msgid "Sum (m1 + m2)" msgstr "" #. module: web_pivot_computed_measure #. openerp-web -#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:275 +#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:0 #, python-format -msgid "This measure is currently used by a 'computed measure'. Please, disable the computed measure first." +msgid "" +"This measure is currently used by a 'computed measure'. Please, disable the " +"computed measure first." msgstr "" - diff --git a/web_pivot_computed_measure/readme/CONTRIBUTORS.rst b/web_pivot_computed_measure/readme/CONTRIBUTORS.rst index 3ce122c7f..ea8b8e058 100644 --- a/web_pivot_computed_measure/readme/CONTRIBUTORS.rst +++ b/web_pivot_computed_measure/readme/CONTRIBUTORS.rst @@ -2,3 +2,4 @@ * Alexandre D. Díaz * Pedro M. Baeza + * Ernesto Tejeda diff --git a/web_pivot_computed_measure/static/description/index.html b/web_pivot_computed_measure/static/description/index.html index 182dd3e28..bf68e1601 100644 --- a/web_pivot_computed_measure/static/description/index.html +++ b/web_pivot_computed_measure/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

Adds support for computed measures on the pivot view.

Table of contents

@@ -439,7 +439,7 @@ can’t be deactivated until you have deactivate the ‘computed measure’.

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.

+feedback.

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

@@ -456,6 +456,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Tecnativa:
    • Alexandre D. Díaz
    • Pedro M. Baeza
    • +
    • Ernesto Tejeda
  • @@ -467,7 +468,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    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.

    +

    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_pivot_computed_measure/static/src/js/pivot_controller.js b/web_pivot_computed_measure/static/src/js/pivot_controller.js index c9ffdb402..4adcbe4f1 100644 --- a/web_pivot_computed_measure/static/src/js/pivot_controller.js +++ b/web_pivot_computed_measure/static/src/js/pivot_controller.js @@ -4,11 +4,11 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { "use strict"; - var core = require("web.core"); - var config = require("web.config"); - var PivotController = require("web.PivotController"); + const core = require("web.core"); + const config = require("web.config"); + const PivotController = require("web.PivotController"); - var QWeb = core.qweb; + const QWeb = core.qweb; PivotController.include({ custom_events: _.extend({}, PivotController.prototype.custom_events, { @@ -24,10 +24,10 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { * * @override */ - getContext: function() { - var res = this._super.apply(this, arguments); - var state = this.model.get(); - res.pivot_computed_measures = state.computed_measures; + getOwnedQueryParams: function() { + const res = this._super.apply(this, arguments); + const state = this.model.get({raw: true}); + res.context.pivot_computed_measures = state.computed_measures; return res; }, @@ -47,9 +47,9 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { * @override */ _onButtonClick: function(event) { - var $target = $(event.target); + const $target = $(event.target); if ($target.parents("div[data-id='__computed__']").length) { - var hideMenu = false; + let hideMenu = false; event.preventDefault(); if ( @@ -60,13 +60,13 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { this._renderComputedMeasures(); } else if ($target.hasClass("o_add_computed_measure")) { hideMenu = true; - var field1 = this.$buttons_measures_ex + const field1 = this.$buttons_measures_ex .find("#computed_measure_field_1") .val(); - var field2 = this.$buttons_measures_ex + const field2 = this.$buttons_measures_ex .find("#computed_measure_field_2") .val(); - var oper = this.$buttons_measures_ex + let oper = this.$buttons_measures_ex .find("#computed_measure_operation") .val(); if (oper === "custom") { @@ -74,13 +74,13 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { .find("#computed_measure_operation_custom") .val(); } - var name = this.$buttons_measures_ex + const name = this.$buttons_measures_ex .find("#computed_measure_name") .val(); - var format = this.$buttons_measures_ex + const format = this.$buttons_measures_ex .find("#computed_measure_format") .val(); - var uniqueId = new Date().getTime(); + const uniqueId = new Date().getTime(); this.model .createComputedMeasure( uniqueId, @@ -105,29 +105,28 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { /** * Render computed measures menu + * + * @private */ _renderComputedMeasures: function() { if (this.$buttons_measures_ex && this.$buttons_measures_ex.length) { this.$buttons_measures_ex.remove(); } - var self = this; - var measures = _.sortBy(_.pairs(_.omit(this.measures, "__count")), function( - x - ) { + const measures = _.sortBy(_.pairs(_.omit(this.measures, "__count")), x => { return x[1].string.toLowerCase(); }); this.$buttons_measures_ex = $( QWeb.render("web_pivot_computed_measure.ExtendedMenu", { isOpen: this.computed_measures_open, - debug: config.debug, + debug: config.isDebug(), measures: measures, computed_measures: _.map( - _.reject(measures, function(item) { + _.reject(measures, item => { return !item[1].__computed_id; }), - function(item) { + item => { item[1].active = _.contains( - self.model.data.measures, + this.model.data.measures, item[0] ); return item; @@ -138,14 +137,16 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { this.$buttons_measures_ex .find("#computed_measure_operation") .on("change", this._onChangeComputedMeasureOperation.bind(this)); - this.$buttons - .find(".o_pivot_measures_list") - .append(this.$buttons_measures_ex); + if (this.$buttons) + this.$buttons + .find(".o_pivot_measures_list") + .append(this.$buttons_measures_ex); }, /** * Custom event to add a new measure * + * @private * @param {CustomEvent} ev */ _onAddMeasure: function(ev) { @@ -156,6 +157,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { /** * Custom event to remove a measure * + * @private * @param {CustomEvent} ev */ _onRemoveMeasure: function(ev) { @@ -166,16 +168,17 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) { /** * Set default values related with the selected operation * + * @private * @param {ChangeEvent} ev */ _onChangeComputedMeasureOperation: function(ev) { - var $option = $(ev.target.options[ev.target.selectedIndex]); + const $option = $(ev.target.options[ev.target.selectedIndex]); if ($(ev.target).val() === "custom") { this.$buttons_measures_ex .find("#container_computed_measure_operation_custom") .removeClass("d-none"); } else { - var format = $option.data("format"); + const format = $option.data("format"); if (format) { this.$buttons_measures_ex .find("#computed_measure_format") diff --git a/web_pivot_computed_measure/static/src/js/pivot_model.js b/web_pivot_computed_measure/static/src/js/pivot_model.js index a9de08c55..315cf3e0e 100644 --- a/web_pivot_computed_measure/static/src/js/pivot_model.js +++ b/web_pivot_computed_measure/static/src/js/pivot_model.js @@ -4,11 +4,10 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { "use strict"; - var core = require("web.core"); - var PivotModel = require("web.PivotModel"); - var ComparisonUtils = require("web.dataComparisonUtils"); + const core = require("web.core"); + const PivotModel = require("web.PivotModel"); - var _t = core._t; + const _t = core._t; PivotModel.include({ _computed_measures: [], @@ -22,9 +21,10 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { * @param {String} operation * @param {String} name * @param {String} format + * @returns a promise */ createComputedMeasure: function(id, field1, field2, operation, name, format) { - var measure = _.find(this._computed_measures, function(item) { + const measure = _.find(this._computed_measures, item => { return ( item.field1 === field1 && item.field2 === field2 && @@ -32,15 +32,13 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { ); }); if (measure) { - return $.Deferred(function(d) { - d.resolve(); - }); + return Promise.resolve(); } - var fieldM1 = this.fields[field1]; - var fieldM2 = this.fields[field2]; - var cmId = "__computed_" + id; - var oper = operation.replace(/m1/g, field1).replace(/m2/g, field2); - var oper_human = operation + const fieldM1 = this.fields[field1]; + const fieldM2 = this.fields[field2]; + const cmId = "__computed_" + id; + const oper = operation.replace(/m1/g, field1).replace(/m2/g, field2); + const oper_human = operation .replace( /m1/g, fieldM1.__computed_id ? "(" + fieldM1.string + ")" : fieldM1.string @@ -49,7 +47,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { /m2/g, fieldM2.__computed_id ? "(" + fieldM2.string + ")" : fieldM2.string ); - var cmTotal = this._computed_measures.push({ + const cmTotal = this._computed_measures.push({ field1: field1, field2: field2, operation: oper, @@ -64,16 +62,21 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { /** * Create and enable a measure based on a 'fake' field * + * @private * @param {Object} cmDef * @param {List} fields *Optional* + * @returns a promise */ _createVirtualMeasure: function(cmDef, fields) { - var arrFields = fields || this.fields; + const arrFields = fields || this.fields; // This is a minimal 'fake' field info arrFields[cmDef.id] = { - type: cmDef.format, // Used to format the value - string: cmDef.name, // Used to print the header name - __computed_id: cmDef.id, // Used to know if is a computed measure field + // Used to format the value + type: cmDef.format, + // Used to print the header name + string: cmDef.name, + // Used to know if is a computed measure field + __computed_id: cmDef.id, }; this.trigger_up("add_measure", { id: cmDef.id, @@ -82,14 +85,13 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { return this._activeMeasures([cmDef.field1, cmDef.field2, cmDef.id]); }, - /** + /* + * @private * @param {List of Strings} fields */ _activeMeasures: function(fields) { - var needLoad = false; - var l = fields.length; - for (var x = 0; x < l; ++x) { - var field = fields[x]; + let needLoad = false; + for (const field of fields) { if (!this._isMeasureEnabled(field)) { this.data.measures.push(field); needLoad = true; @@ -98,12 +100,11 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { if (needLoad) { return this._loadData(); } - return $.Deferred(function(d) { - d.resolve(); - }); + return Promise.resolve(); }, - /** + /* + * @private * @param {String} field */ _isMeasureEnabled: function(field) { @@ -111,81 +112,56 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { }, /** - * Helper function to add computed measure fields data into 'dataPoint' + * Helper function to add computed measure fields data into a 'subGroupData' * - * @param {Object} dataPoint - * @param {Object} dataPointComp + * @private + * @param {Object} subGroupData */ - _fillComputedMeasuresData: function(dataPoint, dataPointComp) { - var self = this; - _.each(this._computed_measures, function(cm) { - if (!self._isMeasureEnabled(cm.id)) { - return; - } - if (dataPointComp) { - var resData = py.eval(cm.operation, dataPointComp.data); - var resComparison = py.eval(cm.operation, dataPointComp.comparison); - dataPoint[cm.id] = { - data: resData, - comparisonData: resComparison, - variation: ComparisonUtils.computeVariation( - resData, - resComparison - ), - }; + _fillComputedMeasuresData: function(subGroupData) { + for (const cm of this._computed_measures) { + if (!this._isMeasureEnabled(cm.id)) return; + if (subGroupData.__count === 0) { + subGroupData[cm.id] = false; } else { - dataPoint[cm.id] = py.eval(cm.operation, dataPoint); + // eslint-disable-next-line no-undef + subGroupData[cm.id] = py.eval(cm.operation, subGroupData); } - }); + } }, /** - * Fill the dataPoints with the computed measures values + * Fill the groupSubdivisions with the computed measures and their values * * @override */ - _mergeData: function(data, comparisonData, groupBys) { - var res = this._super.apply(this, arguments); - var len = groupBys.length; // Cached loop (This is not python! hehe) - for (var index = 0; index < len; ++index) { - if (res.length) { - var len2 = res[index].length; - for (var k = 0; k < len2; ++k) { - var dataPoint = res[index][k]; - if (_.isEmpty(dataPoint)) { - break; - } - if ("__comparisonDomain" in dataPoint) { - // Transform comparison dataPoint object to be compatible - var pairsDataPoint = _.pairs(dataPoint); - var dataPointComp = { - data: _.object( - _.map(pairsDataPoint, item => { - return [item[0], item[1] && item[1].data]; - }) - ), - comparison: _.object( - _.map(pairsDataPoint, item => { - return [ - item[0], - item[1] && item[1].comparisonData, - ]; - }) - ), - }; - // Update datas. Required by computed measures that uses - // other computed measures to work - this._fillComputedMeasuresData(dataPointComp.data); - this._fillComputedMeasuresData(dataPointComp.comparison); - // Update comparison dataPoint - this._fillComputedMeasuresData(dataPoint, dataPointComp); - } else { - // Update standard dataPoint - this._fillComputedMeasuresData(dataPoint); - } - } + _prepareData: function(group, groupSubdivisions) { + for (const groupSubdivision of groupSubdivisions) { + for (const subGroup of groupSubdivision.subGroups) { + this._fillComputedMeasuresData(subGroup); } } + this._super.apply(this, arguments); + }, + + /** + * _getGroupSubdivision method invokes the read_group method of the + * model via rpc and the passed 'fields' argument is the list of + * measure names that is in this.data.measures, so we remove the + * computed measures form this.data.measures before calling _super + * to prevent an exception + * + * @override + */ + _getGroupSubdivision: function() { + const computed_measures = []; + for (let i = 0; i < this.data.measures.length; i++) + if (this.data.measures[i].startsWith("__computed_")) { + computed_measures.push(this.data.measures[i]); + this.data.measures.splice(i, 1); + i--; + } + const res = this._super.apply(this, arguments); + $.merge(this.data.measures, computed_measures); return res; }, @@ -195,15 +171,12 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { * @override */ load: function(params) { - var self = this; this._computed_measures = params.context.pivot_computed_measures || params.computed_measures || []; - var toActive = []; - var l = this._computed_measures.length; - for (var x = 0; x < l; ++x) { - var cmDef = this._computed_measures[x]; + const toActive = []; + for (const cmDef of this._computed_measures) { params.fields[cmDef.id] = { type: cmDef.format, string: cmDef.name, @@ -211,17 +184,16 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { }; toActive.push(cmDef.field1, cmDef.field2, cmDef.id); } - return this._super(params).then(function() { - _.defer(function() { - for (var x = 0; x < l; ++x) { - var cmDef = self._computed_measures[x]; - self.trigger_up("add_measure", { + return this._super(params).then(() => { + _.defer(() => { + for (const cmDef of this._computed_measures) { + this.trigger_up("add_measure", { id: cmDef.id, - def: self.fields[cmDef.id], + def: this.fields[cmDef.id], }); } }); - self._activeMeasures(toActive); + this._activeMeasures(toActive); }); }, @@ -237,24 +209,21 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { params.computed_measures || []; } - var l = this._computed_measures.length; - for (var x = 0; x < l; ++x) { - this._createVirtualMeasure(this._computed_measures[x]); + for (const cmDef of this._computed_measures) { + this._createVirtualMeasure(cmDef); } - // Clean unused 'fake' fields - var fieldNames = Object.keys(this.fields); - for (var x = 0; x < fieldNames.length; ++x) { - var field = this.fields[fieldNames[x]]; + const fieldNames = Object.keys(this.fields); + for (const fieldName of fieldNames) { + const field = this.fields[fieldName]; if (field.__computed_id) { - var cm = _.find(this._computed_measures, {id: field.__computed_id}); + const cm = _.find(this._computed_measures, { + id: field.__computed_id, + }); if (!cm) { - delete this.fields[fieldNames[x]]; - this.data.measures = _.without( - this.data.measures, - fieldNames[x] - ); + delete this.fields[fieldName]; + this.data.measures = _.without(this.data.measures, fieldName); this.trigger_up("remove_measure", { - id: fieldNames[x], + id: fieldName, }); } } @@ -268,7 +237,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { * @override */ get: function() { - var res = this._super.apply(this, arguments); + const res = this._super.apply(this, arguments); res.computed_measures = this._computed_measures; return res; }, @@ -282,31 +251,29 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) { toggleMeasure: function(field) { if (this._isMeasureEnabled(field)) { // Measure is disabled - var umeasures = _.filter(this._computed_measures, function(item) { + const umeasures = _.filter(this._computed_measures, item => { return item.field1 === field || item.field2 === field; }); if (umeasures.length && this._isMeasureEnabled(umeasures[0].id)) { - return $.Deferred(function(d) { - d.reject( - _t( - "This measure is currently used by a 'computed measure'. Please, disable the computed measure first." - ) - ); - }); + return Promise.reject( + _t( + "This measure is currently used by a 'computed measure'. Please, disable the computed measure first." + ) + ); } } else { // Mesaure is enabled - var toEnable = []; - var toAnalize = [field]; + const toEnable = []; + const toAnalize = [field]; while (toAnalize.length) { - var afield = toAnalize.shift(); - var fieldDef = this.fields[afield]; + const afield = toAnalize.shift(); + const fieldDef = this.fields[afield]; if (fieldDef.__computed_id) { - var cm = _.find(this._computed_measures, { + const cm = _.find(this._computed_measures, { id: fieldDef.__computed_id, }); toAnalize.push(cm.field1, cm.field2); - var toEnableFields = []; + const toEnableFields = []; if (!this.fields[cm.field1].__computed_id) { toEnableFields.push(cm.field1); }