[FIX] web: load missing fields when opening form view dialogs

Problem was that sub form field has usually more fields than the list view in
one2many, so we have to load missing fields
This commit is contained in:
Christophe Matthieu
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 454b215389
commit f0cfe7c174
3 changed files with 18 additions and 8 deletions
@@ -68,17 +68,20 @@ return AbstractRenderer.extend({
var field = record.fields[name];
var value = record.data[name];
result[name] = value;
if (field.type === 'many2one') {
if (!value) {
return;
}
else if (field.type === 'many2one') {
result[name] = value.data ? value.data.id || false : false;
}
if (field.type === 'one2many' || field.type === 'many2many') {
else if (field.type === 'one2many' || field.type === 'many2many') {
if (value) {
result[name] = _.pluck(value.data, 'res_id');
} else {
result[name] = [];
}
}
if (field.type === 'boolean') {
else if (field.type === 'boolean') {
// we want an explicit false value, not null if it is unset
result[name] = value || false;
}
@@ -115,7 +115,13 @@ var BasicView = AbstractView.extend({
*/
_loadData: function () {
if (this.recordID) {
return $.when(this.recordID);
var record = this.model.get(this.recordID);
var fieldNames = _.difference(record.fieldNames, Object.keys(record.data));
if (fieldNames.length && !this.model.isNew(record.id)) {
return this.model.reload(this.recordID, {fieldNames: fieldNames});
} else {
return $.when(this.recordID);
}
}
return this._super.apply(this, arguments);
},
@@ -90,9 +90,9 @@ QUnit.module('relational_fields', {
display_name: { string: "Displayed name", type: "char" },
turtle_foo: {string: "Foo", type: "char", default: "My little Foo Value"},
turtle_bar: {string: "Bar", type: "boolean", default: true},
turtle_int: {string: "int", type: "integer", sortable: true, required: true},
turtle_qux: {string: "Qux", type: "float", digits: [16,1], required: true},
turtle_trululu: {string: "Trululu", type: "many2one", relation: 'partner', required: true, default: 1},
turtle_int: {string: "int", type: "integer", sortable: true},
turtle_qux: {string: "Qux", type: "float", digits: [16,1], required: true, default: 1.5},
turtle_trululu: {string: "Trululu", type: "many2one", relation: 'partner'},
product_id: {string: "Product", type: "many2one", relation: 'product', required: true},
},
records: [{
@@ -1677,7 +1677,7 @@ QUnit.module('relational_fields', {
assert.strictEqual(form.$('.o_data_row').length, 3,
"sould have 3 records in one2many list");
assert.strictEqual(form.$('.o_data_row').text(), "blip0.09yop0.0tototo0.050xphone",
assert.strictEqual(form.$('.o_data_row').text(), "blip1.59yop1.5tototo1.550xphone",
"sould display the record values in one2many list");
$('.o_form_button_save').click();
@@ -1705,6 +1705,7 @@ QUnit.module('relational_fields', {
'<field name="turtle_foo"/>' +
'<field name="turtle_bar"/>' +
'<field name="turtle_int"/>' +
'<field name="turtle_trululu"/>' +
'<field name="product_id"/>' +
'</group>' +
'</form>' +