From b940375cab9b3a6736c8bd9304aaf853083f2221 Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 30 Sep 2022 12:07:45 +0000 Subject: [PATCH] [FIX] web: relational_utils save & new As of now, if a user clicks on the "Save & New" button while the form is not valid, it will disable all buttons without any options to make them enabled again. The only solution then is to close the form and re-open it. Steps to reproduce: Inventory -> Configuration -> Route -> Select any route -> Add a line to the rules. As soon as you click on the "Save & New" button and the form isn't valid, you can't use any buttons anymore. Part of task-2985735 closes odoo/odoo#102315 X-original-commit: 6d63d1035b28f2004774a99a7be84b92a1cb1883 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Tiffany Chang --- .../src/views/fields/relational_utils.js | 2 +- .../views/fields/one2many_field_tests.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index 680a61d7165..8376039509b 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -514,8 +514,8 @@ export class X2ManyFieldDialog extends Component { async saveAndNew() { const disabledButtons = this.disableButtons(); const saved = await this.save({ saveAndNew: true }); + this.enableButtons(disabledButtons); if (saved) { - this.enableButtons(disabledButtons); if (this.title) { this.title = this.title.replace(this.env._t("Open:"), this.env._t("New:")); } diff --git a/addons/web/static/tests/views/fields/one2many_field_tests.js b/addons/web/static/tests/views/fields/one2many_field_tests.js index 97f13db74dd..68dc86c7dd6 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -12442,4 +12442,36 @@ QUnit.module("Fields", (hooks) => { assert.containsOnce(target, ".modal .o_data_row td[name=display_name]"); }); + + QUnit.test('Add a line, click on "Save & New" with an invalid form', async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + + + + + `, + }); + + assert.containsNone(target, ".o_data_row"); + // Add a new record + await addRow(target); + assert.containsOnce(target, ".o_dialog .o_form_view"); + + // Click on "Save & New" with an invalid form + await click(target, ".o_dialog .o_form_button_save_new"); + assert.containsOnce(target, ".o_dialog .o_form_view"); + + // Check that no buttons are disabled + assert.hasAttrValue(target.querySelector(".o_dialog .o_form_button_save_new"), "disabled", undefined); + assert.hasAttrValue(target.querySelector(".o_dialog .o_form_button_cancel"), "disabled", undefined); + }); });