diff --git a/addons/website/static/tests/tours/website_form_editor.js b/addons/website/static/tests/tours/website_form_editor.js index dd4ac97428a..48f8715e2a8 100644 --- a/addons/website/static/tests/tours/website_form_editor.js +++ b/addons/website/static/tests/tours/website_form_editor.js @@ -707,4 +707,16 @@ } ]); + wTourUtils.registerWebsitePreviewTour('website_form_contactus_change_random_option', { + test: true, + url: '/contactus', + edition: true, + }, () => editContactUs([ + { + content: "Change a random option", + trigger: '[data-set-mark] input', + run: 'text_blur **', + }, + ])); + export default {}; diff --git a/addons/website/static/tests/tours/website_form_editor_frontend.js b/addons/website/static/tests/tours/website_form_editor_frontend.js index cd2ebb28083..3fb82bc8f0d 100644 --- a/addons/website/static/tests/tours/website_form_editor_frontend.js +++ b/addons/website/static/tests/tours/website_form_editor_frontend.js @@ -217,3 +217,13 @@ registry.category("web_tour.tours").add('website_form_contactus_submit', { isCheck: true, }, ]}); +registry.category("web_tour.tours").add('website_form_contactus_check_changed_email', { + test: true, + url: '/contactus', + steps: () => [ + { + content: "Check that the recipient email is updated", + trigger: 'form:has(input[name="email_to"][value="after.change@mail.com"])', + isCheck: true, + }, +]}); diff --git a/addons/website/tests/test_website_form_editor.py b/addons/website/tests/test_website_form_editor.py index 1fc8c4760b7..445cbb6191c 100644 --- a/addons/website/tests/test_website_form_editor.py +++ b/addons/website/tests/test_website_form_editor.py @@ -41,3 +41,11 @@ class TestWebsiteFormEditor(HttpCaseWithUserPortal): def test_website_form_conditional_required_checkboxes(self): self.start_tour('/', 'website_form_conditional_required_checkboxes', login="admin") + + def test_contactus_form_email_stay_dynamic(self): + # The contactus form should always be sent to the company email except + # if the user explicitly changed it in the options. + self.env.company.email = 'before.change@mail.com' + self.start_tour('/contactus', 'website_form_contactus_change_random_option', login="admin") + self.env.company.email = 'after.change@mail.com' + self.start_tour('/contactus', 'website_form_contactus_check_changed_email', login="portal") diff --git a/addons/website/tools.py b/addons/website/tools.py index 952ab0d5578..debfb113134 100644 --- a/addons/website/tools.py +++ b/addons/website/tools.py @@ -203,10 +203,17 @@ def add_form_signature(html_fragment, env_sudo): # the value of email_to can still be None in case of default value if 'email_to' not in form_values: continue - elif not form_values['email_to'].attrib.get('value'): - form_values['email_to'].attrib['value'] = env_sudo.company.email or '' + + email_to_value = form_values['email_to'].attrib.get('value') + if (not email_to_value + or (email_to_value == 'info@yourcompany.example.com' + and html_fragment.xpath('//span[@data-for="contactus_form"]'))): + # This means that the mail will be sent to the value of the dataFor + # which is the company email. + email_to_value = env_sudo.company.email or '' + has_cc = {'email_cc', 'email_bcc'} & form_values.keys() - value = form_values['email_to'].attrib['value'] + (':email_cc' if has_cc else '') + value = email_to_value + (':email_cc' if has_cc else '') hash_value = hmac(env_sudo, 'website_form_signature', value) if has_cc: hash_value += ':email_cc'