Skip to content

Commit 58e22f1

Browse files
tarteoyajo
authored andcommitted
[IMP] web_widget_x2many_2d_matrix: Total of all rows (#1043)
1 parent 9041da7 commit 58e22f1

4 files changed

Lines changed: 32 additions & 4 deletions

File tree

web_widget_x2many_2d_matrix/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Contributors
168168
* Simone Orsi <simone.orsi@camptocamp.com>
169169
* Timon Tschanz <timon.tschanz@camptocamp.com>
170170
* Jairo Llopis <jairo.llopis@tecnativa.com>
171+
* Dennis Sluijk <d.sluijk@onestein.nl>
171172

172173
Maintainer
173174
----------

web_widget_x2many_2d_matrix/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
55
{
66
"name": "2D matrix for x2many fields",
7-
"version": "11.0.1.0.2",
7+
"version": "11.0.1.1.0",
88
"author": "Therp BV, "
99
"Tecnativa, "
1010
"Camptocamp, "
1.72 KB
Loading

web_widget_x2many_2d_matrix/static/src/js/2d_matrix_renderer.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,32 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
304304
_renderFooter: function () {
305305
var $cells = this._renderAggregateColCells();
306306
if ($cells) {
307-
return $('<tfoot>').append(
308-
$('<tr>').append('<td/>').append($cells)
309-
);
307+
var $tr = $('<tr>').append('<td/>').append($cells);
308+
var $total_cell = this._renderTotalCell();
309+
if ($total_cell) {
310+
$tr.append($total_cell);
311+
}
312+
return $('<tfoot>').append($tr);
310313
}
311314
},
312315

316+
/**
317+
* Renders the total cell (of all rows / columns)
318+
*
319+
* @private
320+
* @returns {jQueryElement} The td element with the total in it.
321+
*/
322+
_renderTotalCell: function() {
323+
if (!this.matrix_data.show_column_totals ||
324+
!this.matrix_data.show_row_totals) {
325+
return;
326+
}
327+
328+
var $cell = $('<td>', {class: 'col-total text-right'});
329+
this._apply_aggregate_value($cell, this.total);
330+
return $cell;
331+
},
332+
313333
/**
314334
* Render the Aggregate cells for the column.
315335
*
@@ -346,6 +366,12 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
346366
if (!~['integer', 'float', 'monetary'].indexOf(type)) {
347367
return;
348368
}
369+
this.total = {
370+
fname: fname,
371+
ftype: type,
372+
help: _t('Sum Total'),
373+
value: 0,
374+
};
349375
_.each(this.columns, function (column, index) {
350376
column.aggregate = {
351377
fname: fname,
@@ -361,6 +387,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
361387
// Nothing to do
362388
}
363389
});
390+
this.total.value += column.aggregate.value;
364391
}.bind(this));
365392
},
366393

0 commit comments

Comments
 (0)