[FIX] web: context orderedBy not propagated to x2m
Have:
- Model A with a x2m to model B
- Object A with multiple objects B in x2m (that will be sorted)
- On the list view of model A, click on a column to sort by a field
- this field shall not exist in B
- open a record A (towards form view)
Before this commit, the sorting of the x2m crashed, because the key orderedBy was propagated
Due to commit e713ed2a69
After this commit, it doesn't crash
OPW 1913133
closes odoo/odoo#29094
This commit is contained in:
@@ -98,6 +98,7 @@ var AbstractView = Class.extend({
|
||||
modelName: params.modelName,
|
||||
res_id: params.currentId,
|
||||
res_ids: params.ids,
|
||||
orderedBy: params.context ? params.context.orderedBy : [],
|
||||
};
|
||||
if (params.modelName) {
|
||||
this.loadParams.modelName = params.modelName;
|
||||
|
||||
@@ -3332,7 +3332,7 @@ var BasicModel = AbstractModel.extend({
|
||||
model: params.modelName,
|
||||
offset: params.offset || (type === 'record' ? _.indexOf(res_ids, res_id) : 0),
|
||||
openGroupByDefault: params.openGroupByDefault,
|
||||
orderedBy: params.orderedBy || (params.context && params.context.orderedBy) || [],
|
||||
orderedBy: params.orderedBy || [],
|
||||
orderedResIDs: params.orderedResIDs,
|
||||
parentID: params.parentID,
|
||||
rawContext: params.rawContext,
|
||||
|
||||
@@ -2914,6 +2914,41 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many from a model that has been sorted', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
/* On a standard list view, sort your records by a field
|
||||
* Click on a record which contains a x2m with multiple records in it
|
||||
* The x2m shouldn't take the orderedBy of the parent record (the one on the form)
|
||||
*/
|
||||
|
||||
this.data.partner.records[0].turtles = [3, 2];
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form string="Partners">' +
|
||||
'<field name="turtles">' +
|
||||
'<tree>' +
|
||||
'<field name="turtle_foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
context: {
|
||||
orderedBy: [{
|
||||
name: 'foo',
|
||||
asc: false,
|
||||
}]
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_one2many[name=turtles] tbody').text().trim(), "kawablip",
|
||||
'The o2m should not have been sorted.');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('O2M List with pager, decoration and default_order: add and cancel adding', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user