Fix default value of one2many in form view
- set_default should correctly pipe promises because One2Many.set_default can be not synchronous. - set previous group parent only if it is not empty because Screen create a default not linked group. - Screen.display should set current_record is not correctly set. issue5135 review19791002
This commit is contained in:
1 parent
1c65b5f750
commit
5cf8093d32
2 files changed
+33
-22
No files matched your search
+22
-21
@@ -802,6 +802,7 @@
|
||||
return dfd;
|
||||
},
|
||||
set_default: function(values) {
|
||||
var promises = [];
|
||||
var fieldnames = [];
|
||||
for (var fname in values) {
|
||||
if (!values.hasOwnProperty(fname)) {
|
||||
@@ -820,16 +821,21 @@
|
||||
delete this._values[field_rec_name];
|
||||
}
|
||||
}
|
||||
this.model.fields[fname].set_default(this, value);
|
||||
promises.push(this.model.fields[fname].set_default(this, value));
|
||||
this._loaded[fname] = true;
|
||||
fieldnames.push(fname);
|
||||
}
|
||||
this.on_change(fieldnames);
|
||||
this.on_change_with(fieldnames);
|
||||
this.validate(null, true).then(function() {
|
||||
this.group.root_group().screens.forEach(function(screen) {
|
||||
screen.display();
|
||||
});
|
||||
return jQuery.when.apply(promises).then(function() {
|
||||
return this.on_change(fieldnames).then(function() {
|
||||
return this.on_change_with(fieldnames).then(function() {
|
||||
return this.validate(null, true).then(function() {
|
||||
return this.group.root_group().screens
|
||||
.forEach(function(screen) {
|
||||
return screen.display();
|
||||
});
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
get_timestamp: function() {
|
||||
@@ -1739,17 +1745,14 @@
|
||||
if ((mode == 'list values') && !jQuery.isEmptyObject(value)) {
|
||||
var context = this.get_context(record);
|
||||
var field_names = {};
|
||||
for (var val in value) {
|
||||
if (!value.hasOwnProperty(val)) {
|
||||
continue;
|
||||
}
|
||||
value.forEach(function(val) {
|
||||
for (var fieldname in val) {
|
||||
if (!val.hasOwnProperty(fieldname)) {
|
||||
continue;
|
||||
}
|
||||
field_names[fieldname] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!jQuery.isEmptyObject(field_names)) {
|
||||
var args = {
|
||||
'method': 'model.' + this.description.relation +
|
||||
@@ -1760,6 +1763,7 @@
|
||||
}
|
||||
}
|
||||
var set_value = function(fields) {
|
||||
var promises = [];
|
||||
if (!jQuery.isEmptyObject(fields)) {
|
||||
group.model.add_fields(fields);
|
||||
}
|
||||
@@ -1771,22 +1775,20 @@
|
||||
}
|
||||
group.load(value);
|
||||
} else {
|
||||
for (var vals in value) {
|
||||
if (!value.hasOwnProperty(vals)) {
|
||||
continue;
|
||||
}
|
||||
value.forEach(function(vals) {
|
||||
var new_record = group.new_(false);
|
||||
if (default_) {
|
||||
new_record.set_default(vals);
|
||||
promises.push(new_record.set_default(vals));
|
||||
group.add(new_record);
|
||||
} else {
|
||||
new_record.set(vals);
|
||||
group.push(new_record);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return jQuery.when.apply(promises);
|
||||
};
|
||||
return prm.pipe(set_value.bind(this));
|
||||
return prm.then(set_value);
|
||||
},
|
||||
set: function(record, value, _default) {
|
||||
if (_default === undefined) {
|
||||
@@ -1902,9 +1904,8 @@
|
||||
return record._values[this.name];
|
||||
},
|
||||
set_default: function(record, value) {
|
||||
var previous_group = record._values[this.name];
|
||||
this.set(record, value, true);
|
||||
record._changed[this.name] = true;
|
||||
return this.set(record, value, true);
|
||||
},
|
||||
set_on_change: function(record, value) {
|
||||
record._changed[this.name] = true;
|
||||
|
||||
+11
-1
@@ -767,7 +767,9 @@
|
||||
group.on_write = group.on_write.filter(function(e, i, a) {
|
||||
return i == a.indexOf(e);
|
||||
});
|
||||
group.parent = this.group.parent;
|
||||
if (this.group.parent) {
|
||||
group.parent = this.group.parent;
|
||||
}
|
||||
}
|
||||
group.screens.push(this);
|
||||
this.tree_states_done = [];
|
||||
@@ -802,6 +804,14 @@
|
||||
},
|
||||
display: function(set_cursor) {
|
||||
var deferreds = [];
|
||||
if (this.current_record &&
|
||||
~this.current_record.group.indexOf(this.current_record)) {
|
||||
} else if (!jQuery.isEmptyObject(this.group) &&
|
||||
(this.current_view.view_type != 'calendar')) {
|
||||
this.current_record = this.group[0];
|
||||
} else {
|
||||
this.current_record = null;
|
||||
}
|
||||
if (this.views) {
|
||||
var search_prm = this.search_active(
|
||||
~['tree', 'graph', 'calendar'].indexOf(
|
||||
|
||||
Reference in new issue
Block a user