summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-16 15:02:58 +0200
committerAaron Bohy <aab@odoo.com>2017-05-17 08:10:49 +0200
commit0f9e986c468702ebe55860895ef8d8b84c90a48c (patch)
tree27ed0b34170d26560fd253d5fdbf1330dbd5055e /addons/web
parent5afe894f440eff3b58134d14fa7c9b43b19fe88b (diff)
[FIX] web: BasicModel: discard changes when reloading
... from a new record. Steps to reproduce the issue: - go to a multi-record view (e.g. list) of basically any model - click on 'Create' -> it opens a form view in edit mode - click on 'Discard' -> it goes back to the list - click on an existing record -> it should open the selected record in readonly. However, it didn't display the data of the selected record, but the default data of a new record (the result of a default_get). This was because the changes weren't properly discarded when reloading from a new record (it rather restored the record to its initial state, i.e. to the result of the default_get).
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js4
-rw-r--r--addons/web/static/tests/views/basic_model_tests.js33
2 files changed, 35 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 5e5b36472f5..a55d2b2723b 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -228,7 +228,7 @@ var BasicModel = AbstractModel.extend({
options = options || {};
var element = this.localData[id];
var isNew = this.isNew(id);
- var rollback = options.rollback || isNew;
+ var rollback = 'rollback' in options ? options.rollback : isNew;
this._visitChildren(element, function (elem) {
if (rollback && elem._savePoint) {
if (elem._savePoint instanceof Array) {
@@ -644,7 +644,7 @@ var BasicModel = AbstractModel.extend({
return this._makeDefaultRecord(element.model, params);
}
if (!options.keepChanges) {
- this.discardChanges(id);
+ this.discardChanges(id, {rollback: false});
}
}
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js
index 180d38668c7..5b3b04c3c37 100644
--- a/addons/web/static/tests/views/basic_model_tests.js
+++ b/addons/web/static/tests/views/basic_model_tests.js
@@ -1371,4 +1371,37 @@ QUnit.module('Views', {
model.destroy();
});
+
+ QUnit.test('changes are discarded when reloading from a new record', function (assert) {
+ // practical use case: click on 'Create' to open a form view in edit
+ // mode (new record), click on 'Discard', then open an existing record
+ assert.expect(2);
+
+ this.data.partner.fields.foo.default = 'default';
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ // load a new record (default_get)
+ var params = _.extend(this.params, {
+ res_id: undefined,
+ type: 'record',
+ fieldNames: ['foo'],
+ });
+ model.load(params).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.strictEqual(record.data.foo, 'default',
+ "should be the default value");
+
+ // reload with id 2
+ model.reload(record.id, {currentId: 2}).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.strictEqual(record.data.foo, 'gnap',
+ "should be the value of record 2");
+ });
+ });
+
+ model.destroy();
+ });
});});