[FIX] web: avoid rendering fields on one2many list validation
This rev. reverts 91911159f5
The above rev. was a good idea, except that internal_set_value expects the raw value, while the records attributes can be tuples(for instance, many2one are tuple(id, name) or list of command(one2many, many2many).
set_value must be use here, as all fields (js) override set_value in order to handle their value repr (for instance, many2one fields handle the tuple (id,name).
Besides, avoiding the re-render provides a huge performance improvment, as rerendering fields can lead to xmlrpc calls (for instance, re-rendering a many2one field implies calling the name_get method)
opw-620111
opw-622108
This commit is contained in:
parent
1e5c68f7a6
commit
38aa984f31
|
@ -3094,7 +3094,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
|
|||
reinit_value: function(val) {
|
||||
this.internal_set_value(val);
|
||||
this.floating = false;
|
||||
if (this.is_started)
|
||||
if (this.is_started && !this.no_rerender)
|
||||
this.render_value();
|
||||
},
|
||||
initialize_field: function() {
|
||||
|
@ -3328,14 +3328,14 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
|
|||
}
|
||||
if (! no_recurse) {
|
||||
var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
|
||||
this.alive(dataset.name_get([self.get("value")])).done(function(data) {
|
||||
this.view.render_value_defs.push(this.alive(dataset.name_get([self.get("value")])).done(function(data) {
|
||||
if (!data[0]) {
|
||||
self.do_warn(_t("Render"), _t("No value found for the field "+self.field.string+" for value "+self.get("value")));
|
||||
return;
|
||||
}
|
||||
self.display_value["" + self.get("value")] = data[0][1];
|
||||
self.render_value(true);
|
||||
});
|
||||
}));
|
||||
}
|
||||
},
|
||||
display_string: function(str) {
|
||||
|
@ -3741,7 +3741,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
|
|||
this.dataset.index = 0;
|
||||
}
|
||||
this.trigger_on_change();
|
||||
if (this.is_started) {
|
||||
if (this.is_started && !this.no_rerender) {
|
||||
return self.reload_current_view();
|
||||
} else {
|
||||
return $.when();
|
||||
|
@ -3888,12 +3888,19 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
|||
return true;
|
||||
}
|
||||
var r;
|
||||
return _.every(this.records.records, function(record){
|
||||
if (_.isEmpty(this.records.records)){
|
||||
return true;
|
||||
}
|
||||
current_values = {};
|
||||
_.each(this.editor.form.fields, function(field){
|
||||
field._inhibit_on_change_flag = true;
|
||||
field.no_rerender = true;
|
||||
current_values[field.name] = field.get('value');
|
||||
});
|
||||
var valid = _.every(this.records.records, function(record){
|
||||
r = record;
|
||||
_.each(self.editor.form.fields, function(field){
|
||||
field._inhibit_on_change_flag = true;
|
||||
field.internal_set_value(r.attributes[field.name]);
|
||||
field._inhibit_on_change_flag = false;
|
||||
field.set_value(r.attributes[field.name]);
|
||||
});
|
||||
return _.every(self.editor.form.fields, function(field){
|
||||
field.process_modifiers();
|
||||
|
@ -3901,6 +3908,12 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
|||
return field.is_valid();
|
||||
});
|
||||
});
|
||||
_.each(this.editor.form.fields, function(field){
|
||||
field.set('value', current_values[field.name]);
|
||||
field._inhibit_on_change_flag = false;
|
||||
field.no_rerender = false;
|
||||
});
|
||||
return valid;
|
||||
},
|
||||
do_add_record: function () {
|
||||
if (this.editable()) {
|
||||
|
|
|
@ -228,8 +228,9 @@ openerp.web.list_editable = function (instance) {
|
|||
this.records.add(record, {
|
||||
at: this.prepends_on_create() ? 0 : null});
|
||||
}
|
||||
|
||||
return this.ensure_saved().then(function () {
|
||||
return this.ensure_saved().then(function(){
|
||||
return $.when.apply(null, self.editor.form.render_value_defs);
|
||||
}).then(function () {
|
||||
var $recordRow = self.groups.get_row_for(record);
|
||||
var cells = self.get_cells_for($recordRow);
|
||||
var fields = {};
|
||||
|
|
Loading…
Reference in New Issue