summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-06-13 15:18:27 +0200
committerAaron Bohy <aab@odoo.com>2017-06-14 10:15:37 +0200
commita3bea9a62bdaf205c0a9cd75945f6f6e9b023d6d (patch)
tree568a0596438b3c96e2492d3fb870a8691ca74702 /addons/web/static/src
parent70624772b2dd6a885a9cc8578e0e451063e18ad4 (diff)
[FIX] web: Form: delete the correct record
When the user duplicated a record 'A', and deleted the new record 'A (copy)' directly, the wrong record was deleted: 'A' was deleted instead of 'A (copy)', because de id of 'A' was bound to the delete handler, and it wasn't updated after the duplication. Also correctly updates the record's offset after the deletion, so that it doesn't produce a warning when deleting the last record of the dataset.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js1
-rw-r--r--addons/web/static/src/js/views/form/form_controller.js10
2 files changed, 10 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 6c23550ba2e..ae48a98dd13 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -208,6 +208,7 @@ var BasicModel = AbstractModel.extend({
delete self.localData[record.id];
} else {
record.res_ids.splice(record.offset, 1);
+ record.offset = Math.min(record.offset, record.res_ids.length - 1);
record.res_id = record.res_ids[record.offset];
record.count--;
}
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js
index d22a4095d1a..8a42168a098 100644
--- a/addons/web/static/src/js/views/form/form_controller.js
+++ b/addons/web/static/src/js/views/form/form_controller.js
@@ -151,7 +151,7 @@ var FormController = BasicController.extend({
if (this.is_action_enabled('delete')) {
otherItems.push({
label: _t('Delete'),
- callback: this._deleteRecords.bind(this, [this.handle]),
+ callback: this._onDeleteRecord.bind(this),
});
}
if (this.is_action_enabled('create') && this.is_action_enabled('duplicate')) {
@@ -395,6 +395,14 @@ var FormController = BasicController.extend({
this.createRecord();
},
/**
+ * Deletes the current record
+ *
+ * @private
+ */
+ _onDeleteRecord: function () {
+ this._deleteRecords([this.handle]);
+ },
+ /**
* Called when the user wants to discard the changes made to the current
* record -> @see discardChanges
*