summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2019-07-10 12:49:19 +0000
committerAaron Bohy <aab@odoo.com>2019-07-11 10:43:42 +0000
commitcea3f51e2f5cfdf44c657237e664ef397a0aa35f (patch)
tree62a0d8b04ba6c7e08f518b602e9cab6b44581148 /addons/web/static/tests/fields
parent646ccfc5304af697b27f4fc308fbd12ee81a4947 (diff)
[FIX] web: batch read of m2m in o2m after onchange
Let's assume a one2many field (editable list) in a form view with a many2many (e.g. many2many_tags), and an onchange on the one2many such that, when a row is added to the relation, the server returns update commands for (a subset of) the records being already in the relation. For thoses updated records, the many2many field needs to be read (the onchange only returns the ids in the relation). Before this rev., the many2many field was read independently for each record in the one2many. This could cause a performance issue on large relations. For instance, this was the case on account.invoice records with a lot of lines. Issue 2027356 closes odoo/odoo#34785 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/tests/fields')
-rw-r--r--addons/web/static/tests/fields/relational_fields/field_one2many_tests.js52
1 files changed, 51 insertions, 1 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
index 4eb02b0c380..f39a5f714a1 100644
--- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
+++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
@@ -2,7 +2,6 @@ odoo.define('web.field_one_to_many_tests', function (require) {
"use strict";
var AbstractField = require('web.AbstractField');
-var concurrency = require('web.concurrency');
var FormView = require('web.FormView');
var KanbanRecord = require('web.KanbanRecord');
var ListRenderer = require('web.ListRenderer');
@@ -8344,6 +8343,57 @@ QUnit.module('fields', {}, function () {
form.destroy();
});
+
+ QUnit.test('many2manys inside a one2many are fetched in batch after onchange', async function (assert) {
+ assert.expect(7);
+
+ this.data.partner.onchanges = {
+ turtles: function (obj) {
+ obj.turtles = [
+ [5],
+ [1, 1, {
+ turtle_foo: "leonardo",
+ partner_ids: [[4, 2]],
+ }],
+ [1, 2, {
+ turtle_foo: "donatello",
+ partner_ids: [[4, 2], [4, 4]],
+ }],
+ ];
+ },
+ };
+
+ var form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="turtles">' +
+ '<tree editable="bottom">' +
+ '<field name="turtle_foo"/>' +
+ '<field name="partner_ids" widget="many2many_tags"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ enableBasicModelBachedRPCs: true,
+ mockRPC: function (route, args) {
+ assert.step(args.method || route);
+ if (args.method === 'read') {
+ assert.deepEqual(args.args[0], [2, 4],
+ 'should read the partner_ids once, batched');
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ assert.containsN(form, '.o_data_row', 2);
+ assert.strictEqual(form.$('.o_field_widget[name="partner_ids"]').text().replace(/\s/g, ''),
+ "secondrecordsecondrecordaaa");
+
+ assert.verifySteps(['default_get', 'onchange', 'read']);
+
+ form.destroy();
+ });
});
});
});