[FIX] web: re-evaluate column_invisible after onchange
Let's assume a form view with field A and B (a one2many list), with a column with attrs column_invisible depending on A. If the user sets A manually, everything works fine (the column is hidden/shown directly). However, if A is updated by an onchange (e.g. depending on the number of rows in B), it doesn't. This rev. fixes that issue. Related to Issue: 1851451 Co-authored-by: Priyanka Kaakdiya <pka@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Priyanka Kaakdiya
parent
60cdd13eb3
commit
006c31b955
@@ -981,6 +981,13 @@ var FieldX2Many = AbstractField.extend({
|
||||
}
|
||||
return def.then(function () {
|
||||
self.pager.updateState({ size: self.value.count });
|
||||
var newEval = self._evalColumnInvisibleFields();
|
||||
if (!_.isEqual(self.currentColInvisibleFields, newEval)) {
|
||||
self.currentColInvisibleFields = newEval;
|
||||
self.renderer.updateState(self.value, {
|
||||
columnInvisibleFields: self.currentColInvisibleFields,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -12812,6 +12812,53 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many column visiblity depends on onchange of parent field', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.records[0].p = [2];
|
||||
this.data.partner.records[0].bar = false;
|
||||
|
||||
this.data.partner.onchanges.p = function (obj) {
|
||||
// set bar to true when line is added
|
||||
if (obj.p.length > 1 && obj.p[1][2].foo === 'New line') {
|
||||
obj.bar = true;
|
||||
}
|
||||
};
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form>' +
|
||||
'<field name="bar"/>' +
|
||||
'<field name="p">' +
|
||||
'<tree editable="bottom">' +
|
||||
'<field name="foo"/>' +
|
||||
'<field name="int_field" attrs="{\'column_invisible\': [(\'parent.bar\', \'=\', False)]}"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
// bar is false so there should be 1 column
|
||||
assert.strictEqual(form.$('th').length, 1,
|
||||
"should be only 1 column ('foo') in the one2many");
|
||||
assert.strictEqual(form.$('.o_list_view .o_data_row').length, 1, "should contain one row");
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
|
||||
// add a new o2m record
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
form.$('.o_field_one2many input:first').focus();
|
||||
form.$('.o_field_one2many input:first').val('New line').trigger('input');
|
||||
form.$el.click(); // click outside to save a line
|
||||
|
||||
assert.strictEqual(form.$('th').length, 2, "should be 2 columns('foo' + 'int_field')");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many column_invisible on view not inline', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user