From a82480c38528fdd440a434141fcda7af3a73c406 Mon Sep 17 00:00:00 2001 From: Vincent Hatakeyama Date: Wed, 22 May 2019 16:23:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20option=20to=20set=20a=20label?= =?UTF-8?q?=20for=20total=20column?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_widget_x2many_2d_matrix/README.rst | 3 +++ web_widget_x2many_2d_matrix/__manifest__.py | 2 +- .../static/src/js/2d_matrix_renderer.js | 19 +++++++++++++++++-- .../static/src/js/widget_x2many_2d_matrix.js | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index e9d10d2a..89003c73 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -67,6 +67,9 @@ field_value show_row_totals If field_value is a numeric field, it indicates if you want to calculate row totals. True by default +label_row_totals + If show_row_totals is True, this will allow to set a column label for the + totals column. Default to ''. show_column_totals If field_value is a numeric field, it indicates if you want to calculate column totals. True by default diff --git a/web_widget_x2many_2d_matrix/__manifest__.py b/web_widget_x2many_2d_matrix/__manifest__.py index 0c86417e..a760235f 100644 --- a/web_widget_x2many_2d_matrix/__manifest__.py +++ b/web_widget_x2many_2d_matrix/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "2D matrix for x2many fields", - "version": "11.0.1.1.2", + "version": "11.0.1.1.3", "author": "Therp BV, " "Tecnativa, " "Camptocamp, " diff --git a/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js b/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js index 2b567950..5bb85007 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js +++ b/web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js @@ -111,10 +111,25 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ this.columns, this._renderHeaderCell.bind(this) )); + $tr.append(this._renderHeaderSpecial()); + return $('').append($tr); + }, + + /** + * Render the special headers of our matrix, like totals + * + * @private + * @returns {jQueryElement} a list of elements + */ + _renderHeaderSpecial: function () { + var ths = []; if (this.matrix_data.show_row_totals) { - $tr.append($('', {class: 'total'})); + var $th = $('', {class: 'total text-right'}); + // label_row_totals contains either something or '' + $th.append(this.matrix_data.label_row_totals).append(''); + ths.push($th); } - return $('').append($tr); + return ths; }, /** diff --git a/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js b/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js index addf7cd4..6b196945 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js +++ b/web_widget_x2many_2d_matrix/static/src/js/widget_x2many_2d_matrix.js @@ -61,6 +61,7 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) { node.field_editability || this.field_editability; this.show_row_totals = this.parse_boolean(node.show_row_totals || '1'); + this.label_row_totals = node.label_row_totals || ''; this.show_column_totals = this.parse_boolean(node.show_column_totals || '1'); }, @@ -108,6 +109,7 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) { 'columns': this.columns, 'rows': this.rows, 'show_row_totals': this.show_row_totals, + 'label_row_totals': this.label_row_totals, 'show_column_totals': this.show_column_totals, }; },