3
0
Fork 0

[ADD] detect if used field type can be aggregated

fixes #1365
16.0
Holger Brunn 2019-09-15 05:58:52 +02:00 committed by tarteo
parent 0a7d6e52a9
commit f1e30a0090
2 changed files with 25 additions and 5 deletions

View File

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': '2D matrix for x2many fields', 'name': '2D matrix for x2many fields',
'version': '12.0.1.0.4', 'version': '12.0.1.1.0',
'author': ( 'author': (
'Therp BV, ' 'Therp BV, '
'Tecnativa, ' 'Tecnativa, '

View File

@ -56,10 +56,23 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
node[property]; node[property];
} }
} }
this.show_row_totals = var field_defs = this.recordData[this.name].fields;
this.parse_boolean(node.show_row_totals || '1'); // TODO: raise when any of the fields above don't exist with a
this.show_column_totals = // helpful error message
this.parse_boolean(node.show_column_totals || '1'); if (!field_defs[this.field_value]) {
throw new Error(_.str.sprintf(
'You need to include %s in your view definition',
this.field_value
));
}
this.show_row_totals = this.parse_boolean(
node.show_row_totals ||
this.is_aggregatable(field_defs[this.field_value]) ? '1' : ''
);
this.show_column_totals = this.parse_boolean(
node.show_column_totals ||
this.is_aggregatable(field_defs[this.field_value]) ? '1' : ''
);
}, },
/** /**
@ -149,6 +162,13 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
return row; return row;
}, },
/**
* Determine if a field represented by field_def can be aggregated
*/
is_aggregatable: function (field_def) {
return field_def.type in {float: 1, monetary: 1, integer: 1};
},
/** /**
* Parse a String containing a bool and convert it to a JS bool. * Parse a String containing a bool and convert it to a JS bool.
* *