[FIX] web: many2many_checkboxes: react to domain changes

Let's assume a many2many_checkboxes widget in a form view with a
dynamic domain (depending on another field in the view). At first
rendering, the widget contains a checkbox for each value matching
the domain.

Before this rev., if the user changed the value of the field used
in the domain, the many2many_checkboxes wasn't redrawn, so it still
displayed the values matching the previous version of the domain.

Closes #38509
Closes #40173

closes odoo/odoo#42867

X-original-commit: 1ace56f9a8cb56fb39235468dd13447bcbbee40a
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
This commit is contained in:
Carlos Mayo
2020-01-07 14:37:06 +00:00
committed by Aaron Bohy
co-authored by Aaron Bohy
parent c86bff6a02
commit 9f49709ef3
2 changed files with 41 additions and 2 deletions
@@ -2571,17 +2571,27 @@ var FieldMany2ManyCheckBoxes = AbstractField.extend({
/**
* @private
*/
_render: function () {
_renderCheckboxes: function () {
var self = this;
this._super.apply(this, arguments);
this.m2mValues = this.record.specialData[this.name];
this.$el.html(qweb.render(this.template, {widget: this}));
_.each(this.value.res_ids, function (id) {
self.$('input[data-record-id="' + id + '"]').prop('checked', true);
});
},
/**
* @override
* @private
*/
_renderEdit: function () {
this._renderCheckboxes();
},
/**
* @override
* @private
*/
_renderReadonly: function () {
this._renderCheckboxes();
this.$("input").prop("disabled", true);
},
@@ -2314,6 +2314,35 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('widget many2many_checkboxes: values are updated when domain changes', async function (assert) {
assert.expect(5);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `<form>
<field name="int_field"/>
<field name="timmy" widget="many2many_checkboxes" domain="[['id', '>', int_field]]"/>
</form>`,
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '10');
assert.containsN(form, '.o_field_widget[name=timmy] .custom-checkbox', 2);
assert.strictEqual(form.$('.o_field_widget[name=timmy] .o_form_label').text(), 'goldsilver');
await testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 13);
assert.containsOnce(form, '.o_field_widget[name=timmy] .custom-checkbox');
assert.strictEqual(form.$('.o_field_widget[name=timmy] .o_form_label').text(), 'silver');
form.destroy();
});
QUnit.module('FieldMany2ManyBinaryMultiFiles');
QUnit.test('widget many2many_binary', async function (assert) {