[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
This commit is contained in:
Xavier Morel 2013-06-07 17:23:26 +02:00
parent aa423f4cb1
commit 1ea609ba65
3 changed files with 3 additions and 9 deletions

View File

@ -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);
},
/**

View File

@ -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);

View File

@ -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);
},