3
0
Fork 0

[FIX] web_widget_x2many_2d_matrix: Ensure lines order

As objects are unordered collections of properties, we ensure incoming lines order by using lists
15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
Pablo Fuentes 2020-01-28 15:09:01 +01:00 committed by Lois Rilo
parent 79247c53b6
commit 355e491c2c
1 changed files with 13 additions and 7 deletions

View File

@ -34,8 +34,9 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
*/ */
init_params: function () { init_params: function () {
var node = this.attrs; var node = this.attrs;
this.by_x_axis = {};
this.by_y_axis = {}; this.by_y_axis = {};
this.x_axis = [];
this.y_axis = [];
this.field_x_axis = node.field_x_axis || this.field_x_axis; this.field_x_axis = node.field_x_axis || this.field_x_axis;
this.field_y_axis = node.field_y_axis || this.field_y_axis; this.field_y_axis = node.field_y_axis || this.field_y_axis;
this.field_label_x_axis = this.field_label_x_axis =
@ -84,8 +85,9 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
init_matrix: function () { init_matrix: function () {
var records = this.recordData[this.name].data; var records = this.recordData[this.name].data;
// Wipe the content if something still exists // Wipe the content if something still exists
this.by_x_axis = {};
this.by_y_axis = {}; this.by_y_axis = {};
this.x_axis = [];
this.y_axis = [];
_.each(records, function (record) { _.each(records, function (record) {
var x = record.data[this.field_x_axis], var x = record.data[this.field_x_axis],
y = record.data[this.field_y_axis]; y = record.data[this.field_y_axis];
@ -97,18 +99,22 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
// We have a related record // We have a related record
y = y.data.display_name; y = y.data.display_name;
} }
this.by_x_axis[x] = this.by_x_axis[x] || {};
this.by_y_axis[y] = this.by_y_axis[y] || {}; this.by_y_axis[y] = this.by_y_axis[y] || {};
this.by_x_axis[x][y] = record;
this.by_y_axis[y][x] = record; this.by_y_axis[y][x] = record;
if (this.y_axis.indexOf(y) === -1) {
this.y_axis.push(y);
}
if (this.x_axis.indexOf(x) === -1) {
this.x_axis.push(x);
}
}.bind(this)); }.bind(this));
// Init columns // Init columns
this.columns = []; this.columns = [];
$.each(this.by_x_axis, function (x) { _.each(this.x_axis, function (x) {
this.columns.push(this._make_column(x)); this.columns.push(this._make_column(x));
}.bind(this)); }.bind(this));
this.rows = []; this.rows = [];
$.each(this.by_y_axis, function (y) { _.each(this.y_axis, function (y) {
this.rows.push(this._make_row(y)); this.rows.push(this._make_row(y));
}.bind(this)); }.bind(this));
this.matrix_data = { this.matrix_data = {
@ -156,7 +162,7 @@ odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
}, },
'data': [], 'data': [],
}; };
$.each(self.by_x_axis, function (x) { _.each(self.x_axis, function (x) {
row.data.push(self.by_y_axis[y][x]); row.data.push(self.by_y_axis[y][x]);
}); });
return row; return row;