[IMP] website_crm : catch logged partner info on contact form

1) Improves user experience by filling contact form with logged partner info.
This facilitates the flow when logged.

The contact us form is filled with data from the partner linked
with logged in web visitor, logged_partner. Its data is used in priority.
Empty fields (e.g. no partner is logged) will be set to default values
in request.params if any. This way, previous behaviour is preserved (as well
as widget correct display behaviour).

2) This commit also adds a star next to the required field Subject in the contact
us form like for the rest of required fields of the form : s_website_form_mark
This improves coherence and clarity when filling the form.

Task-ID : 2241639
PR : #61126
This commit is contained in:
Noe Antoine
2021-03-31 13:18:07 +00:00
parent 7cfb0e0e74
commit 5e0f7d1e78
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="contactus_form" name="Contact Form (Opportunity)" inherit_id="website_form.contactus_form" customize_show="True">
<xpath expr="//span[@data-for='contactus_form']" position="before">
<t t-set="logged_partner" t-value="request.env['website.visitor']._get_visitor_from_request().partner_id"/>
</xpath>
<xpath expr="//span[@data-for='contactus_form']" position="attributes">
<attribute name="t-att-data-values">{
'contact_name': request.params.get('contact_name', ''),
'phone': request.params.get('phone', ''),
'email_from': request.params.get('email_from', ''),
'partner_name': request.params.get('partner_name', ''),
'contact_name': request.params.get('contact_name', logged_partner.name if logged_partner else ''),
'phone': request.params.get('phone', logged_partner.phone if logged_partner and logged_partner.phone else ''),
'email_from': request.params.get('email_from', logged_partner.email if logged_partner else ''),
'partner_name': request.params.get('partner_name', logged_partner.commercial_company_name if logged_partner else ''),
'name': request.params.get('name', ''),
'description': request.params.get('description', ''),
}</attribute>
@@ -63,6 +66,7 @@
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 200px" for="opportunity5">
<span class="s_website_form_label_content">Subject</span>
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-sm">
<input id="opportunity5" type="text" class="form-control s_website_form_input" name="name" required="" />