[MERGE] forward port branch 11.0 up to bb6f6c57f9
This commit is contained in:
@@ -2096,6 +2096,18 @@ var FieldProgressBar = AbstractField.extend({
|
||||
this.$('.o_progressbar_value').focus().select();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* The progress bar has more than one field/value to deal with
|
||||
* i.e. max_value
|
||||
*
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_reset: function () {
|
||||
this._super.apply(this, arguments);
|
||||
var new_max_value = this.recordData[this.nodeOptions.max_value];
|
||||
this.max_value = new_max_value !== undefined ? new_max_value : this.max_value;
|
||||
},
|
||||
isSet: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -468,6 +468,7 @@ var FieldMany2One = AbstractField.extend({
|
||||
initial_ids: ids ? _.map(ids, function (x) { return x[0]; }) : undefined,
|
||||
initial_view: view,
|
||||
disable_multiple_selection: true,
|
||||
no_create: !self.can_create,
|
||||
on_selected: function (records) {
|
||||
self.reinitialize(records[0]);
|
||||
self.activate();
|
||||
|
||||
@@ -141,6 +141,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;
|
||||
|
||||
@@ -3365,7 +3365,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,
|
||||
@@ -4279,7 +4279,7 @@ var BasicModel = AbstractModel.extend({
|
||||
if (orderData1 > orderData2) {
|
||||
return order.asc ? 1 : -1;
|
||||
}
|
||||
return compareRecords(record1ID, record2ID, level + 1);
|
||||
return compareRecords(resId1, resId2, level + 1);
|
||||
};
|
||||
utils.stableSort(list.res_ids, compareRecords);
|
||||
}
|
||||
|
||||
@@ -4888,6 +4888,48 @@ QUnit.module('basic_fields', {
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldProgressBar');
|
||||
|
||||
QUnit.test('Field ProgressBar: max_value should update', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data.partner.records = this.data.partner.records.slice(0,1);
|
||||
this.data.partner.records[0].qux = 2;
|
||||
|
||||
this.data.partner.onchanges = {
|
||||
display_name: function (obj) {
|
||||
obj.int_field = 999;
|
||||
obj.qux = 5;
|
||||
}
|
||||
};
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<field name="display_name" />' +
|
||||
'<field name="qux" invisible="1" />' +
|
||||
'<field name="int_field" widget="progressbar" options="{\'current_value\': \'int_field\', \'max_value\': \'qux\'}" />' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_progressbar_value').text(), '10 / 2',
|
||||
'The initial value of the progress bar should be correct');
|
||||
|
||||
// trigger the onchange
|
||||
form.$('.o_input[name=display_name]').val('new name').trigger('input');
|
||||
|
||||
assert.strictEqual(form.$('.o_progressbar_value').text(), '999 / 5',
|
||||
'The value of the progress bar should be correct after the update');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2733,6 +2733,48 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('x2many default_order multiple fields', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
this.data.partner.records = [
|
||||
{int_field: 10, id: 1, display_name: "record1"},
|
||||
{int_field: 12, id: 2, display_name: "record2"},
|
||||
{int_field: 11, id: 3, display_name: "record3"},
|
||||
{int_field: 12, id: 4, display_name: "record4"},
|
||||
{int_field: 10, id: 5, display_name: "record5"},
|
||||
{int_field: 10, id: 6, display_name: "record6"},
|
||||
{int_field: 11, id: 7, display_name: "record7"},
|
||||
];
|
||||
|
||||
this.data.partner.records[0].p = [1, 7, 4, 5, 2, 6, 3];
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<field name="p" >' +
|
||||
'<tree default_order="int_field,id">' +
|
||||
'<field name="id"/>' +
|
||||
'<field name="int_field"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
var $recordList = form.$('.o_field_x2many_list .o_data_row');
|
||||
var expectedOrderId = ['1', '5', '6', '3', '7', '2', '4'];
|
||||
|
||||
_.each($recordList, function(record, index) {
|
||||
var $record = $(record);
|
||||
assert.strictEqual($record.find('.o_data_cell').eq(0).text(), expectedOrderId[index],
|
||||
'The record should be the right place. Index: ' + index);
|
||||
});
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('many2many list add *many* records, remove, re-add', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
@@ -2873,6 +2915,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);
|
||||
|
||||
|
||||
@@ -476,6 +476,66 @@ QUnit.module('Views', {
|
||||
testUtils.unpatch(ListController);
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('propagate can_create onto the search popup o2m', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.instrument.records = [
|
||||
{id: 1, name: 'Tromblon1'},
|
||||
{id: 2, name: 'Tromblon2'},
|
||||
{id: 3, name: 'Tromblon3'},
|
||||
{id: 4, name: 'Tromblon4'},
|
||||
{id: 5, name: 'Tromblon5'},
|
||||
{id: 6, name: 'Tromblon6'},
|
||||
{id: 7, name: 'Tromblon7'},
|
||||
{id: 8, name: 'Tromblon8'},
|
||||
];
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<field name="name"/>' +
|
||||
'<field name="instrument" can_create="false"/>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
archs: {
|
||||
'instrument,false,list': '<tree>'+
|
||||
'<field name="name"/>'+
|
||||
'</tree>',
|
||||
'instrument,false,search': '<search>'+
|
||||
'<field name="name"/>'+
|
||||
'</search>',
|
||||
},
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
|
||||
mockRPC: function(route, args) {
|
||||
if (args.method === 'get_formview_id') {
|
||||
return $.when(false);
|
||||
}
|
||||
return this._super(route, args);
|
||||
},
|
||||
});
|
||||
|
||||
form.$('.o_field_widget[name="instrument"] .o_input').click();
|
||||
|
||||
assert.notOk($('.ui-autocomplete a:contains(Create and Edit)').length,
|
||||
'Create and edit not present in dropdown');
|
||||
|
||||
$('.ui-autocomplete a:contains(Search More)').trigger('mouseenter').trigger('click');
|
||||
|
||||
var $modal = $('.modal-dialog.modal-lg');
|
||||
|
||||
assert.strictEqual($modal.length, 1, 'Modal present');
|
||||
|
||||
assert.strictEqual($modal.find('.modal-footer button').text(), "Cancel",
|
||||
'Only the cancel button is present in modal');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user