[FIX] web: form: no "oh snap" dialog on error in dialog
Have a form view in a dialog (action in target=new) The create/write of that model throws an error. Before this commit, the "Oh snap!" dialog was displayed, but makes little sense in a dialog. After this commit, the old UserError dialog is displayed. closes odoo/odoo#102764 X-original-commit: d36f1708219f63fae5a86b6c1e81b328ca96b347 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -360,7 +360,7 @@ export class FormController extends Component {
|
||||
async beforeExecuteActionButton(clickParams) {
|
||||
if (clickParams.special !== "cancel") {
|
||||
return this.model.root
|
||||
.save({ stayInEdition: true, useSaveErrorDialog: true })
|
||||
.save({ stayInEdition: true, useSaveErrorDialog: !this.env.inDialog })
|
||||
.then((saved) => {
|
||||
if (saved && this.props.onSave) {
|
||||
this.props.onSave(this.model.root);
|
||||
|
||||
@@ -39,6 +39,7 @@ import { localization } from "@web/core/l10n/localization";
|
||||
import { SIZES } from "@web/core/ui/ui_service";
|
||||
import { errorService } from "@web/core/errors/error_service";
|
||||
import { RPCError } from "@web/core/network/rpc_service";
|
||||
import { WarningDialog } from "@web/core/errors/error_dialogs";
|
||||
|
||||
import * as legacyCore from "web.core";
|
||||
|
||||
@@ -9355,7 +9356,10 @@ QUnit.module("Views", (hooks) => {
|
||||
},
|
||||
});
|
||||
|
||||
assert.hasClass(target.querySelector('button[data-value="4"]'), "o_arrow_button_current");
|
||||
assert.hasClass(
|
||||
target.querySelector('button[data-value="4"]'),
|
||||
"o_arrow_button_current"
|
||||
);
|
||||
assert.hasClass(target.querySelector('button[data-value="4"]'), "disabled");
|
||||
|
||||
failFlag = true;
|
||||
@@ -11968,6 +11972,56 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsOnce(target, ".o_form_error_dialog");
|
||||
});
|
||||
|
||||
QUnit.test("no 'oh snap' error in form view in dialog", async (assert) => {
|
||||
assert.expect(5);
|
||||
|
||||
registry.category("services").add("error", errorService);
|
||||
registry.category("error_dialogs").add("odoo.exceptions.UserError", WarningDialog);
|
||||
// remove the override in qunit.js that swallows unhandledrejection errors
|
||||
// s.t. we let the error service handle them
|
||||
const originalOnUnhandledRejection = window.onunhandledrejection;
|
||||
window.onunhandledrejection = () => {};
|
||||
registerCleanup(() => {
|
||||
window.onunhandledrejection = originalOnUnhandledRejection;
|
||||
});
|
||||
|
||||
serverData.views = {
|
||||
"partner,false,form": `<form><field name="foo"/><footer><button type="object" name="some_method" class="myButton"/></footer></form>`,
|
||||
};
|
||||
|
||||
const webClient = await createWebClient({
|
||||
serverData,
|
||||
mockRPC(route, { method }) {
|
||||
if (method === "create") {
|
||||
assert.step("create");
|
||||
const error = new RPCError("Some business message");
|
||||
error.data = { context: {} };
|
||||
error.exceptionName = "odoo.exceptions.UserError";
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await doAction(webClient, {
|
||||
type: "ir.actions.act_window",
|
||||
target: "new",
|
||||
res_model: "partner",
|
||||
view_mode: "form",
|
||||
views: [[false, "form"]],
|
||||
});
|
||||
|
||||
await editInput(target, ".o_field_widget[name='foo'] input", "test");
|
||||
await click(target.querySelector(".modal footer .myButton"));
|
||||
assert.verifySteps(["create"]);
|
||||
await nextTick();
|
||||
assert.containsNone(target, ".o_form_error_dialog");
|
||||
assert.containsN(target, ".modal", 2);
|
||||
assert.strictEqual(
|
||||
target.querySelectorAll(".modal .modal-body")[1].textContent,
|
||||
"Some business message"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('field "length" with value 0: can apply onchange', async function (assert) {
|
||||
serverData.models.partner.fields.length = { string: "Length", type: "float", default: 0 };
|
||||
serverData.models.partner.fields.foo.default = "foo default";
|
||||
|
||||
Reference in New Issue
Block a user