summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-31 16:26:50 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit21324ded09883d08ec951b0e3cc80ff5ed270aed (patch)
treecddd8f60c4ccd79e5072ae722d4896a531c9f66c /addons/web/static/src/js
parent28e1620731604410216239fee70a7b1cbfd3b7ae (diff)
[FIX] web: do not create new line if onchange has warning in o2m
In a one2many field, when the user clicks on the 'Add a line' button, we need to create a new record. This means that we call the default_get route, then call the onchanges. The onchange can return a 'warning' key, which is displayed to the user. But in the specific case of a one2many, we don't want to actually create the record. So, we reject the deferred to prevent that from happening.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js8
1 files changed, 7 insertions, 1 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 f93635618e3..9139906f982 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -770,6 +770,7 @@ var BasicModel = AbstractModel.extend({
var onchangeDef;
if (onChangeFields.length) {
onchangeDef = self._applyOnChange(record, onChangeFields).then(function (result) {
+ delete record._warning;
return _.keys(changes).concat(Object.keys(result && result.value || {}));
});
} else {
@@ -884,6 +885,7 @@ var BasicModel = AbstractModel.extend({
title: result.warning.title,
type: 'dialog',
});
+ record._warning = true;
}
var defs = [];
_.each(result.value, function (val, name) {
@@ -2045,7 +2047,11 @@ var BasicModel = AbstractModel.extend({
}
}
if (shouldApplyOnchange) {
- return self._applyOnChange(record, fields_key);
+ return self._applyOnChange(record, fields_key).then(function () {
+ if (record._warning) {
+ return $.Deferred().reject();
+ }
+ });
} else {
return $.when();
}