3
0
Fork 0

[ADD] detect if used field type can be aggregated

fixes #1365
13.0
Holger Brunn 2019-09-15 05:58:52 +02:00 committed by Adrià Gil Sorribes
parent 5a593d1452
commit da4c0b0e10
1 changed files with 24 additions and 4 deletions

View File

@ -56,10 +56,23 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
node[property];
}
}
this.show_row_totals =
this.parse_boolean(node.show_row_totals || '1');
this.show_column_totals =
this.parse_boolean(node.show_column_totals || '1');
var field_defs = this.recordData[this.name].fields;
// TODO: raise when any of the fields above don't exist with a
// helpful error message
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;
},
/**
* 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.
*