[FIX] web: list_editable in FieldOne2Many: onSuccess at the right time
When changing a value for a o2m (list) within a form, the _setValue returned a Promise that did not take into account the real rendering of the list renderer. The use case at hand is: - enable product configurator - have a product with options - add that product in a SO - add the option as well through the product configurator - confirm the configurator The configurator triggers an add_record event, with an onSuccess callback Before this commit, the onSuccess callback was called too early, when the previous rendering operations were not finished yet. After this commit, the onSuccess is executed when the list renderer is really ready opw-2580044 closes odoo/odoo#79591 X-original-commit: 8def0d103020aed4211fd22f2b917567fb06de1e Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
committed by
Hubert Van de Walle (huvw)
parent
c6c41f359e
commit
5df6a6efd7
@@ -2001,7 +2001,7 @@ var FieldOne2Many = FieldX2Many.extend({
|
||||
index = self.value.data.length - 1;
|
||||
}
|
||||
var newID = self.value.data[index].id;
|
||||
self.renderer.editRecord(newID);
|
||||
return self.renderer.editRecord(newID);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -330,7 +330,7 @@ ListRenderer.include({
|
||||
editRecord: function (recordID) {
|
||||
var $row = this._getRow(recordID);
|
||||
var rowIndex = $row.prop('rowIndex') - 1;
|
||||
this._selectCell(rowIndex, 0);
|
||||
return this._selectCell(rowIndex, 0);
|
||||
},
|
||||
/**
|
||||
* Gives focus to a specific cell, given its row and its related column.
|
||||
|
||||
@@ -21,6 +21,8 @@ const { makeLegacyDialogMappingTestEnv } = require('@web/../tests/helpers/legacy
|
||||
const cpHelpers = require('@web/../tests/search/helpers');
|
||||
var createView = testUtils.createView;
|
||||
const { FieldOne2Many } = relationalFields;
|
||||
const AbstractFieldOwl = require('web.AbstractFieldOwl');
|
||||
const fieldRegistryOwl = require('web.field_registry_owl');
|
||||
|
||||
QUnit.module('fields', {}, function () {
|
||||
|
||||
@@ -10025,6 +10027,69 @@ QUnit.module('fields', {}, function () {
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("add_record in an o2m with an OWL field: wait mounted before success", async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
let testInst = 0;
|
||||
class TestField extends AbstractFieldOwl {
|
||||
setup() {
|
||||
super.setup();
|
||||
const ID = testInst++;
|
||||
owl.hooks.onMounted(() => {
|
||||
assert.step(`mounted ${ID}`);
|
||||
});
|
||||
|
||||
owl.hooks.onWillUnmount(() => {
|
||||
assert.step(`willUnmount ${ID}`);
|
||||
});
|
||||
}
|
||||
activate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TestField.template = owl.tags.xml`<span>test</span>`;
|
||||
fieldRegistryOwl.add('test_field', TestField);
|
||||
|
||||
const def = testUtils.makeTestPromise();
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
debug: 1,
|
||||
data: this.data,
|
||||
arch: `<form>
|
||||
<field name="p">
|
||||
<tree editable="bottom">
|
||||
<field name="name" widget="test_field"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
});
|
||||
|
||||
const list = form.renderer.allFieldWidgets[form.handle][0];
|
||||
|
||||
list.trigger_up('add_record', {
|
||||
context: [{
|
||||
default_name: 'this is a test',
|
||||
}],
|
||||
allowWarning: true,
|
||||
forceEditable: 'bottom',
|
||||
onSuccess: function () {
|
||||
assert.step("onSuccess");
|
||||
def.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
await testUtils.nextTick();
|
||||
await def;
|
||||
assert.verifySteps(["mounted 0", "willUnmount 0", "mounted 1", "onSuccess"]);
|
||||
form.destroy();
|
||||
assert.verifySteps(["willUnmount 1"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user