[FIX] web: reload right record when editing a many2one inside an x2many
Before this revision, editing a many2one inside an x2many field did not cause an update of the x2many field upon saving. This is due to the fact that a field on a screen was deemed affected by a record change only if its value or a directly related record has been updated. This present revision looks for changes recursively, thereby including the case where an x2many field contains a many2one. The bug appeared for example in Manufacturing, when editing the product name of a BOM line.
This commit is contained in:
@@ -217,7 +217,7 @@ var FormController = BasicController.extend({
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @override method from field manager mixin
|
* @override method from field manager mixin
|
||||||
* @param {string} id
|
* @param {string} id - id of the previously changed record
|
||||||
* @returns {Deferred}
|
* @returns {Deferred}
|
||||||
*/
|
*/
|
||||||
_confirmSave: function (id) {
|
_confirmSave: function (id) {
|
||||||
@@ -228,15 +228,21 @@ var FormController = BasicController.extend({
|
|||||||
return this._setMode('readonly');
|
return this._setMode('readonly');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// a subrecord changed, so update the corresponding relational field
|
// A subrecord has changed, so update the corresponding relational field
|
||||||
// i.e. the one whose value is a record with the given id or a list
|
// i.e. the one whose value is a record with the given id or a list
|
||||||
// having a record with the given id in its data
|
// having a record with the given id in its data
|
||||||
var record = this.model.get(this.handle);
|
var record = this.model.get(this.handle);
|
||||||
var fieldsChanged = _.findKey(record.data, function (d) {
|
|
||||||
return _.isObject(d) &&
|
// Callback function which returns true
|
||||||
(d.id === id || _.findWhere(d.data, {id: id}));
|
// if a value recursively contains a record with the given id.
|
||||||
});
|
// This will be used to determine the list of fields to reload.
|
||||||
return this.renderer.confirmChange(record, record.id, [fieldsChanged]);
|
var containsChangedRecord = function (value) {
|
||||||
|
return _.isObject(value) &&
|
||||||
|
(value.id === id || _.find(value.data, containsChangedRecord));
|
||||||
|
};
|
||||||
|
|
||||||
|
var changedFields = _.findKey(record.data, containsChangedRecord);
|
||||||
|
return this.renderer.confirmChange(record, record.id, [changedFields]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1418,6 +1418,58 @@ QUnit.module('relational_fields', {
|
|||||||
form.destroy();
|
form.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('updating a many2one from a many2many', function (assert) {
|
||||||
|
assert.expect(4);
|
||||||
|
|
||||||
|
this.data.turtle.records[1].turtle_trululu = 1;
|
||||||
|
|
||||||
|
var form = createView({
|
||||||
|
View: FormView,
|
||||||
|
model: 'partner',
|
||||||
|
data: this.data,
|
||||||
|
arch: '<form string="Partners">' +
|
||||||
|
'<group>' +
|
||||||
|
'<field name="turtles">' +
|
||||||
|
'<tree editable="bottom">' +
|
||||||
|
'<field name="display_name"/>' +
|
||||||
|
'<field name="turtle_trululu"/>' +
|
||||||
|
'</tree>' +
|
||||||
|
'</field>' +
|
||||||
|
'</group>' +
|
||||||
|
'</form>',
|
||||||
|
res_id: 1,
|
||||||
|
archs: {
|
||||||
|
'partner,false,form': '<form string="Trululu"><field name="display_name"/></form>',
|
||||||
|
},
|
||||||
|
mockRPC: function (route, args) {
|
||||||
|
if (args.method === 'get_formview_id') {
|
||||||
|
assert.deepEqual(args.args[0], [1], "should call get_formview_id with correct id");
|
||||||
|
return $.when(false);
|
||||||
|
}
|
||||||
|
return this._super(route, args);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Opening the modal
|
||||||
|
form.$buttons.find('.o_form_button_edit').click();
|
||||||
|
form.$('.o_data_row td:contains(first record)').click();
|
||||||
|
form.$('.o_external_button').click();
|
||||||
|
assert.strictEqual($('.modal').length, 1,
|
||||||
|
"should have one modal in body");
|
||||||
|
|
||||||
|
// Changing the 'trululu' value
|
||||||
|
$('.modal input[name="display_name"]').val('test').trigger('input');
|
||||||
|
$('.modal button.btn-primary').click();
|
||||||
|
|
||||||
|
// Test whether the value has changed
|
||||||
|
assert.strictEqual($('.modal').length, 0,
|
||||||
|
"the modal should be closed");
|
||||||
|
assert.equal(form.$('.o_data_cell:contains(test)').text(), 'test',
|
||||||
|
"the partner name should have been updated to 'test'");
|
||||||
|
|
||||||
|
form.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.module('FieldOne2Many');
|
QUnit.module('FieldOne2Many');
|
||||||
|
|
||||||
QUnit.test('one2many basic properties', function (assert) {
|
QUnit.test('one2many basic properties', function (assert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user