[FIX] web: list: re-evalute modifiers depending on id

In an editable (main) list view with modifiers depending on the
record id, add a new record. While the record isn't created yet,
the modifiers were correctly evaluated. However, they weren't
re-evaluted when the record was saved (thus getting an id), and a
reload of the view was necessary for the modifiers to be correctly
applied. With this rev. they are now correctly re-evaluated when
the record is saved.

closes odoo/odoo#32483

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
This commit is contained in:
Aaron Bohy
2019-04-08 11:32:18 +00:00
parent 8d34eb1328
commit 7d31b863ca
2 changed files with 53 additions and 0 deletions
@@ -428,6 +428,18 @@ ListRenderer.include({
});
}
},
/**
* @override
*/
updateState: function (state, params) {
if (params.noRender) {
// the state changed, but we won't do a re-rendering right now, so
// remove computed modifiers data (as they are obsolete) to force
// them to be recomputed at next (sub-)rendering
this.allModifiersData = [];
}
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Private
@@ -4153,6 +4153,47 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('create record on list with modifiers depending on id', function (assert) {
assert.expect(8);
var list = createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top">' +
'<field name="id" invisible="1"/>' +
'<field name="foo" attrs="{\'readonly\': [[\'id\',\'!=\',False]]}"/>' +
'<field name="int_field" attrs="{\'invisible\': [[\'id\',\'!=\',False]]}"/>' +
'</tree>',
});
// add a new record
testUtils.dom.click(list.$buttons.find('.o_list_button_add'));
// modifiers should be evaluted to false
assert.containsOnce(list, '.o_selected_row');
assert.doesNotHaveClass(list.$('.o_selected_row .o_data_cell:first'), 'o_readonly_modifier');
assert.doesNotHaveClass(list.$('.o_selected_row .o_data_cell:nth(1)'), 'o_invisible_modifier');
// set a value and save
testUtils.fields.editInput(list.$('.o_selected_row input[name=foo]'), 'some value');
testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
// modifiers should be evaluted to true
assert.hasClass(list.$('.o_data_row:first .o_data_cell:first'), 'o_readonly_modifier');
assert.hasClass(list.$('.o_data_row:first .o_data_cell:nth(1)'), 'o_invisible_modifier');
// edit again the just created record
testUtils.dom.click(list.$('.o_data_row:first .o_data_cell:first'));
// modifiers should be evaluted to true
assert.containsOnce(list, '.o_selected_row');
assert.hasClass(list.$('.o_selected_row .o_data_cell:first'), 'o_readonly_modifier');
assert.hasClass(list.$('.o_selected_row .o_data_cell:nth(1)'), 'o_invisible_modifier');
list.destroy();
});
});
});