[FIX] web,pad: ensure pad content is displayed after discard
Up to this revision, clicking on 'edit' in a record with an existing pad and discarding the changes straight away caused the pad content not to be displayed. The root cause of this issue is twofold: - a hack tricks the model into thinking the pad URL has changed by replacing it with an object yielding the URL when JSONified; - the pad never affects the 'dirtiness' of a record and BasicModel only actually discards changes when the record is dirty. When a user clicks on discard, the model does not actually discard the changes, thereby leaving the web client into thinking the pad URL is the object mentioned above. We fix this issue by requiring that the model always discard changes when clicking 'Discard', regardless of whether the record is dirty. In fact, the lines we changed were no longer correct since the introduction of 'doNotSetDirty' (see https://github.com/odoo/odoo/commit/72ed3a1), as a record could be changed without being dirty. This commit thus also ensures that such records are also properly discarded.
This commit is contained in:
@@ -230,4 +230,37 @@ QUnit.module('pad widget', {
|
||||
delete FieldPad.prototype.isPadConfigured;
|
||||
});
|
||||
|
||||
QUnit.test('record should be discarded properly even if only pad has changed', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'task',
|
||||
data: this.data,
|
||||
arch:'<form>' +
|
||||
'<sheet>' +
|
||||
'<group>' +
|
||||
'<field name="description" widget="pad"/>' +
|
||||
'</group>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
res_id: 2,
|
||||
mockRPC: function (route, args) {
|
||||
if (!args.method) {
|
||||
return $.when(true);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
session: {
|
||||
userName: "batman",
|
||||
},
|
||||
});
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$buttons.find('.o_form_button_cancel').click();
|
||||
assert.strictEqual(form.$('.oe_pad_readonly').text(), this.data.task.pad_get_content(),
|
||||
"pad content should not have changed");
|
||||
form.destroy();
|
||||
delete FieldPad.prototype.isPadConfigured;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -329,9 +329,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
|
||||
if (options && options.readonlyIfRealDiscard && !needDiscard) {
|
||||
return;
|
||||
}
|
||||
if (needDiscard) { // Just some optimization
|
||||
self.model.discardChanges(recordID);
|
||||
}
|
||||
self.model.discardChanges(recordID);
|
||||
if (self.model.isNew(recordID)) {
|
||||
self._abandonRecord(recordID);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user