[FIX] web: grouped list with <groupby> node and onchange

Let's assume an editable grouped list view with a <groupby>
node containing subfields, and an onchange. Edit a row to trigger
the onchange. Before this rev., it crashed because the onchange
specs was incorrect: it followed the relation of the many2one
and thus included its subfields (whereas it should only follow the
relation for x2many fields).

For example, go to Accounting > Accounting > Sales and edit the
label of a move line.

Task 2044187

closes odoo/odoo#36001

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
Aaron Bohy
2019-08-23 11:08:27 +00:00
parent edc710f758
commit 6602e1cf2d
2 changed files with 41 additions and 3 deletions
@@ -2001,9 +2001,11 @@ var BasicModel = AbstractModel.extend({
if (field.onChange) {
hasOnchange = true;
}
_.each(fieldInfo.views, function (view) {
generateSpecs(view.fieldsInfo[view.type], view.fields, key + '.');
});
if (field.type === 'one2many' || field.type === 'many2many') {
_.each(fieldInfo.views, function (view) {
generateSpecs(view.fieldsInfo[view.type], view.fields, key + '.');
});
}
});
}
return hasOnchange ? specs : false;
@@ -2251,6 +2251,42 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('groupby node with subfields, and onchange', async function (assert) {
assert.expect(1);
this.data.foo.onchanges = {
foo: function () {},
};
const list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: `<tree editable="bottom" expand="1">
<field name="foo"/>
<field name="currency_id"/>
<groupby name="currency_id">
<field name="position" invisible="1"/>
</groupby>
</tree>`,
groupBy: ['currency_id'],
mockRPC: function (route, args) {
if (args.method === 'onchange') {
assert.deepEqual(args.args[3], {
foo: "1",
currency_id: "",
}, 'onchange spec should not follow relation of many2one fields');
}
return this._super.apply(this, arguments);
},
});
await testUtils.dom.click(list.$('.o_data_row:first .o_data_cell:first'));
await testUtils.fields.editInput(list.$('.o_field_widget[name=foo]'), "new value");
list.destroy();
});
QUnit.test('list view, editable, without data', async function (assert) {
assert.expect(12);