From 24e1f6991d28367441a1ccdfc56a6129df7e8a66 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 6 Sep 2012 14:48:16 +0200 Subject: [PATCH] [FIX] o2m breakage introduced in xmo@openerp.com-20120903131744-xfnxpqgn4ixbi7e9 BufferedDataSet#read_ids expect coherent between #cache and #to_create, patch removed a record from #cache which was in #to_create leading to not being able to create new records in editable o2ms: * The record would be inserted in #cache and #to_create * The listview would reload the record - Evicting the record from #cache - And re-reading the record - Leading to breakage Don't evict records locally edited from the cache, the server probably doesn't know about it (at all) or we can assume the server's outdated, so the local version remains the "correct" one and there's nothing more recent to fetch. bzr revid: xmo@openerp.com-20120906124816-8ivtbppm9pixf8w6 --- addons/web/static/src/js/data.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 74b2ec87f01..cbfc4d061f5 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -783,11 +783,19 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ return completion.promise(); }, evict_from_cache: function (id) { + // Don't evict records which haven't yet been saved: there is no more + // recent data on the server (and there potentially isn't any data), + // and this breaks the assumptions of other methods (that the data + // for new and altered records is both in the cache and in the to_write + // or to_create collection) + if (_(this.to_create.concat(this.to_write)).find(function (record) { + return record.id === id; })) { + return; + } + for (var i = 0, len = this.cache.length; i < len; ++i) { var record = this.cache[i]; - // if record we call the button upon is in the cache if (record.id === id) { - // evict it so it gets reloaded from server this.cache.splice(i, 1); break; }