summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/data.js
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2011-09-26 18:00:57 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2011-09-26 18:00:57 +0200
commit78cdb8d1ab6081a7c9ce3bb63ff1560e67270918 (patch)
tree48e526d581f0c5d2ef56fc80d4f70baea4efafbe /addons/web/static/src/js/data.js
parent0962e5b9193099e2760928a3ff5fe3440ec8d264 (diff)
[fix] problem in o2m form view with read only fields, now saves result of default_get
bzr revid: nicolas.vanhoren@openerp.com-20110926160057-zss7934ji5hhtq44
Diffstat (limited to 'addons/web/static/src/js/data.js')
-rw-r--r--addons/web/static/src/js/data.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js
index e5d323c8a96..00281628e75 100644
--- a/addons/web/static/src/js/data.js
+++ b/addons/web/static/src/js/data.js
@@ -608,15 +608,23 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
init: function() {
this._super.apply(this, arguments);
this.reset_ids([]);
+ this.last_default_get = {};
+ },
+ default_get: function(fields, callback) {
+ return this._super(fields).then(this.on_default_get).then(callback);
+ },
+ on_default_get: function(res) {
+ this.last_default_get = res;
},
create: function(data, callback, error_callback) {
- var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data};
+ var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data,
+ defaults: this.last_default_get};
this.to_create.push(cached);
this.cache.push(cached);
this.on_change();
- var to_return = $.Deferred().then(callback);
- to_return.resolve({result: cached.id});
- return to_return.promise();
+ var prom = $.Deferred().then(callback);
+ setTimeout(function() {prom.resolve({result: cached.id});}, 0);
+ return prom.promise();
},
write: function (id, data, options, callback) {
var self = this;
@@ -676,7 +684,8 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
var cached = _.detect(self.cache, function(x) {return x.id === id;});
var created = _.detect(self.to_create, function(x) {return x.id === id;});
if (created) {
- _.each(fields, function(x) {if (cached.values[x] === undefined) cached.values[x] = false;});
+ _.each(fields, function(x) {if (cached.values[x] === undefined)
+ cached.values[x] = created.defaults[x] || false;});
} else {
if (!cached || !_.all(fields, function(x) {return cached.values[x] !== undefined}))
to_get.push(id);
@@ -716,6 +725,10 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
}
});
openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({
+ default_get: function(fields, callback) {
+ return this._super(fields, callback).then(this.on_default_get);
+ },
+ on_default_get: function(result) {},
create: function(data, callback, error_callback) {
this.on_create(data);
var to_return = $.Deferred().then(callback);