I am trying to send a mail to the portal user who've successfully submitted a request and I'm getting this error KeyError: False.
These are my controller and template codes.
@http.route('/submit', method='post', type='http', auth='public', website=True, csrf=False)
def send_request(self, **post):
values = {
'name': post['subject'],
'maintenance_team_id': post['teams'],
'equipment_id': post['equipment'],
'description': post['details'],
'priority': post['stars'],
}
print(values)
# maintenance_request = self.env['maintenance.request'].search()
request.env['maintenance.request'].sudo().create(values)
search_ids = request.env['maintenance.request'].search([])
last_id = search_ids and max(search_ids)
print(last_id.id)
template = request.env.ref('website_maintenance.mail_template_maintenance_request')
print(template)
template.send_mail(last_id.id, force_send=True)
return redirect('/maintenance_request-thanks')
template
<odoo>
<data>
<record id="mail_template_maintenance_request" model="mail.template">
<field name="name">Maintenance: Reception Acknowledgment</field>
<!-- <field name="model_id" ref="website_maintenance"/>-->
<field name="subject">Maintenance request received</field>
<field name="email_to">robodoo2019@gmail.com</field>
<field name="body_html"><![CDATA[
<div>
<!-- Just trying to send an empty mail first -->
</div>]]>
</field>
</record>
</data>
</odoo>
What am I doing wrong here?