[FIX] web: buttons with special attr close, close x2many dialogs
Before this commit, if a button had the attribute special="close" on the footer of an x2many dialog, the dialog was not closed. This occurs because the view button hook searches the dialog close functions put in the environment by the dialog component, and in this case is another component that initialize the hook, and the function is not found. Now, the view button hook will use the dialog close function put in the environment by the dialog service. closes odoo/odoo#159121 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -54,7 +54,7 @@ export class Dialog extends Component {
|
||||
{ bypassEditableProtection: true }
|
||||
);
|
||||
this.id = `dialog_${this.data.id}`;
|
||||
useChildSubEnv({ inDialog: true, dialogId: this.id, closeDialog: () => this.data.close() });
|
||||
useChildSubEnv({ inDialog: true, dialogId: this.id });
|
||||
this.position = useState({ left: 0, top: 0 });
|
||||
useDialogDraggable({
|
||||
enable: () => !this.env.isSmall,
|
||||
|
||||
@@ -58,7 +58,8 @@ export function useViewButtons(model, ref, options = {}) {
|
||||
if (!_continue) {
|
||||
return;
|
||||
}
|
||||
const closeDialog = (clickParams.close || clickParams.special) && env.closeDialog;
|
||||
const closeDialog =
|
||||
(clickParams.close || clickParams.special) && env.dialogData?.close;
|
||||
const params = getResParams();
|
||||
const resId = params.resId;
|
||||
const resIds = params.resIds || model.resIds;
|
||||
|
||||
@@ -500,6 +500,39 @@ QUnit.module("Fields", (hooks) => {
|
||||
await click(target, ".o_field_many2one input");
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
'O2M with buttons with attr "special" in dialog close the dialog',
|
||||
async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="p">
|
||||
<tree>
|
||||
<field name="bar"/>
|
||||
</tree>
|
||||
<form>
|
||||
<field name="bar"/>
|
||||
<footer>
|
||||
<button special="cancel" data-hotkey="x" string="Cancel" class="btn-secondary"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
await addRow(target);
|
||||
assert.containsOnce(target, ".o_dialog");
|
||||
|
||||
assert.strictEqual(document.querySelector(".modal .btn").innerText, "Cancel");
|
||||
|
||||
await click(target, ".modal .btn");
|
||||
assert.containsNone(target, ".o_dialog");
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("O2M modal buttons are disabled on click", async function (assert) {
|
||||
// Records in an o2m can have a m2o pointing to themselves.
|
||||
// In that case, a domain evaluation on that field followed by name_search
|
||||
@@ -14629,16 +14662,16 @@ QUnit.module("Fields", (hooks) => {
|
||||
if (args.method === "onchange") {
|
||||
if (onchangeCount === 1) {
|
||||
// partner turtles onchange for the new x2m record
|
||||
assert.strictEqual(args.model, 'partner');
|
||||
assert.strictEqual(args.model, "partner");
|
||||
assert.deepEqual(Object.keys(args.args[1]), ["turtles"]);
|
||||
assert.strictEqual(args.args[1].turtles[0][0], 0);
|
||||
assert.deepEqual(args.args[2], ['turtles']);
|
||||
assert.deepEqual(args.args[2], ["turtles"]);
|
||||
} else if (onchangeCount === 2) {
|
||||
// x2m record removed, empty list of commands expected
|
||||
assert.strictEqual(args.model, 'partner');
|
||||
assert.strictEqual(args.model, "partner");
|
||||
assert.deepEqual(Object.keys(args.args[1]), ["turtles"]);
|
||||
assert.deepEqual(args.args[1].turtles, []);
|
||||
assert.deepEqual(args.args[2], ['turtles']);
|
||||
assert.deepEqual(args.args[2], ["turtles"]);
|
||||
}
|
||||
onchangeCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user