[FIX] web: Basic model X2Many commands don't handled correctly
Steps to reproduce: 1. Go to the Accounting / Invoicing apps 2. Open Taxes (Configuration -> Accounting / Invoicing -> Taxes) 3. Try to create a new tax and the client crash. It occurs because the `_processX2ManyCommands()` method doesn't handle correctly a missing `fieldInfo` on some X2Many tags. On mobile, when calling `load_views` the kanban view is used by default. But if the kanban isn't defined, a default kanban view with only the id of the model is used. In the case of the taxes form, the `default_get` retrieved for this form refers to a Many2Many (`tag_ids`) inside a One2Many. But this field isn't present inside the loaded kanban view, so when we process the command defined by the `default_get`, the `field_view` item doesn't exist (because the default kanban loaded only contains the id of the field). Now instead of using an undefined `fieldInfo`, we fall back to an empty object on the missing field to avoid the crash. closes odoo/odoo#40617 X-original-commit: 47a306a31ac6d3c9e68e83b77a80426d5c6ceb05 Signed-off-by: res-odoo <res-odoo@users.noreply.github.com>
This commit is contained in:
committed by
fw-bot
parent
07f70e3c10
commit
3fd2debdc8
@@ -4227,7 +4227,7 @@ var BasicModel = AbstractModel.extend({
|
||||
options = options || {};
|
||||
var defs = [];
|
||||
var field = record.fields[fieldName];
|
||||
var fieldInfo = record.fieldsInfo[options.viewType || record.viewType][fieldName];
|
||||
var fieldInfo = record.fieldsInfo[options.viewType || record.viewType][fieldName] || {};
|
||||
var view = fieldInfo.views && fieldInfo.views[fieldInfo.mode];
|
||||
var fieldsInfo = view ? view.fieldsInfo : fieldInfo.fieldsInfo;
|
||||
var fields = view ? view.fields : fieldInfo.relatedFields;
|
||||
|
||||
@@ -2,9 +2,11 @@ odoo.define('web.basic_model_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
var BasicModel = require('web.BasicModel');
|
||||
var FormView = require('web.FormView');
|
||||
var testUtils = require('web.test_utils');
|
||||
|
||||
var createModel = testUtils.createModel;
|
||||
var createView = testUtils.createView;
|
||||
|
||||
QUnit.module('Views', {
|
||||
beforeEach: function () {
|
||||
@@ -30,7 +32,8 @@ odoo.define('web.basic_model_tests', function (require) {
|
||||
},
|
||||
product: {
|
||||
fields: {
|
||||
name: { string: "Product Name", type: "char" }
|
||||
name: { string: "Product Name", type: "char" },
|
||||
category: { string: "Category M2M", type: 'many2many', relation: 'partner_type' },
|
||||
},
|
||||
records: [
|
||||
{ id: 37, display_name: "xphone" },
|
||||
@@ -62,6 +65,57 @@ odoo.define('web.basic_model_tests', function (require) {
|
||||
}, function () {
|
||||
QUnit.module('BasicModel');
|
||||
|
||||
QUnit.test('can process x2many commands', async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="product_ids"/>
|
||||
</form>
|
||||
`,
|
||||
archs: {
|
||||
'product,false,list': `
|
||||
<tree>
|
||||
<field name="display_name"/>
|
||||
</tree>
|
||||
`,
|
||||
'product,false,kanban': `
|
||||
<kanban>
|
||||
<templates><t t-name="kanban-box">
|
||||
<div><field name="display_name"/></div>
|
||||
</t></templates>
|
||||
</kanban>
|
||||
`,
|
||||
},
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
mockRPC(route, args) {
|
||||
assert.step(args.method);
|
||||
if (args.method === 'default_get' && args.model === 'partner') {
|
||||
return Promise.resolve({
|
||||
product_ids: [
|
||||
[0, 0, {category: []}],
|
||||
]
|
||||
});
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
assert.verifySteps([
|
||||
'load_views',
|
||||
'default_get',
|
||||
]);
|
||||
assert.containsOnce(form, '.o_field_x2many_list', 'should have rendered a x2many list');
|
||||
assert.containsOnce(form, '.o_field_x2many_list_row_add', 'should have rendered a x2many add row on list');
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('can load a record', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user