From dede76bd5c898c7b68b1b70c44bb73588c2f594e Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 8 Dec 2023 14:19:22 +0100 Subject: [PATCH] [FIX] website, website_form_project: set email_from as custom for task Commit [1] removed the `email_from` field from the `project.task` model but forgot to adapt/delete some field occurences. One of those is related to the form in the website builder which allows to create task when the form is sent. Two errors were detected: - Non critical: The field is still passed to the form field whitelisting process. Since the whitelisting is done in raw SQL, it didn't crash or log anything even if the column did not exist anymore. - Critical: The field was still marked as model required in the form JS registry, altering the form builder behaviors. One of those is that when the form input related to this field was re-created (eg when changing / hovering an option in the right panel), it would lose it's "name" attribute. Two possible issues from that point: 1. When a visitor submit the form, the "email_from" field value is not set anymore in the task description and that information is just lost. You then have no way to reach back to him. 2. (Minor) The auto-fill behavior of the form was not working anymore Probably more issues were introduced but only those ones got detected as of today. Step to reproduce: - Drop a website form, choose "Create a Task" - Focus the default "Email" field - Hover the mouse on the "eye" icon ("Invisible") next to the Position attribute. If you inspect the DOM, the input has now lost the `name` attribute. - If you save, you will face the issues reported above. - If you then reopen the editor and focus the email field again, the tooltip will now say that the "null" field is required. [1]: https://github.com/odoo/odoo/commit/a424cf481c676a230beeb6102fc67bedf472a882 opw-3626573 closes odoo/odoo#146170 X-original-commit: 6679fddbcaf7d9146ab242e0eed61ee0628f047f Signed-off-by: Quentin Smetz (qsm) Signed-off-by: Romain Derie (rde) --- addons/website/models/website_form.py | 9 +++++++++ .../data/website_form_project_data.xml | 1 - .../static/src/js/website_form_project_editor.js | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/website/models/website_form.py b/addons/website/models/website_form.py index 896568595ef..cb4b4b141b5 100644 --- a/addons/website/models/website_form.py +++ b/addons/website/models/website_form.py @@ -1,9 +1,13 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import logging + from odoo import models, fields, api, SUPERUSER_ID from odoo.http import request +_logger = logging.getLogger(__name__) + class website_form_config(models.Model): _inherit = 'website' @@ -116,6 +120,11 @@ class website_form_model_fields(models.Model): if not self.env['res.users'].has_group('website.group_website_designer'): return False + unexisting_fields = [field for field in fields if field not in self.env[model]._fields.keys()] + if unexisting_fields: + # TODO in master: Raise instead of log + _logger.error("Unable to whitelist field(s) %r for model %r.", unexisting_fields, model) + # the ORM only allows writing on custom fields and will trigger a # registry reload once that's happened. We want to be able to # whitelist non-custom fields and the registry reload absolutely diff --git a/addons/website_form_project/data/website_form_project_data.xml b/addons/website_form_project/data/website_form_project_data.xml index 1a3052472c3..df4d340a0eb 100644 --- a/addons/website_form_project/data/website_form_project_data.xml +++ b/addons/website_form_project/data/website_form_project_data.xml @@ -11,7 +11,6 @@ project.task diff --git a/addons/website_form_project/static/src/js/website_form_project_editor.js b/addons/website_form_project/static/src/js/website_form_project_editor.js index 5c137b0254c..4ba1aeedbc9 100644 --- a/addons/website_form_project/static/src/js/website_form_project_editor.js +++ b/addons/website_form_project/static/src/js/website_form_project_editor.js @@ -11,7 +11,8 @@ FormEditorRegistry.add('create_task', { string: _t('Task Title'), }, { type: 'email', - modelRequired: true, + custom: true, + required: true, fillWith: 'email', name: 'email_from', string: _t('Your Email'),