From 24ef92f66f4e64de04db21fc0ad905654a58e5d5 Mon Sep 17 00:00:00 2001 From: Florian Charlier Date: Wed, 11 Jan 2023 12:50:41 +0000 Subject: [PATCH] [FIX] survey: fix handleSurveyError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to changes in errorService added in dd6f103b, a traceback was shown due to our (handled) "unhandled" rejected promise that wasn't an "Error" object. Using the original error works now for our handleSurveyError function. The only additional requirement was to restore the buttons of the dialog when saving is blocked due to our validation process. Task-3128957 closes odoo/odoo#109648 Signed-off-by: Warnon Aurélien (awa) --- .../question_page_one2many_field.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/survey/static/src/question_page/question_page_one2many_field.js b/addons/survey/static/src/question_page/question_page_one2many_field.js index 16faf8f77ae..67671a1313b 100644 --- a/addons/survey/static/src/question_page/question_page_one2many_field.js +++ b/addons/survey/static/src/question_page/question_page_one2many_field.js @@ -2,12 +2,31 @@ import { QuestionPageListRenderer } from "./question_page_list_renderer"; import { registry } from "@web/core/registry"; -import { useOpenX2ManyRecord, useX2ManyCrud } from "@web/views/fields/relational_utils"; +import { useOpenX2ManyRecord, useX2ManyCrud, X2ManyFieldDialog } from "@web/views/fields/relational_utils"; +import { patch } from '@web/core/utils/patch'; import { useService } from "@web/core/utils/hooks"; import { X2ManyField } from "@web/views/fields/x2many/x2many_field"; const { useSubEnv } = owl; +patch(X2ManyFieldDialog.prototype, 'survey_question_chaining_with_validation', { + /** + * Re-enable buttons after our error is thrown because blocking normal + * behavior is required to not close the dialog and stay in edition but + * the buttons are required to try and save again after changing form data. + * + * @override + */ + async saveAndNew() { + const res = this._super(...arguments); + if (this.record.resModel === 'survey.question') { + const btns = this.modalRef.el.querySelectorAll(".modal-footer button"); // see XManyFieldDialog.disableButtons + this.enableButtons(btns); + } + return res; + } +}); + class QuestionPageOneToManyField extends X2ManyField { setup() { super.setup(); @@ -95,7 +114,7 @@ class QuestionPageOneToManyField extends X2ManyField { } ); // Prevent closing the question form view - return Promise.reject("Impossible to save survey, see error notification."); + throw error; } } QuestionPageOneToManyField.components = {