summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-02-13 16:49:43 +0100
committerAlexandre Kühn <aku@odoo.com>2018-02-16 11:17:36 +0100
commitb09f0c99be2b13d33986414485556d87da186d65 (patch)
tree295fc8ab252cdd47b14365f5f1b3296480b0b8f4 /addons/web/static/src/js/views/basic/basic_model.js
parent4f418c26d50634b21b7cc936b5f6aca8ca6f5d1b (diff)
[FIX] web: discard new record with empty required field
Before this commit, there is an issue with one2many lists with records that have been created on 'default_get': if the record has a required field that is empty, when the user clicks on this empty required field and then somewhere else, the record is removed from the list. The cause of this bug is that these records have invalid field changes, here the required field that is empty. As a consequence, it checks whether the record is "new", and if so, removes it visually from the editable list. (Note: a record is "new" when it is not stored in DB). This behaviour is expected when discarding records created from "Add an item". However, that is not intended for records that have been created as default items of the list. These records are still considered as "new" items, because they are not stored in DB, but they should stay in the list on discard. This commit solves the issue by making an additional check before assuming that the record for which we discard changes comes from "Add an item": if the record in the list has been created before user interacts on the list (in other words, the record has been added in the list when the user accesses it), then we should not remove the record from the list, even though the record has some invalid fields from the savepoint (e.g. empty required). opw-806650
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js24
1 files changed, 24 insertions, 0 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 b5b668a43a1..68fcd05fab1 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -478,6 +478,30 @@ var BasicModel = AbstractModel.extend({
return _t("New");
},
/**
+ * Returns true if a record can be abandoned from a list datapoint.
+ *
+ * A record cannot be abandonned if it has been registered as "added"
+ * in the parent's savepoint, otherwise it can be abandonned.
+ *
+ * This is useful when discarding changes on this record, as it means that
+ * we must keep the record even if some fields are invalids (e.g. required
+ * field is empty).
+ *
+ * @param {string} id id for a local resource
+ * @returns {boolean}
+ */
+ canBeAbandoned: function (id) {
+ var data = this.localData[id];
+ var parent = this.localData[data.parentID];
+ var abandonable = true;
+ if (parent) {
+ abandonable = !_.some(parent._savePoint, function (entry) {
+ return entry.operation === 'ADD' && entry.id === id;
+ });
+ }
+ return abandonable;
+ },
+ /**
* Returns true if a record is dirty. A record is considered dirty if it has
* some unsaved changes, marked by the _isDirty property on the record or
* one of its subrecords.