[FIX] survey: fix handleSurveyError

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) <awa@odoo.com>
This commit is contained in:
Florian Charlier
2023-01-12 14:34:48 +01:00
parent ed99208b6c
commit 24ef92f66f
@@ -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 = {