From 1ea609ba651c070d1d90c3321a210a2346de17ea Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 7 Jun 2013 17:23:26 +0200 Subject: [PATCH] [FIX] bugs discovered by failing onwrite test case Following xmo@openerp.com-20130607120355-x3poxy2ar2bpqqvw: * add_ids should not add ids which are already in the dataset, this leads to duplicates which the web client does not overly like * methods which add or remove records should not manipulate dataset.ids as well as that's now automatic (on_write feature) * record add should only insert the id in the dataset on non-false ids (e.g. list edition uses "pending" record with false id during creation, then sets the id it got from create() call) bzr revid: xmo@openerp.com-20130607152326-2pja1kuwo0ropfuw --- addons/web/static/src/js/data.js | 2 +- addons/web/static/src/js/view_list.js | 9 ++------- addons/web/static/src/js/view_list_editable.js | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 5884336dcfe..679afe77bcd 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -626,7 +626,7 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, this.alter_ids(_(this.ids).difference(ids)); }, add_ids: function(ids, at) { - var args = [at, 0].concat(ids); + var args = [at, 0].concat(_.difference(ids, this.ids)); this.ids.splice.apply(this.ids, args); }, /** diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 60c3acad107..9d09316f618 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -906,12 +906,7 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web. throw new Error(_.str.sprintf( _t("Setting 'id' attribute on existing record %s"), JSON.stringify(record.attributes) )); } - if (!_.contains(self.dataset.ids, value)) { - // add record to dataset if not already in (added by - // the form view?) - self.dataset.ids.splice( - self.records.indexOf(record), 0, value); - } + self.dataset.add_ids([value], self.records.indexOf(record)); // Set id on new record $row = self.$current.children('[data-id=false]'); } else { @@ -923,7 +918,7 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web. 'add': function (ev, records, record, index) { var $new_row = $(self.render_record(record)); var id = record.get('id'); - self.dataset.add_ids([id], index); + if (id) { self.dataset.add_ids([id], index); } if (index === 0) { $new_row.prependTo(self.$current); diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 4e042b60c5d..512fc4ff373 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -429,7 +429,6 @@ openerp.web.list_editable = function (instance) { var index = this.records.indexOf(source_record) + 1; record = this.make_empty_record(id); this.records.add(record, {at: index}); - this.dataset.ids.splice(index, 0, id); } return this.reload_record(record); },