[FIX] web: save should not re-read fields if none were changed
Previously, it used to reload its data when the user clicked multiple times on save, even though there were only changed fields during the first initial save, all the other queued ones have no changes at all and, as such, should not trigger additional reloads.
This commit is contained in:
@@ -388,18 +388,19 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
|
||||
// Note: it is the model's job to do nothing if there is nothing to save
|
||||
if (this.canBeSaved(recordID)) {
|
||||
var self = this;
|
||||
var def = this.model.save(recordID, { // Save then leave edit mode
|
||||
var saveDef = this.model.save(recordID, { // Save then leave edit mode
|
||||
reload: options.reload,
|
||||
savePoint: options.savePoint,
|
||||
});
|
||||
if (!options.stayInEdit) {
|
||||
def = def.then(function (fieldNames) {
|
||||
return self._confirmSave(recordID).then(function () {
|
||||
saveDef = saveDef.then(function (fieldNames) {
|
||||
var def = fieldNames.length ? self._confirmSave(recordID) : self._setMode('readonly');
|
||||
return def.then(function () {
|
||||
return fieldNames;
|
||||
});
|
||||
});
|
||||
}
|
||||
return def;
|
||||
return saveDef;
|
||||
} else {
|
||||
return $.Deferred().reject(); // Cannot be saved
|
||||
}
|
||||
|
||||
@@ -4529,5 +4529,51 @@ QUnit.module('Views', {
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('multiple clicks on save should reload only once', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var def = $.Deferred();
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<group>' +
|
||||
'<field name="foo"/>' +
|
||||
'</group>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
mockRPC: function (route, args) {
|
||||
var result = this._super.apply(this, arguments);
|
||||
assert.step(args.method);
|
||||
if (args.method === "write") {
|
||||
return def.then(function () {
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$('input[name="foo"]').val("test").trigger("input");
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
|
||||
def.resolve();
|
||||
|
||||
assert.verifySteps([
|
||||
'read', // initial read to render the view
|
||||
'write', // write on save
|
||||
'read' // read on reload
|
||||
]);
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user