Skip to content
Permalink
Browse files

fixup! [IMP] web, base: put buttons in list group headers

  • Loading branch information...
aab-odoo committed Mar 21, 2019
1 parent f61ff78 commit e70b84cff31adb717b30d6742b5371f0d6f2b78f
Showing with 63 additions and 29 deletions.
  1. +21 −18 addons/web/static/src/js/views/list/list_model.js
  2. +42 −11 addons/web/static/tests/views/list_tests.js
@@ -119,31 +119,34 @@ odoo.define('web.ListModel', function (require) {
return groupIds;
}, []);
var groupFields = Object.keys(this.groups[groupByFieldName].viewFields);
var prom;
if (groupIds.length && groupFields.length) {
return this._rpc({
prom = this._rpc({
model: groupedByField.relation,
method: 'read',
args: [groupIds, groupFields],
context: list.context,
}).then(function (result) {
_.each(list.data, function (id) {
var dp = self.localData[id];
var groupData = _.findWhere(result, { id: dp.res_id });
var fvg = self.groups[groupByFieldName];
dp.groupData = self._makeDataPoint({
context: dp.context,
data: groupData,
fields: fvg.fields,
fieldsInfo: fvg.fieldsInfo,
modelName: fvg.model,
parentID: dp.id,
res_id: dp.res_id,
viewType: dp.viewType,
});
});
});
}
return Promise.resolve();
return Promise.resolve(prom).then(function (result) {
var fvg = self.groups[groupByFieldName];
_.each(list.data, function (id) {
var dp = self.localData[id];
var groupData = result && _.findWhere(result, {
id: dp.res_id,
});
dp.groupData = self._makeDataPoint({
context: dp.context,
data: groupData,
fields: fvg.fields,
fieldsInfo: fvg.fieldsInfo,
modelName: groupedByField.relation,
parentID: dp.id,
res_id: dp.res_id,
viewType: 'groupby',
});
});
});
},
});
return ListModel;
@@ -1720,8 +1720,8 @@ QUnit.module('Views', {
list.destroy();
});

QUnit.test('support groupby node', async function (assert) {
assert.expect(19);
QUnit.test('groupby node with a button', async function (assert) {
assert.expect(13);

var list = await createView({
View: ListView,
@@ -1730,20 +1730,16 @@ QUnit.module('Views', {
arch: '<tree>' +
'<field name="foo"/>' +
'<groupby name="currency_id">' +
'<field name="position"/>' +
'<button string="Button 1" type="object" name="button_method" attrs=\'{"invisible": [("position", "=", "after")]}\'/>' +
'<button string="Button 1" type="object" name="button_method"/>' +
'</groupby>' +
'</tree>',
mockRPC: function (route, args) {
assert.step(args.method || route);
if (args.method === 'read' && args.model === 'res_currency') {
assert.deepEqual(args.args, [[2, 1], ['position']]);
}
return this._super.apply(this, arguments);
},
intercepts: {
execute_action: function (ev) {
assert.deepEqual(ev.data.env.currentID, 1,
assert.deepEqual(ev.data.env.currentID, 2,
'should call with correct id');
assert.strictEqual(ev.data.env.model, 'res_currency',
'should call with correct model');
@@ -1760,26 +1756,61 @@ QUnit.module('Views', {

await list.update({groupBy: ['currency_id']});

assert.verifySteps(['/web/dataset/read_group', 'read']);
assert.verifySteps(['/web/dataset/read_group']);
assert.containsN(list, '.o_group_header', 2,
"there should be 2 group headers");
assert.containsNone(list, '.o_group_header button', 0,
"there should be no button in the header");

await testUtils.dom.click(list.$('.o_group_header:eq(0)'));
assert.verifySteps(['/web/dataset/search_read']);
assert.containsOnce(list, '.o_group_header button');

await testUtils.dom.click(list.$('.o_group_header:eq(0) button'));

list.destroy();
});

QUnit.test('groupby node with a button with modifiers', async function (assert) {
assert.expect(11);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree>' +
'<field name="foo"/>' +
'<groupby name="currency_id">' +
'<field name="position"/>' +
'<button string="Button 1" type="object" name="button_method" attrs=\'{"invisible": [("position", "=", "after")]}\'/>' +
'</groupby>' +
'</tree>',
mockRPC: function (route, args) {
assert.step(args.method || route);
if (args.method === 'read' && args.model === 'res_currency') {
assert.deepEqual(args.args, [[2, 1], ['position']]);
}
return this._super.apply(this, arguments);
},
groupBy: ['currency_id'],
});

assert.verifySteps(['/web/dataset/read_group', 'read']);

await testUtils.dom.click(list.$('.o_group_header:eq(0)'));

assert.verifySteps(['/web/dataset/search_read']);
assert.containsOnce(list, '.o_group_header button.o_invisible_modifier',
"the first group (EUR) should have an invisible button");

await testUtils.dom.click(list.$('.o_group_header:eq(1)'));

assert.verifySteps(['/web/dataset/search_read']);
assert.containsN(list, '.o_group_header button', 2,
"there should be two buttons (one by header)");
assert.doesNotHaveClass(list, '.o_group_header:eq(1) button', 'o_invisible_modifier',
"the second header button should be visible");

await testUtils.dom.click(list.$('.o_group_header:eq(1) button'));

list.destroy();
});

0 comments on commit e70b84c

Please sign in to comment.
You can’t perform that action at this time.